import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto n = RD!int;
	writeln(4 + n * 3);
	writeln("0 0");
	writeln("0 1");
	writeln("1 0");
	writeln("1 1");

	foreach (i; 0..n)
	{
		writeln(i+2, " ", i+2);
		writeln(i+1, " ", i+2);
		writeln(i+2, " ", i+1);
	}

	stdout.flush;
	debug readln;
}

// Code By H~$~C

import std.stdio, std.format;
import std.math, std.uni, std.bigint, std.numeric;
import std.array, std.string, std.container, std.range, std.typecons;
import std.algorithm, std.conv, std.functional, std.random;

void _Main() {
  int n;
  readf!" %s"(n);
  writeln(3 * n + 4);
  writeln("0 0\n0 1");
  foreach(i; 0 .. n) {
    writefln!"%s %s\n%s %s\n%s %s"(i + 1, i, i + 1, i + 1, i + 1, i + 2);
  }
  writefln!"%s %s\n%s %s"(n + 1, n, n + 1, n + 1);
}

void main(string[] args) {
  int tests = 1;
//  readf!" %d"(tests);
  foreach (test; 0 .. tests) _Main();
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      debug {
        writeln("N = ", N);
      }

      writeln(3 * (N + 1) + 1);
      foreach (i; 0 .. N + 1) {
        writeln(i, " ", i);
        writeln(i, " ", i + 1);
        writeln(i + 1, " ", i);
      }
      writeln(N + 1, " ", N + 1);
    }
  } catch (EOFException e) {
  }
}

import std.algorithm;
import std.conv;
import std.numeric;
import std.stdio;
import std.typecons;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		writeln (n * 3 + 4);
		writeln (0, " ", 0);
		foreach (i; 0..n + 1)
		{
			foreach (j; 0..2)
			{
				foreach (k; 0..2)
				{
					if (j + k > 0)
					{
						writeln (i + j, " ", i + k);
					}
				}
			}
		}
	}
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      debug {
        writeln("N = ", N);
      }

      foreach (i; 0 .. N + 1) {
        writeln(i, " ", i);
        writeln(i, " ", i + 1);
        writeln(i + 1, " ", i);
      }
      writeln(N + 1, " ", N + 1);
    }
  } catch (EOFException e) {
  }
}


import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long MOD = 998244353;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = readln.split.map!(to!long).array;
    auto C = readln.split.map!(to!long).array;

    auto B = N.iota.map!(i => tuple(C[i], i)).array;
    B.sort();
    int p = 0;

    foreach (_; 0..M) {

        s = readln.split.map!(to!int);
        auto t = s[0] - 1;
        auto d = s[1].to!long;
        long ans = 0;

        if (A[t] >= d) {
            writeln(C[t] * d);
            A[t] -= d;
        } else {
            ans += A[t] * C[t];
            d -= A[t];
            A[t] = 0;
            while (d > 0 && p < N) {
                while (p < N && A[B[p][1]] == 0) ++p;
                if (p >= N) break;
                long v = min(d, A[B[p][1]]);
                ans += v * C[B[p][1]];
                A[B[p][1]] -= v;
                d -= v;
            }
            if (d == 0) {
                writeln(ans);
            } else {
                writeln(0);
            }
        }
    }
}

import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Dish = Tuple!(int, "cost", int, "index");

void main() {
    int n, m;
    scan(n, m);
    auto a = readln.split.to!(int[]);
    auto c = readln.split.to!(int[]);

    auto ds = new Dish[](n);
    foreach (i ; 0 .. n) {
        ds[i] = Dish(c[i], i);
    }

    ds.sort!();

    foreach (j ; 0 .. m) {
        int tj, dj;
        scan(tj, dj);
        tj--;

        long ans;

        if (a[tj] > 0) {
            int x = min(dj, a[tj]);
            ans += 1L * x * c[tj];
            a[tj] -= x;
            dj -= x;
        }

        while (dj > 0 && !ds.empty) {
            int cost = ds.front.cost;
            int ind = ds.front.index;

            int x = min(dj, a[ind]);
            ans += 1L * x * c[ind];
            a[ind] -= x;
            dj -= x;

            if (a[ind] == 0) {
                ds.popFront();
            }
        }

        if (dj > 0) {
            ans = 0;
        }

        writeln(ans);
    }
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


immutable multi = true;

void solve(int tc)
{
	auto n = readInt!int;
	auto a = ma(n, readInt!int);
	int[2][] vis;
	auto ft = FenwickTree(n);
	foreach(i, ai; a) vis ~= [ai, cast(int)i];
	sort(vis);
	auto less = new int[](n);
	auto equal = new int[](n);
	{
		int i = 0;
		while (i < n)
		{
			auto v = vis[i][0];
			int[] _is;
			while (i < n && vis[i][0] == v)
			{
				_is ~= vis[i][1];
				i++;
			}
			int cnt = 0;
			foreach(j; _is)
			{
				less[j] = ft.sum(j-1);
				equal[j] = cnt++;
			}
			foreach(j; _is)
			{
				ft.add(j, 1);
			}
		}
	}
	auto deque = DList!int();
	long mininvs = 0;
	debug writeln(less);
	foreach(i; 0 .. n)
	{
		auto l = less[i];
		auto e = equal[i];
		auto g = i - l - e;
		mininvs += min(l, g);
	}
	writeln(mininvs);
}
struct FenwickTree {
	int[] bit;
	int n;

	this(int n) {
		this.n = n;
		bit = new int[](n);

	}

	int sum(int r) {
		int ret = 0;
		for (; r >= 0; r = (r & (r + 1)) - 1)
			ret += bit[r];
		return ret;
	}

	int sum(int l, int r) {
		return sum(r) - sum(l - 1);
	}

	void add(int idx, int delta) {
		for (; idx < n; idx = idx | (idx + 1))
			bit[idx] += delta;
	}
}

//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

char topChar()
{
	return cast(char) currChar;
}

void popChar()
{
	import core.stdc.stdio;
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
	{
		popChar;
	}
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.ascii, std.typecons;

struct fw {
    int[] arr;
    int sz;

    this(int sz) {
        this.sz = sz;
        arr = new int[sz+1];
        arr[] = 0;
    }

    void add(int p) {
        while (p <= sz) {
            arr[p] += 1;
            p += (1 << p.bsf);
        }
    }

    int sum(int p) {
        int ret = 0;
        while (p > 0) {
            ret += arr[p];
            p -= (1 << p.bsf);
        }

        return ret;
    }
}

void main()
{
    int t;
    readf!"%s"(t);
    readln;

    while (t--) {
        int n;
        readf!"%s"(n);
        readln;

        auto arr = readln.chomp.split.map!(to!int).array;

        auto uni = arr.dup.sort.uniq.array;
        int[int] mapping;
        foreach (i, e; uni.enumerate(1)) { mapping[e] = i; }
        arr = arr.map!(x => mapping[x]).array;

        debug { writeln(uni, ' ' , mapping, ' ', arr); }

        auto f = fw(uni.length.to!int);
        long ans = 0;
        foreach (i, e; arr) {
            auto smaller = f.sum(e-1);
            auto bigger = i - f.sum(e);

            ans += min(smaller, bigger);

            f.add(e);
        }

        ans.writeln;
    }
}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.ascii, std.typecons;

struct fw {
    int[] arr;
    int sz;

    this(int sz) {
        this.sz = sz;
        arr = new int[sz+1];
        arr[] = 0;
    }

    void add(int p) {
        while (p <= sz) {
            arr[p] += 1;
            p += (1 << p.bsf);
        }
    }

    int sum(int p) {
        int ret = 0;
        while (p > 0) {
            ret += arr[p];
            p -= (1 << p.bsf);
        }

        return ret;
    }
}

void main()
{
    int t;
    readf!"%s"(t);
    readln;

    while (t--) {
        int n;
        readf!"%s"(n);
        readln;

        auto arr = readln.chomp.split.map!(to!int).array;

        auto uni = arr.dup.sort.uniq.array;
        int[int] mapping;
        foreach (i, e; uni.enumerate(1)) { mapping[e] = i; }
        arr = arr.map!(x => mapping[x]).array;

        debug { writeln(uni, ' ' , mapping, ' ', arr); }

        auto f = fw(uni.length.to!int);
        int ans = 0;
        foreach (i, e; arr) {
            auto smaller = f.sum(e-1);
            auto bigger = i - f.sum(e);

            ans += min(smaller, bigger);

            f.add(e);
        }

        ans.writeln;
    }
}


import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new string[](t);
	foreach (ti; 0..t)
	{
		auto b = RD!string;
		auto begin = b[0];
		auto end = b[$-1];
		foreach (i; 1..b.length-1)
		{
			if (i % 2 == 0) continue;
			ans[ti] ~= b[i];
		}
		ans[ti] = begin ~ ans[ti] ~ end;
	}

	foreach (e; ans)
	{
		writeln(e);
	}
	stdout.flush;
	debug readln;
}

import std.stdio;
import std.range;
import std.string : strip;

void main()
{
  int t;
  readf!"%d\n"(t);

  foreach (i; 0..t) {
    auto s = readln.strip;
    writeln(s.takeOne.chain(s.dropOne.stride(2)));
  }
}


import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto s = readln.split.map!(to!long);
    auto N = s[0];
    auto Q = s[1];

    while (Q--) {
        s = readln.split.map!(to!long);
        auto r = s[0];
        auto c = s[1];
        if ((r + c) % 2 == 0) {
            long odd = r / 2;
            long even = r - 1 - odd;
            long n = odd * (N / 2 + N % 2) + even * (N / 2);
            writeln(n + (c - 1) / 2 + 1);
        } else {
            long odd = r / 2;
            long even = r - 1 - odd;
            long n = odd * (N / 2) + even * (N / 2 + N % 2);
            n += N * N / 2 + N % 2;
            writeln(n + (c - 1) / 2 + 1);
        }
    }
}

import core.bitop;
import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.range.interfaces;

long f(int n, int x, int y) {
    auto sumOdd = (x+y) % 2 == 1;
    auto rowOdd = x % 2 == 1;
    auto prevRows = n % 2 == 0 ?
        cast(long)(x-1) * n/2 :
        cast(long)(x-1)/2 * (n/2 + n/2 + 1) + (!rowOdd ? (sumOdd ? n/2 : n/2+1) : 0);
    auto prevCols = (y-1) / 2;
    return 1 + prevRows + prevCols + (sumOdd ? f(n, n, n) : 0);
}

void main()
{
    int n, q;
    readf("%s %s", &n, &q);
    readln;

    while (q--) {
        int x, y;
        readf("%s %s", &x, &y);
        readln;

        f(n, x, y).writeln;
    }
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto s = readln.split.map!(to!long);
    auto N = s[0];
    auto Q = s[1];

    while (Q--) {
        s = readln.split.map!(to!long);
        auto r = s[0];
        auto c = s[1];
        if ((r + c) % 2 == 0) {
            long odd = r / 2;
            long even = r - 1 - odd;
            long n = odd * (N / 2 + N % 2) + even * N / 2;
            writeln(n + (c - 1) / 2 + 1);
        } else {
            long odd = r / 2;
            long even = r - 1 - odd;
            long n = odd * N / 2 + even * (N / 2 + N % 2);
            n += N * N / 2 + N % 2;
            writeln(n + (c - 1) / 2 + 1);
        }
    }
}


import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

const long mod = 1_000_000_007;

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	int n = read.to!int;
	char[] cs = readln.chomp.to!(char[]);

	if(n % 2 > 0){ // this matters only for n = 1
		writeln(":(");
		return;
	}

	if(cs[0] == ')' || cs[$ - 1] == '('){
		writeln(":(");
		return;
	}

	auto cntleft = cs.count!(x => x == '(');
	auto cntright = cs.count!(x => x == ')');
	if( cntleft > n / 2 || cntright > n / 2){
		writeln(":(");
		return;
	}

	auto lackleft = n / 2 - cntleft;
	auto lackright = n / 2 - cntright;
	foreach(i; 0 .. n){
		if(cs[i] == '?') lackleft -= 1, cs[i] = '(';
		if(lackleft == 0) break;
	}
	foreach_reverse(i; 0 .. n){
		if(cs[i] == '?') lackright -= 1, cs[i] = ')';
		if(lackright == 0) break;
	}

	int depth = 0;
	foreach(i; 0 .. n){
		if(cs[i] == '(') depth += 1;
		else depth -= 1;
		if(i < n - 1 && depth == 0){
			writeln(":(");
			return;
		}
	}

	cs.to!string.writeln;
}

/*

- Fail if n is odd
- Fail if the leftmost is )
- Fail if the rightmost is (
- Fail if there are too many (s
- Fail if there are too many )s
~ Otherwise, try this:
  - Fill with ( from the left end until (s are enough
  - Fill with ) from the right end until )s are enough
- If the result is valid, it is valid
- Otherwise, it is failure

*/

import std.algorithm;
import std.conv;
import std.stdio;
import std.string;

immutable string NO = ":(";

string solve (int n, string s)
{
	if (n & 1)
	{
		return NO;
	}
	auto a = n / 2 - s.count ('(').to !(int);
	auto b = n / 2 - s.count (')').to !(int);
	if (a < 0 || b < 0)
	{
		return NO;
	}
	auto t = s.dup;
	foreach (ref c; t)
	{
		if (c == '?')
		{
			if (a > 0)
			{
				c = '(';
				a -= 1;
			}
			else
			{
				c = ')';
				b -= 1;
			}
		}
	}

	int balance = 0;
	foreach (ref c; t[0..$ - 1])
	{
		balance += (c == '(') ? +1 : -1;
		if (balance <= 0)
		{
			return NO;
		}
	}

	return t.idup;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto s = readln.strip;
		writeln (solve (n, s));
	}
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;

    if (N % 2 == 1) {
        ":(".writeln;
        return;
    }

    int open = N / 2 - S.map!(s => s == '(').sum;
    int tmp = 0;

    dchar[] ans;

    foreach (i; 0..N) {
        if (S[i] == '(') {
            tmp += 1;
            ans ~= '(';
        } else if (S[i] == ')') {
            tmp -= 1;
            ans ~= ')';
        } else if (open > 0) {
            tmp += 1;
            open -= 1;
            ans ~= '(';
        } else {
            tmp -= 1;
            ans ~= ')';
        }
        if (i != N - 1 && tmp <= 0) {
            ":(".writeln;
            return;
        } else if (i == N - 1 && tmp != 0) {
            ":(".writeln;
            return;
        }
    }

    ans.writeln;
}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.ascii, std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    auto s = readln.chomp;

    if (n % 2 != 0) {
        writeln(":(");
        return;
    }

    int open = n / 2 - s.count!(x => x == '(').to!int;
    int v = 0;
    string ans;
    foreach (i, e; s) {
        dchar nxt = e;
        if (e == '?') {
            if (open > 0) {
                nxt = '(';
                --open;
            } else {
                nxt = ')';
            }
        }

        ans ~= nxt;

        if (nxt == '(') { ++v; }
        else { --v; }

        if (v < 0 || (v == 0 && i < n-1)) {
            writeln(":(");
            return;
        }
    }

    if (v != 0) {
        writeln(":(");
        return;
    }

    writeln(ans);
}

import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.ascii, std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;

    auto s = readln.chomp;

    if (n % 2 != 0) {
        writeln(":(");
        return;
    }

    int open = n / 2 - s.count!(x => x == '(').to!int;
    int v = 0;
    string ans;
    foreach (i, e; s) {
        dchar nxt = e;
        if (e == '?') {
            if (open > 0) {
                nxt = '(';
                --open;
            } else {
                nxt = ')';
            }
        }

        ans ~= nxt;

        if (nxt == '(') { ++v; }
        else { --v; }

        if (v < 0 || (v == 0 && i < n-1)) {
            writeln(":(");
            return;
        }
    }

    writeln(ans);
}

import std.algorithm;
import std.stdio;
import std.string;

immutable string NO = ":(";

string solve (int n, string s)
{
	if (n & 1)
	{
		return NO;
	}
	auto a = n / 2 - s.count ('(');
	auto b = n / 2 - s.count (')');
	if (a < 0 || b < 0)
	{
		return NO;
	}
	auto t = s.dup;
	foreach (ref c; t)
	{
		if (c == '?')
		{
			if (a > 0)
			{
				c = '(';
				a -= 1;
			}
			else
			{
				c = ')';
				b -= 1;
			}
		}
	}

	int balance = 0;
	foreach (ref c; t[0..$ - 1])
	{
		balance += (c == '(') ? +1 : -1;
		if (balance == 0)
		{
			return NO;
		}
	}

	return t.idup;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto s = readln.strip;
		writeln (solve (n, s));
	}
}

import std.algorithm;
import std.stdio;
import std.string;

immutable string NO = ":(";

string solve (int n, string s)
{
	if (n & 1)
	{
		return NO;
	}
	auto a = n / 2 - s.count ('(');
	auto b = n / 2 - s.count (')');
	if (a < 0 || b < 0)
	{
		return NO;
	}
	auto t = s.dup;
	foreach (ref c; t)
	{
		if (c == '?')
		{
			if (a > 0)
			{
				c = '(';
				a -= 1;
			}
			else
			{
				c = ')';
				b -= 1;
			}
		}
	}

	int balance = 0;
	foreach (ref c; t[0..$ - 1])
	{
		balance += (c == '(') ? +1 : -1;
		if (balance <= 0)
		{
			return NO;
		}
	}

	return t.idup;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto s = readln.strip;
		writeln (solve (n, s));
	}
}

import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

const long mod = 1_000_000_007;

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	int n = read.to!int;
	char[] cs = readln.chomp.to!(char[]);

	if(cs[0] == ')' || cs[$ - 1] == '('){
		writeln(":(");
		return;
	}

	auto cntleft = cs.count!(x => x == '(');
	auto cntright = cs.count!(x => x == ')');
	if( cntleft > n / 2 || cntright > n / 2){
		writeln(":(");
		return;
	}

	auto lackleft = n / 2 - cntleft;
	auto lackright = n / 2 - cntright;
	foreach(i; 0 .. n){
		if(cs[i] == '?') lackleft -= 1, cs[i] = '(';
		if(lackleft == 0) break;
	}
	foreach_reverse(i; 0 .. n){
		if(cs[i] == '?') lackright -= 1, cs[i] = ')';
		if(lackright == 0) break;
	}

	int depth = 0;
	foreach(i; 0 .. n){
		if(cs[i] == '(') depth += 1;
		else depth -= 1;
		if(i < n - 1 && depth == 0){
			writeln(":(");
			return;
		}
	}

	cs.to!string.writeln;
}

/*

- Fail if the leftmost is )
- Fail if the rightmost is (
- Fail if there are too many (s
- Fail if there are too many )s
~ Otherwise, try this:
  - Fill with ( from the left end until (s are enough
  - Fill with ) from the right end until )s are enough
- If the result is valid, it is valid
- Otherwise, it is failure

*/


import std.stdio, std.range, std.algorithm;
void main()
{
    int q;
    readf!"%d\n"(q);
    foreach (_; 0 .. q)
    {
        int n, k;
        readf!"%d %d\n"(n, k);
        int[] p = iota(1, k + 1).array;
        reverse(p[2 * k - n - 1 .. k]);
        p.writefln!"%(%s %)";
    }
}

import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

void main()
{
    int T; get(T);
    while (T--) {
        int N, K; get(N, K);
        auto res = 1.iota(K + 1).array();
        if (N != K) {
            auto i = K - (N - K) - 1;
            reverse(res[i..$]);
        }
        writefln!"%(%d %)"(res);
    }
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		auto p = iota (1, k + 1).array;
		reverse (p[k + k - n - 1..k]);
		writefln !("%(%s %)") (p);
	}
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto k = RD!int;

		ans[ti].length = k;
		auto d = n-k;
		foreach (i; 0..k-d)
		{
			ans[ti][i] = i+1;
		}
		foreach (i; k-d-1..k)
		{
			ans[ti][i] = (k-1) - (i-(k-d));
		}
	}

	foreach (e; ans)
	{
		e.map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}

import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

void main()
{
    int T; get(T);
    while (T--) {
        int N, K; get(N, K);
        auto res = 1.iota(K + 1).array();
        if (N != K) swap(res[$-1], res[$-2]);
        writefln!"%(%d %)"(res);
    }
}

import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void get(Args...)(ref Args args)
{
    import std.traits, std.meta, std.typecons;

    static if (Args.length == 1) {
        alias Arg = Args[0];

        static if (isArray!Arg) {
          static if (isSomeChar!(ElementType!Arg)) {
            args[0] = readln.chomp.to!Arg;
          } else {
            args[0] = readln.split.to!Arg;
          }
        } else static if (isTuple!Arg) {
            auto input = readln.split;
            static foreach (i; 0..Fields!Arg.length) {
                args[0][i] = input[i].to!(Fields!Arg[i]);
            }
        } else {
            args[0] = readln.chomp.to!Arg;
        }
    } else {
        auto input = readln.split;
        assert(input.length == Args.length);

        static foreach (i; 0..Args.length) {
            args[i] = input[i].to!(Args[i]);
        }
    }
}

void get_lines(Args...)(size_t N, ref Args args)
{
    import std.traits, std.range;

    static foreach (i; 0..Args.length) {
        static assert(isArray!(Args[i]));
        args[i].length = N;
    }

    foreach (i; 0..N) {
        static if (Args.length == 1) {
            get(args[0][i]);
        } else {
            auto input = readln.split;
            static foreach (j; 0..Args.length) {
                args[j][i] = input[j].to!(ElementType!(Args[j]));
            }
        }
    }
}

void main()
{
    int T; get(T);
    while (T--) {
        int N, K; get(N, K);
        auto res = 1.iota(K + 1).array();
        if (N > K) {
            auto n = K - (N - K) - 1;
            swap(res[n], res[n + 1]);
        }
        writefln!"%(%d %)"(res);
    }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto k = RD!int;

		ans[ti].length = k;
		foreach (i; 0..k)
		{
			ans[ti][i] = i+1;
		}
		if (n == k) continue;
		auto d = n-k;
		ans[ti] = ans[ti][0..k-d-1] ~ ans[ti][k-d..$] ~ (k-d);
	}

	foreach (e; ans)
	{
		e.map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto k = RD!int;

		ans[ti].length = k;
		foreach (i; 0..k)
		{
			ans[ti][i] = i+1;
		}
		if (n == k) continue;
		swap(ans[ti][$-2], ans[ti][$-1]);
	}

	foreach (e; ans)
	{
		e.map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}


import std;

void main () {
    int t;
    readf("%s\n", t);

    foreach (_; 0..t) {
        int[3] l;
        readf("%s %s %s\n", l[0], l[1], l[2]);

        l = sort(l.dup).array;

        if (l[0] + l[1] == l[2])
            writeln("YES");
        else if (l[0] == l[1] && l[2] % 2 == 0)
            writeln("YES");
        else if (l[1] == l[2] && l[0] % 2 == 0)
            writeln("YES");
        else
            writeln("NO");
    }
}
// ""

import std.stdio;
import std.array;
import std.conv;
import std.algorithm;

enum MOD = 998244353;

void main()
{
    ulong count = readln.split[0].to!int;
    foreach (line; 0 .. count)
    {
        ulong[3] nums;
        auto nptr = nums.ptr;
        scanf("%lu %lu %lu", nptr, nptr + 1, nptr + 2);
        if (nums.sumCase)
        {
            writeln("yes");

        }
        else if (nums.binCase)
        {
            writeln("yes");
        }
        else
            writeln("NO");

    }
}

auto sumCase(ulong[3] nums)
{
    for (int i = 0; i < 3; i++)
    {
        if (nums[(0 + i) % 3] == nums[(1 + i) % 3] + nums[(2 + i) % 3])
            return true;
    }
    return false;
}

auto binCase(ulong[3] nums)
{
    for (int i = 0; i < 3; i++)
    {
        if (nums[(0 + i) % 3] == nums[(1 + i) % 3] && nums[(2 + i) % 3] % 2 == 0)
            return true;
    }
    return false;
}

import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,
       std.container, std.typecons, std.conv, std.random, std.bigint;

void read(S...)(ref S args) {
  auto input = readln.split;
  enforce(input.length == args.length);
  foreach (i, ref arg; args) {
    arg = input[i].to!(S[i]);
  }
}

auto list(T)() { return readln.split.map!(e => e.to!T).array; }

void main() {
  int n;
  read(n);
  while (n--) {
    int[] arr = list!int();
    sort(arr);
    if (arr[2] == arr[0] + arr[1]) writeln("YES");
    else if (arr[0] == arr[1] && arr[2] % 2 == 0) writeln("YES");
    else if (arr[2] == arr[1] && arr[0] % 2 == 0) writeln("YES");
    else writeln("NO");
  }
}

import std;

void main()
{
    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        long[] nums = readln.strip.split(" ").to!(long[]);
        nums.sort();
        if (nums[2] - nums[1] == nums[0])
            writeln("YES");
        else if ((nums[0] == nums[1]) && (nums[2] % 2 == 0))
            writeln("YES");
        else if ((nums[1] == nums[2]) && (nums[0] % 2 == 0))
            writeln("YES");
        else
            writeln("NO");
    }
}

void main() { runSolver(); }

void problem() {
  auto QN = scan!long;
  auto Q = scan!long(3 * QN).chunks(3);

  auto solve() {
    bool[] ans;

    foreach(q; Q) {
      bool qa;
      foreach(i; 0..3) {
        const a = q[(i + 0) % 3];
        const b = q[(i + 1) % 3];
        const c = q[(i + 2) % 3];

        if (a > b && (a - b == c)) qa = true;
        if (a > c && (a - c == b)) qa = true;
        if (a % 2 == 0 && b == c) qa = true;
      }

      ans ~= qa;
    }

    return ans.map!(a => a ? "YES" : "NO").array;
  }

  outputForAtCoder(&solve);
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

// -----------------------------------------------

import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto a = readln.splitter.map!(to!long).array.sort.array;
    if (a[0] + a[1] == a[2]) {
      writeln("YES");
    } else {
      if ((a[0] == a[1] && a[2] % 2 == 0) ||
          (a[1] == a[2] && a[0] % 2 == 0)) {
        writeln("YES");
      } else {
        writeln("NO");
      }
    }
  }
}


import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto edges = new int[][](N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        edges[s[0] - 1] ~= s[1] - 1;
        edges[s[1] - 1] ~= s[0] - 1;
    }

    if (N == 1) {
        writeln(0);
        return;
    }

    auto dists = new int[](N);
    auto exp = new real[](N);

    void dfs1(int n, int p, int d) {
        dists[n] = d;
        foreach (m; edges[n]) if (m != p) dfs1(m, n, d + 1);
    }

    void dfs2(int n, int p, real e) {
        exp[n] = e;
        int cnt = 0;
        foreach (m; edges[n]) if (m != p) cnt += 1;
        foreach (m; edges[n]) if (m != p) dfs2(m, n, e / cnt);
    }

    dfs1(0, -1, 0);
    dfs2(0, -1, 1);
    real ans = 0;
    foreach (i; 1..N) if (edges[i].length == 1) ans += dists[i] * exp[i];
    writefln("%.9f", ans);
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio, std.string, std.conv, std.algorithm, std.array;

T[] getVals(T)() { return to!(T[])(readln().chomp().split(" ")); }

struct IP { int i; double p; }

void main() {
    int n = getVals!(int)()[0];
    Appender!(int[])[100001] aps;
    for (int i=1;i<n;i++) {
        auto xy = getVals!(int)();
        int x = xy[0], y = xy[1];
        aps[x].put(y);
        aps[y].put(x);
    }
    bool[100001] flags;
    auto temp1 = appender!(IP[])();
    temp1.put(IP(1, 1.0));
    flags[1] = true;
    auto ans = 0.0;
    for (int k = 0; k <= n; k++) {
        auto temp2 = appender!(IP[])();
        foreach (v ; temp1.data) {
            int c = 0;
            foreach (j ; aps[v.i].data) {
                if (flags[j]) { continue; }
                c++;
            }
            if (c == 0) {
                ans += double(k) * v.p;
            } else {
                auto p = v.p / double(c);
                foreach (j ; aps[v.i].data) {
                    if (flags[j]) { continue; }
                    flags[j] = true;
                    temp2.put(IP(j, p));
                }
            }
        }
        if (temp2.data.length == 0) {
            break;
        }
        temp1 = temp2;
    }
    writefln("%.8f", ans);
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto edges = new int[][](N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        edges[s[0] - 1] ~= s[1] - 1;
        edges[s[1] - 1] ~= s[0] - 1;
    }

    if (N == 1) {
        writeln(0);
        return;
    }

    long[] dists;

    void dfs(int n, int p, int d) {
        int cnt = 0;
        foreach (m; edges[n]) if (m != p) cnt += 1;
        if (cnt == 0) {
            dists ~= d;
        } else {
            foreach (m; edges[n]) if (m != p) dfs(m, n, d + 1);
        }
    }

    dfs(0, -1, 0);
    writefln("%.9f", 1.0L * dists.sum / dists.length);
}


immutable multi = true;
import std.range;

void solve(int tc)
{
	auto n = readInt!int;
	auto a = ma(n, readInt!int);
	auto b = ma(n, readInt!int);
	sort(a), sort(b);
	while (a.length && b.length)
	{
		auto fa = a.front;
		auto fb = b.front;
		if (fa > fb) return writeln("NO");
		if (fa < fb)
		{
			if (fa != fb - 1) return writeln("NO");
		}
		a.popFront; b.popFront;
	}
	if (a.length || b.length) return writeln("NO");
	return writeln("YES");
}

//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

char topChar()
{
	return cast(char) currChar;
}

void popChar()
{
	import core.stdc.stdio;
	currChar = getchar();
}

auto readInt(T)()
{
	T num = 0;
	int sgn = 0;
	while (topChar.isWhite)
	{
		popChar;
	}
	while (topChar == '-' || topChar == '+')
	{
		sgn ^= (topChar == '-');
		popChar;
	}
	while (topChar.isDigit)
	{
		num *= 10;
		num += (topChar - '0');
		popChar;
	}
	if (sgn)
		return -num;
	return num;
}

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
void writes(T...)(T t)
{
	static foreach(i, ti; t)
	{
		static if (isIterable!(T[i]))
		{
			foreach(e; ti)
			{
				write(e, " ");
			}
		}
	}
}
auto ra(V)()
{
	int n = readInt!int;
	return ma(n, readInt!V);
}
auto rt(V)()
{
	int n = readInt!int;
	int m = readInt!int;
	return ma(n, ma(m, readInt!V));
}
auto rbg()
{
	int n = readInt!int;
	int m = readInt!int;
	auto adj = new int[][](n);
	foreach(i; 0 .. m)
	{
		auto u = readInt!int - 1;
		auto v = readInt!int - 1;
		adj[u] ~= v;
		adj[v] ~= u;
	}
	return adj;
}
auto ma(V)(size_t n, lazy V v)
{
	auto arr = new V[](n);
	foreach(ref ai; arr) ai = v;
	return arr;
}
// }}}
// imports {{{
import std.stdio;
import std.algorithm;
import std.typecons;
import std.math;
import std.numeric;
import std.container;
import std.range;
import std.array;
import std.ascii;
// }}}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		auto b = readln.splitter.map !(to !(int)).array;
		sort (a);
		sort (b);
		writeln (n.iota.map !(i => b[i] - a[i])
		    .all !(x => 0 <= x && x <= 1) ? "YES" : "NO");
	}
}

// Cheese-Cracker: cheese-cracker.github.io

void solve(){
    long n = scan;
    auto a = scanArray!int;
    auto b = scanArray!int;
    auto freqa = new ll[301];
    auto freqb = new ll[301];
    auto cache = new ll[301];
    for(int i = 0; i < n; ++i){
        ++freqa[a[i] + 100];
        ++freqb[b[i] + 100];
    }
    for(int i = 0; i <= 200; ++i){
        ll take = min(freqb[i], cache[i]);
        cache[i] -= take;
        ll left = freqb[i] - take;
        freqa[i] -= left;
        if(freqa[i] < 0){
            writeln("NO");
            return;
        }
        cache[i+1] += freqa[i];
        freqa[i] = 0;
    }
    writeln("YES");
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");


import std.algorithm, std.array, std.container, std.conv, std.format, std.functional, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    string s = readln.strip;
    char minch = 'z';
    size_t minidx;
    foreach (i ; 0 .. s.length) {
      if (s[i] <= minch) {
        minch = s[i];
        minidx = i;
      }
    }
    writefln("%c %s", minch, s[0 .. minidx] ~ s[minidx + 1 .. $]);
  }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new string[](t);
	foreach (ti; 0..t)
	{
		auto s = RD!string;

		char c = 'z';
		size_t pos;
		foreach (i, e; s)
		{
			if (e < c)
			{
				pos = i;
				c = e;
			}
		}

		ans[ti] = [c, ' '];
		foreach (i, e; s)
		{
			if (i == pos) continue;
			ans[ti] ~= e;
		}
	}

	foreach (e; ans)
		writeln(e);
	stdout.flush;
	debug readln;
}


// Cheese-Cracker: cheese-cracker.github.io

void solve(){
    auto n = scan!int;
    auto m = scan!int;
    tup[] blocks;
    for(int i = 0; i < m; ++i){
        blocks ~= tup(scan!int - 1, scan!int);
    }
    blocks.sort!((a, b) => b[1] > a[1]);
    blocks ~= tup(0, n+1);
    blocks ~= tup(1, n+1);

    int norm = 0;
    int yprev = 0;
    foreach(ref block; blocks){
        if(block[1] == yprev){
            block[1] -= norm;
            continue;
        }
        int gap = (block[1] - (yprev + 1)) % 2;
        norm += (block[1] - (yprev+1) - gap);
        yprev = block[1];
        block[1] -= norm;
    }
    int len = (n+1) - norm;
    assert(len <= 1_000_000);

    auto table = new int[][](2, len+1);
    foreach(block; blocks){
        table[block[0]][block[1]] = 1;
    }
    table[0][0] = 1;
    table[1][0] = 1;
    show(table);

    for(int k = len-1; k > 0; --k){
        if(!table[0][k] && !table[1][k]){
            /* table[0][k] = 1; */
            /* table[1][k] = 1; */
        }else if(!table[0][k]){
            if(table[0][k-1]){
                writeln("NO");
                return;
            }
            table[0][k-1] = 1;
        }else if(!table[1][k]){
            if(table[1][k-1]){
                writeln("NO");
                return;
            }
            table[1][k-1] = 1;
        }
    }
    writeln("YES");
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(int, int);

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		alias Block = Tuple !(int, q{col}, int, q{row});
		auto b = new Block [m];
		foreach (ref c; b)
		{
			readf !(" %s %s") (c.row, c.col);
			c.row -= 1;
			c.col -= 1;
		}
		sort (b);

		int mask = 0;
		int prev = 0;
		bool ok = true;
		foreach (ref c; b)
		{
			if (prev % 2 != c.col % 2)
			{
				mask = (3 - mask) % 3;
				prev += 1;
			}
			if (prev != c.col)
			{
				mask %= 3;
				prev = c.col;
			}
			if (mask & (1 << c.row))
			{
				ok = false;
			}
			mask |= 1 << c.row;
		}

		ok &= (mask % 3 == 0);
		writeln (ok ? "Yes" : "No");
	}
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;

		int[int] a;
		foreach (i; 0..m)
		{
			auto r = RD!int;
			auto c = RD!int-1;
			a[c] |= r;
		}
		debug writeln("a:", a);

		auto keys = a.keys.sort;
		auto len = keys.length;
		int ud;
		int eo;
		bool ok = true;
		foreach (key; keys)
		{
			auto v = a[key];
			auto i = key;
			if (ud == 0)
			{
				if (v == 1 || v == 2)
				{
					ud = v;
					eo = i % 2;
				}
			}
			else
			{
				if (v == 3)
				{
					ok = false;
					break;
				}
				if (ud & v)
				{
					if (eo == i % 2)
					{
						ok = false;
						break;
					}
					ud = 0;
				}
				else
				{
					if (eo != i % 2)
					{
						ok = false;
						break;
					}
					ud = 0;
				}
			}
			debug writeln("ud:", ud, " eo:", eo);
		}
		if (ud != 0)
			ok = false;

		ans[ti] = ok;
	}

	foreach (e; ans)
		writeln(e ? "YES" : "NO");
	stdout.flush;
	debug readln;
}

// Cheese-Cracker: cheese-cracker.github.io

void solve(){
    auto n = scan!int;
    auto m = scan!int;
    tup[] blocks;
    for(int i = 0; i < m; ++i){
        blocks ~= tup(scan!int - 1, scan!int);
    }
    blocks.sort!((a, b) => b[1] > a[1]);
    blocks ~= tup(0, n+1);
    blocks ~= tup(1, n+1);

    int norm = 0;
    int yprev = 0;
    foreach(ref block; blocks){
        if(block[1] == yprev){
            block[1] -= norm;
            continue;
        }
        int gap = (block[1] - (yprev + 1)) % 2;
        norm += (block[1] - (yprev+1) - gap);
        yprev = block[1];
        block[1] -= norm;
    }
    int len = (n+1) - norm;
    assert(len <= 1_000_000);

    auto table = new bool[][](2, len+1);
    foreach(block; blocks){
        table[block[0]][block[1]] = 1;
    }
    table[0][0] = 1;
    table[1][0] = 1;

    for(int k = len-1; k > 0; --k){
        if(!table[0][k] && !table[1][k]){
            /* table[0][k] = 1; */
            /* table[1][k] = 1; */
        }else if(!table[0][k]){
            if(table[0][k-1]){
                writeln("NO");
                return;
            }
            table[0][k-1] = 1;
        }else if(!table[1][k]){
            if(table[0][k-1]){
                writeln("NO");
                return;
            }
            table[1][k-1] = 1;
        }
    }
    writeln("YES");
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(int, int);

// Cheese-Cracker: cheese-cracker.github.io

void solve(){
    auto n = scan!int;
    auto m = scan!int;
    tup[] blocks;
    for(int i = 0; i < m; ++i){
        blocks ~= tup(scan!int - 1, scan!int);
    }
    blocks.sort!((a, b) => b[1] > a[1]);
    blocks ~= tup(0, n+1);
    blocks ~= tup(1, n+1);

    int norm = 0;
    int yprev = 0;
    foreach(block; blocks){
        if(block[1] == yprev){
            block[1] -= norm;
            continue;
        }
        int gap = (block[1] - (yprev + 1)) % 2;
        norm += (block[1] - (yprev+1) - gap);
        yprev = block[1];
        block[1] -= norm;
    }
    int len = (n+1) - norm;
    show(len);
    assert(len <= 1_000_000);

    auto table = new bool[][](2, len+1);
    foreach(block; blocks){
        table[block[0]][block[1]] = 1;
    }
    table[0][0] = 1;
    table[1][0] = 1;

    for(int k = len-1; k > 0; --k){
        if(!table[0][k] && !table[1][k]){
            /* table[0][k] = 1; */
            /* table[1][k] = 1; */
        }else if(!table[0][k]){
            if(table[0][k-1]){
                writeln("NO");
                return;
            }
            table[0][k-1] = 1;
        }else if(!table[1][k]){
            if(table[0][k-1]){
                writeln("NO");
                return;
            }
            table[1][k-1] = 1;
        }
    }
    writeln("YES");
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(int, int);


import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	foreach(_; 0 .. rint){
		long x = rlong, y = rlong, a = rlong, b = rlong;
		if((y - x) % (a + b) == 0) ((y - x) / (a + b)).writeln;
		else (-1).writeln;
	}
}

import std.algorithm : max, maxElement;
import std.container : Array;
import std.stdio : stdin, write, writeln;
import std.typecons : Tuple, tuple;

struct IO {
    string readToken() {
        import std.range : empty, front, popFront, split;
        import std.stdio : readln;

        while (tokens.empty) {
            tokens = readln.split;
        }
        auto token = tokens.front;
        tokens.popFront;
        return token;
    }

    int readInt() {
        import std.conv : to;

        return readToken.to!int;
    }

    string[] tokens;
}

void main() {
    IO io;
    int T = io.readInt;
    while (T--) {
        int x = io.readInt;
        int y = io.readInt;
        int a = io.readInt;
        int b = io.readInt;
        if ((y - x) % (a + b)) {
            writeln(-1);
        }
        else {
            writeln((y - x) / (a + b));
        }
    }
}

import std.container;
import std.algorithm;
import std.range;
import std.array;
import std.stdio;
import std.utf;
import std.math;
import std.typecons;

alias type = multi;
struct TestCase
{
  mixin prettyPrinting;

  long x, y, a, b;

  void solve(long tc = -1)
  {
    if ((y - x) % (a + b) != 0)
      {
        writeln(-1);
      }
    else
      {
        writeln((y - x) / (a + b));
      }
  }
}

mixin template prettyPrinting()
{
  string toString()
  {
    alias structType = typeof(this);
    auto res = appender!(string)();
    res.put(structType.stringof);
    res.put("(");
    static foreach(fieldName; FieldNameTuple!structType)
      {
        res.put(text(" ", fieldName, ": ", mixin(fieldName)));
      }
    res.put(" )");
    res.put("\n");
    return res[];
  }
}

struct Graph(N)
{
  size_t size;
  this(S)(S size)
  {
    adjacencyList.length = cast(size_t) size;
    this.size = cast(size_t) size;
    this.visited = makeSlice!bool(size);
  }
  N[][] adjacencyList;
  alias ne = neighbours;
  N[] neighbours(N n)
  {
    return adjacencyList.at(n);
  }
  alias bcon = biconnect;
  void biconnect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
    adjacencyList.at(b) ~= a;
  }
  alias con = connect;
  void connect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
  }
  void connect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        connect(edge[0], edge[1]);
      }
  }
  void biconnect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        biconnect(edge[0], edge[1]);
      }
  }
  alias deg = degree!long;
  auto degree(T)(N a)
  {
    return cast(T) adjacencyList.at(a).length;
  }

  auto visited = new bool[0];
  void dfs(Visitor)(long startNode)
  {
    auto visitor = Visitor.init;
    void internalDfs(long node)
    {
      visited.set(node, true);
      static if (is(typeof({visitor.n = node;})))
        visitor.n = node;
      static if (is(typeof({visitor.pre;})))
        visitor.pre;
      foreach(w; ne(node))
        if (!visited.at(w))
          {
            static if (is(typeof({visitor.w = w;})))
              visitor.w = w;
            static if (is(typeof(visitor.pren)))
              visitor.pren;
            internalDfs(w);
            static if (is(typeof(visitor.postn)))
              visitor.postn;
          }
      static if (is(typeof(visitor.post)))
        visitor.post;
    }
    internalDfs(startNode);
  }
  void dfs(long startNode)
  {
    struct DefVisitor {}
    dfs!DefVisitor(startNode);
  }
}

DList!string _words;

template baseType(W)
{
  static if (isDynamicArray!W)
    alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));
  else
    alias baseType = W;
}

auto makeSlice(E, W, T...)(W size, T otherSizes)
{
  static if (T.length == 0)
    {
      E[] res;
      res.length = cast(size_t) size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = cast(size_t) size;
      foreach(ref row; res)
        row = makeSlice!E(otherSizes);
      return res;
    }
}

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, string))
              {
                static assert(isDynamicArray!(typeOfField)
                              , " A field with dimension initialization UDA must be a dynamic array.");
                enum uda = getUDAs!(fieldSymbol, string)[0];
                mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda, q{)});
              }
            else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
              {
                pragma(msg, "Warning: You probably want to add dimension to input ", fieldName);
              }
            read(mixin(fieldName));
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

auto next(T)()
{
  T t;
  read(t);
  return t;
}

size_t ind(T)(T t)
{
  return cast(size_t)t;
}

ref auto at(R, I)(ref R r, I i)
{
  return r[cast(size_t)i];
}

void set(R, I, V)(ref R r, I i, V v)
{
  r[cast(size_t)i] = v;
}

import std.conv;
import std.traits;
import std.meta;
int _loglevel = -1;
void _log(string functionName, argSeq...)()
{
  foreach(i; 0 .. _loglevel * 4)
    write(' ');
  write(functionName);
  static foreach(arg; argSeq)
    {
      write(" ", arg.stringof, " = ", arg);
    }
  writeln;
}
enum logCall =
  q{
    debug
    {
     {
     _loglevel++;
     alias _parameterTuple = ParameterIdentifierTuple!(mixin(split(__FUNCTION__, ".").back));
     static if (_parameterTuple.length > 0)
       mixin(`_log!(__FUNCTION__, `, [_parameterTuple].joiner(", ").array, `);`);
     else
       _log!(__FUNCTION__);
      }
     foreach(i; 0 .. _loglevel * 4) write(' ');
     writeln('{');
     scope(exit)
       {
         foreach(i; 0 .. _loglevel * 4) write(' ');
         writeln('}');
         _loglevel--;
       }
    }
};

void logSym(S...)(int line = __LINE__, string file = __FUNCTION__)
{
  debug
    {
      foreach(i; 0 .. _loglevel * 4) write(' ');
      write(file, "(", line, "):");
      static foreach(s; S)
        write(" ", s.stringof, " = ", s);
      writeln;

    }
}

Array!E makeArray(E, S)(S size, lazy E value)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  foreach(ref ai; a)
    ai = value();
  return a;
}
Array!E makeArray(E, S)(S size)
{
  auto a = Array!E();
  a.length = cast(size_t) size;
  return a;
}

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  static if (is(typeof(f(i))))
    foreach(i; 0 .. times)
      f(i);
  else
    foreach(i; 0 .. times)
      f();
}

void multi()
{
  foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

void single()
{
  auto tc = next!TestCase;
  tc.solve;
}

void main()
{
  type;
}

import std.stdio;
int main()
{
	int t=0;
	readf(" %d", &t);
	for (int i=0; i<t; i++)
	{
		int a=0;
		int b=0;
		int c=0;
		int d=0;
		readf(" %d", &a);
		readf(" %d", &b);
		readf(" %d", &c);
		readf(" %d", &d);
		if ((b-a)%(c+d)==0)
		{
			writeln((b-a)/(c+d));
		}
		else
		{
			writeln(-1);
		}
	}
	return 0;
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto x = RD;
		auto y = RD;
		auto a = RD;
		auto b = RD;
		auto d = y - x;
		if (d % (a+b) != 0)
			ans[ti] = -1;
		else
			ans[ti] = d / (a+b);
	}

	foreach (e; ans)
		writeln(e);
	stdout.flush;
	debug readln;
}


import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, s;
		readf !(" %s %s") (n, s);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;

		long [] p = [0];
		foreach (ref c; a)
		{
			p ~= p.back + c;
		}

		int half = 1;
		while (half < n + 1)
		{
			half <<= 1;
		}
		auto t = new long [half * 2];
		t[] = long.max / 4;
		t[half..half + n + 1] = p[];
		foreach_reverse (i; 1..half)
		{
			t[i] = min (t[i * 2 + 0], t[i * 2 + 1]);
		}

		long getMin (int lo, int hi)
		{
			auto res = long.max / 4;
			for (lo += half, hi += half;
			    lo < hi; lo >>= 1, hi >>= 1)
			{
				if (lo & 1)
				{
					res = min (res, t[lo]);
					lo += 1;
				}
				if (hi & 1)
				{
					hi -= 1;
					res = min (res, t[hi]);
				}
			}
			return res;
		}

		int bestLo = -1;
		int bestHi = -1;
		foreach (i; 0..n)
		{
			int lo = i;
			int hi = n + 1;
			while (hi - lo > 1)
			{
				int me = (lo + hi) / 2;
				if (s < p[i] - getMin (i, me + 1))
				{
					hi = me;
				}
				else
				{
					lo = me;
				}
			}
			if (bestHi - bestLo < lo - i)
			{
				bestLo = i;
				bestHi = lo;
			}
		}

		if (bestLo == bestHi)
		{
			writeln (-1);
		}
		else
		{
			writeln (bestLo + 1, " ", bestHi);
		}
	}
}

import std.stdio;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }

void main() {
    int T = read!int;
    foreach (t; 0 .. T) solve();
}

void solve() {
    int N; long S; readf("%d %d\n", &N, &S);
    auto A = readarray!long;

    int len = 0;
    int[] ans = [0, 0];
    int l = 0, r = 0;
    long s = S;
    while (true) {
        if (r < N && s + A[r] >= 0) {
            s += A[r];
            r++;
        } else {
            if (l == r) {
                if (l == N) break;
                s = S;
                l = l + 1;
                r = r + 1;
            } else {
                s -= A[l];
                l++;
            }
        }
        if (r - l > len) {
            ans = [l, r];
            len = r - l;
        }
    }
    if (ans[0] == ans[1]) {
        writeln(-1);
    } else {
        ans[0]++;
        writefln("%(%s %)", ans);
    }
}


import std;

void main(){
	int t=readln().strip.to!int;
	foreach(_;0..t){
		auto z=readln().strip.split.to!(int[])[1];
		auto a=readln().strip.split.to!(int[]);
		writeln(a.map!(x=>x|z).reduce!max);
	}
}

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

void main() {
  try {
    for (; ; ) {
      const numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        const N = readInt;
        const Z = readLong;
        auto A = new long[N];
        foreach (i; 0 .. N) {
          A[i] = readLong;
        }

        long ans;
        foreach (i; 0 .. N) {
          chmax(ans, Z | A[i]);
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void solve()
{
    ulong n, z;
    readf!(" %s %s")(n, z);
    readln;
    readln.splitter
        .map!(to!int)
        .map!(x => x | z)
        .maxElement!()
        .writeln;
}

void main()
{
    size_t TC = 1;
    TC = readln.strip.to!int;
    foreach (_; 0 .. TC)
        solve();
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void solve()
{
    ulong n, z;
    readf!(" %s %s")(n, z);
    readln;
    auto arr = readln.splitter.map!(to!int);
    arr.map!(x => x | z).maxElement!().writeln;
}

void main()
{
    size_t TC = 1;
    TC = readln.strip.to!int;
    foreach (_; 0 .. TC)
        solve();
}


// Vicfred
// https://codeforces.com/contest/1426/problem/D
// greedy
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.stdio;
import std.string;

void main () {
    long n = readln.chomp.to!long;

    long[] a = readln.split.map!(to!long).array;

    auto rbt = new RedBlackTree!long;
    long prefix = 0L;
    long ans = 0L;

    rbt.insert(0L);

    foreach(x; a) {
        prefix += x;
        if(prefix in rbt) {
            ans += 1L;
            rbt = new RedBlackTree!long;
            rbt.insert(0L);
            prefix = x;
        }
        rbt.insert(prefix);
    }

    ans.writeln;

}

import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }

void play(){
    int n;
    n = rd!int;
    ll[] arr = rdarr;
    ll[] pref = [0];
    foreach(el; arr){
        pref ~= el + pref.back;
    }
    int[long] vis;
    /* bool[long] seen; */
    foreach(el; pref){
        ++vis[el];
    }
    int[long] lastseen;
    ll cnt = 0;
    int lasti = -1;
    foreach(i; 0..n+1){
        assert(pref[i] in vis);
        if(vis[pref[i]] > 1){
            int prev = lastseen.get(pref[i], -1);
            if(lasti < prev){
                ++cnt;
                lasti = i - 2;
            }
        }
        lastseen[pref[i]] = i;
        /* writeln(lasti, " ", lastseen); */
    }
    writeln(cnt);
}

int main(){
    long t = 1;
    /* t = rd;        // Toggle! */
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

// Vicfred
// https://codeforces.com/contest/1426/problem/D
// greedy
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.stdio;
import std.string;

void main () {
    long n = readln.chomp.to!long;

    long[] a = readln.split.map!(to!long).array;

    auto rbt = new RedBlackTree!long;
    long prefix = 0L;
    long ans = 0L;

    rbt.insert(0L);

    foreach(x; a) {
        prefix += x;
        if(prefix in rbt) {
            ans += 1L;
            rbt.insert(0L);
            prefix = x;
        }
        rbt.insert(prefix);
    }

    ans.writeln;

}


void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, m, q; rd(n, m, q);
  auto s=readln.chomp.to!(char[]);
  auto t=readln.chomp.to!(char[]);

  auto ok=new bool[](s.length+1);
  for(int i=0; i+t.length<=s.length; i++){
    if(s[i..(i+t.length)]==t) ok[i]=true;
  }
  while(q--){
    int l, r; rd(l, r);
    l--; r--;
    int w=0;
    for(int i=l; i<=r; i++){
      if(ok[i] && i+t.length-1<=r) w++;
    }
    writeln(w);
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto Q = s[2];

    auto S = readln.chomp;
    auto T = readln.chomp;
    auto A = new int[](N+1);

    foreach (i; 0..N-M+1) {
        bool ok = true;
        foreach (j; i..i+M) {
            if (S[j] != T[j-i]) {
                ok = false;
                break;
            }
        }
        if (ok) A[i+1] += 1;
    }

    foreach (i; 0..N) A[i+1] += A[i];

    while (Q--) {
        s = readln.split.map!(to!int);
        int l = s[0] - 1;
        int r = s[1] - M;
        if (l > r)
            writeln(0);
        else
            writeln(A[r+1] - A[l]);
    }

}

import core.bitop;
import std.algorithm;
import std.array;
import std.bitmanip;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.range.interfaces;

void main()
{
    int n, m, q;
    readf("%s %s %s", &n, &m, &q);
    readln;

    auto s = readln.chomp;
    auto t = readln.chomp;

    auto cnt = new int [] (n+1);
    while (s.canFind(t)) {
        s = s.find(t);

        debug { s.writeln; }

        ++cnt[n - s.length + 1];

        s = s.dropOne();
    }

    cnt = cnt.cumulativeFold!((a, b) => a + b).array;

    debug { cnt.writeln; }

    while (q--) {
        int a, b;
        readf("%s %s", &a, &b);
        readln;

        if (b - (a-1) < t.length) {
            writeln(0);
            continue;
        }

        writeln(cnt[b - t.length + 1] - cnt[a-1]);
    }
}