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

immutable int NA = -1;

__gshared int [] [] a;
__gshared int [] p;
__gshared bool [] b;
__gshared int n;

bool find_pair (int c)
{
	if (b[c])
	{
		return false;
	}
	b[c] = true;
	foreach_reverse (d; a[c])
	{
		if (!b[d])
		{
			if (p[d] == NA || find_pair (p[d]))
			{
				debug {writeln (c, '-', d);}
				p[d] = c;
				p[c] = d;
				return true;
			}
		}
	}
	return false;
}

bool find_pair2 (int c)
{
// /*
	if (c < n / 2)
	{
		return find_pair (c);
	}
// */
	if (b[c])
	{
		return false;
	}
	b[c] = true;
	if (a[c].length == 0)
	{
		return false;
	}
/*
	foreach_reverse (d; a[c])
	{
		if (!b[d])
		{
			if (p[d] == NA || find_pair2 (p[d]))
			{
				debug {writeln (c, '-', d);}
				p[d] = c;
				p[c] = d;
				return true;
			}
		}
	}
*/
	foreach_reverse (d; a[a[c][$ - 1]])
	{
		if (!b[d])
		{
			if (p[d] == NA || find_pair2 (p[d]))
			{
				debug {writeln (c, '-', d);}
				p[d] = c;
				p[c] = d;
				return true;
			}
		}
	}

	if (a[c].length <= 1)
	{
		return false;
	}
	foreach_reverse (d; a[a[c][0]])
	{
		if (!b[d])
		{
			if (p[d] == NA || find_pair2 (p[d]))
			{
				debug {writeln (c, '-', d);}
				p[d] = c;
				p[c] = d;
				return true;
			}
		}
	}

	return false;
}

void main ()
{
	while (readf (" %s", &n) > 0)
	{
		n++;
		a = new int [] [n];
		foreach (c; 2..n)
		{
			for (int d = c * 2; d < n; d += c)
			{
				a[c] ~= d;
				a[d] ~= c;
			}
		}

		long res = 0;
		p = new int [n];
		p[] = NA;
		b = new bool [n];
		foreach_reverse (c; 2..n)
		{
			if (p[c] == NA)
			{
				if (find_pair (c))
				{
					res++;
				}
				else
				{
					b[] = false;
					if (find_pair (c))
					{
						res++;
					}
				}
				debug {writeln (p);}
			}
		}

		version (DEBUG)
		{
			int num = 0;
			foreach (c; 2..n)
			{
				if (a[c].length > 0 && p[c] == NA)
				{
					num++;
				}
			}
			writeln ("!", num);
		}

		b[] = false;
		foreach_reverse (c; 2..n)
		{
			if (p[c] == NA)
			{
				if (find_pair2 (c))
				{
					res++;
				}
				else
				{
/*
					b[] = false;
					if (find_pair2 (c))
					{
						res++;
					}
*/
				}
				debug {writeln (p);}
			}
		}

		version (DEBUG)
		{
			num = 0;
			foreach (c; 2..n)
			{
				if (a[c].length > 0 && p[c] == NA)
				{
					num++;
				}
			}
			writeln ("!", num);
		}

		foreach_reverse (c; 2..n)
		{
			if (p[c] == NA)
			{
				b[] = false;
				if (find_pair2 (c))
				{
					res++;
				}
				debug {writeln (p);}
			}
		}

		version (DEBUG)
		{
			num = 0;
			foreach (c; 2..n)
			{
				if (a[c].length > 0 && p[c] == NA)
				{
					num++;
				}
			}
			writeln ("!", num);
		}

		writeln (res);
		foreach (c; 2..n)
		{
			if (p[c] > c)
			{
				writeln (c, ' ', p[c]);
			}
		}
	}
}

import core.thread;
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.math, std.range;

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

//	chmin/chmax
void chmin(T)(ref T t, const T f) { if (t > f) t = f; }
void chmax(T)(ref T t, const T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

immutable LIM = 100005;

int N;

void main(string[] args) {
	bool[] isnp = new bool[LIM];
	for (int i = 2; i * i < LIM; ++i) if (!isnp[i]) for (int j = i * i; j < LIM; j += i) isnp[j] = true;

	try {
	for (; ; ) {
		N = readInt;

		Pair!(int, int)[] ans;
		bool[] used = new bool[N + 1];
		for (int d = N; d >= 2; --d) if (!isnp[d]) {
			int[] xs;
			for (int x = d; x <= N; x += d) if (!used[x]) {
				xs ~= x;
			}
			if (xs.length >= 2 && xs[1] == d * 2) {
				swap(xs[0], xs[1]);
			}
			for (int j = xs.length % 2; j < xs.length; j += 2) {
				ans ~= pair(xs[j], xs[j + 1]);
				used[xs[j]] = true;
				used[xs[j + 1]] = true;
			}
		}

		writeln(ans.length);
		foreach (p; ans) {
			writeln(p.x, " ", p.y);
		}

	}
	} catch (EOFException) {}
}

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

immutable int NA = -1;

__gshared int [] [] a;
__gshared int [] p;
__gshared bool [] b;
__gshared int n;

bool find_pair (int c)
{
	if (b[c])
	{
		return false;
	}
	b[c] = true;
	foreach_reverse (d; a[c])
	{
		if (!b[d])
		{
			if (p[d] == NA || find_pair (p[d]))
			{
				debug {writeln (c, '-', d);}
				p[d] = c;
				p[c] = d;
				return true;
			}
		}
	}
	return false;
}

void main ()
{
	while (readf (" %s", &n) > 0)
	{
		n++;
		a = new int [] [n];
		foreach (c; 2..n)
		{
			for (int d = c * 2; d < n; d += c)
			{
				a[c] ~= d;
				a[d] ~= c;
			}
		}

		long res = 0;
		p = new int [n];
		p[] = NA;
		b = new bool [n];
		foreach_reverse (c; 2..n)
		{
			if (p[c] == NA)
			{
				if (find_pair (c))
				{
					res++;
				}
				else
				{
					b[] = false;
					if (find_pair (c))
					{
						res++;
					}
				}
				debug {writeln (p);}
			}
		}

		writeln (res);
		foreach (c; 2..n)
		{
			if (p[c] > c)
			{
				writeln (c, ' ', p[c]);
			}
		}
	}
}

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

immutable int NA = -1;

__gshared int [] [] a;
__gshared int [] p;
__gshared bool [] b;
__gshared int n;

bool find_pair (int c)
{
	if (b[c])
	{
		return false;
	}
	b[c] = true;
	foreach_reverse (d; a[c])
	{
		if (!b[d])
		{
			if (p[d] == NA || find_pair (p[d]))
			{
				debug {writeln (c, '-', d);}
				p[d] = c;
				p[c] = d;
				return true;
			}
		}
	}
	return false;
}

void main ()
{
	while (readf (" %s", &n) > 0)
	{
		n++;
		a = new int [] [n];
		foreach (c; 2..n)
		{
			for (int d = c * 2; d < n; d += c)
			{
				a[c] ~= d;
				a[d] ~= c;
			}
		}

		long res = 0;
		p = new int [n];
		p[] = NA;
		b = new bool [n];
		foreach_reverse (c; 2..n / 2 + 1)
		{
			if (p[c] == NA)
			{
				if (find_pair (c))
				{
					res++;
				}
				else
				{
					b[] = false;
					if (find_pair (c))
					{
						res++;
					}
				}
				debug {writeln (p);}
			}
		}

		writeln (res);
		foreach (c; 2..n)
		{
			if (p[c] > c)
			{
				writeln (c, ' ', p[c]);
			}
		}
	}
}

import core.thread;
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.math, std.range;

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

//	chmin/chmax
void chmin(T)(ref T t, const T f) { if (t > f) t = f; }
void chmax(T)(ref T t, const T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

int N;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;

		Pair!(int, int)[] ans;
		bool[] used = new bool[N + 1];
		for (int d = N; d >= 2; --d) {
			int[] xs;
			for (int i = d; i <= N; i += d) if (!used[i]) {
				xs ~= i;
			}
			if (xs.length > 1 && xs.length % 2 != 0) {
				swap(xs[0], xs[1]);
			}
			for (int j = xs.length % 2; j < xs.length; j += 2) {
				ans ~= pair(xs[j], xs[j + 1]);
				used[xs[j]] = true;
				used[xs[j + 1]] = true;
			}
		}

		writeln(ans.length);
		foreach (p; ans) {
			writeln(p.x, " ", p.y);
		}

	}
	} catch (EOFException) {}
}

import core.thread;
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.math, std.range;

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

//	chmin/chmax
void chmin(T)(ref T t, const T f) { if (t > f) t = f; }
void chmax(T)(ref T t, const T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

int N;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;

		Pair!(int, int)[] ans;
		bool[] used = new bool[N + 1];
		for (int d = N; d >= 2; --d) {
			int[] xs;
			for (int i = d; i <= N; i += d) if (!used[i]) {
				xs ~= i;
			}
			if (xs.length >= 2 && xs[1] == d * 2) {
				swap(xs[0], xs[1]);
			}
			for (int j = xs.length % 2; j < xs.length; j += 2) {
				ans ~= pair(xs[j], xs[j + 1]);
				used[xs[j]] = true;
				used[xs[j + 1]] = true;
			}
		}

		writeln(ans.length);
		foreach (p; ans) {
			writeln(p.x, " ", p.y);
		}

	}
	} catch (EOFException) {}
}


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.typecons;

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

    while (t--) {
        int x1, y1, x2, y2;
        readf("%s %s %s %s", &x1, &y1, &x2, &y2);
        readln;

        auto n = x2 - x1;
        auto m = y2 - y1;

        if (n > m) { swap(n, m); }

        long sm (int k) {
            return (1 + k).to!long * k / 2;
        }

        long ans = 1 + sm(n) * 2 + n.to!long * (m - 1 - n);

        ans.writeln;
    }
}

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 row1, col1, row2, col2;
		readf !(" %s %s %s %s") (row1, col1, row2, col2);
		writeln ((row2 - row1) * 1L * (col2 - col1) + 1);
	}
}


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

  int n, m;
  rd(n, m);
  auto a = new int[][](n, m);
  foreach (i; 0 .. n) {
    a[i] = readln.split.to!(int[]);
  }
  auto b = new int[][](n, m);
  foreach (i; 0 .. n) {
    b[i] = readln.split.to!(int[]);
  }

  if (n < 2 || m < 2) {
    bool all = true;
    foreach (i; 0 .. n) {
      foreach (j; 0 .. m) {
        all &= a[i][j] == b[i][j];
      }
    }
    writeln(all ? "Yes" : "No");
    return;
  }
  foreach (i; 0 .. (n - 1)) {
    foreach (j; 0 .. (m - 1)) {
      if (a[i][j] != b[i][j]) {
        a[i][j] ^= 1;
        a[i + 1][j] ^= 1;
        a[i][j + 1] ^= 1;
        a[i + 1][j + 1] ^= 1;
      }
    }
  }
  bool all = true;
  foreach (i; 0 .. n) {
    foreach (j; 0 .. m) {
      all &= a[i][j] == b[i][j];
    }
  }
  writeln(all ? "Yes" : "No");
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}

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

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

		int [] [] a;
		foreach (i; 0..n)
		{
			a ~= readln.splitter.map !(to !(int)).array;
		}

		int [] [] b;
		foreach (i; 0..n)
		{
			b ~= readln.splitter.map !(to !(int)).array;
		}

		foreach (i; 0..n)
		{
			a[i][] ^= b[i][];
		}

		auto u = new int [n];
		auto v = new int [m];
		foreach (i; 0..n)
		{
			foreach (j; 0..m)
			{
				u[i] += a[i][j];
				v[j] += a[i][j];
			}
		}

		bool ok = true;
		ok &= u.all !(x => x % 2 == 0);
		ok &= v.all !(x => x % 2 == 0);
		writeln (ok ? "Yes" : "No");
	}
}

//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

class InputReader {
  private:
  ubyte[] p;
  ubyte[] buffer;
  size_t cur;
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
    p = stdin.rawRead (buffer);
  }
  final ubyte skipByte (ubyte lo) {
    while (true) {
      auto a = p[cur .. $];
      auto r = a.find! (c => c >= lo);
      if (!r.empty) {
        cur += a.length - r.length;
        return p[cur++];
      }
      p = stdin.rawRead (buffer);
      cur = 0;
      if (p.empty) return 0;
    }
  }
  final ubyte nextByte () {
    if (cur < p.length) {
       return p[cur++];
    }
    p = stdin.rawRead (buffer);
    if (p.empty) return 0;
    cur = 1;
    return p[0];
  }

  template next(T) if (isSigned!T) {
    final T next ()  {
      T res;
      ubyte b = skipByte (45);
      if (b == 45) {
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    final T next () {
      T res = skipByte (48) - 48;
      while (true) {
        ubyte b = nextByte ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
}

bool check (int[][] a, int[][] b, int h, int w) {
  auto r = new int[h];
  foreach (i; 0 .. h) {
    int t;
    foreach (j; 0 .. w) {
      t += a[i][j] ^ b[i][j];
    }
    if (t & 1) return false;
  }
  foreach (j; 0 .. w) {
    int t;
    foreach (i; 0 .. h) {
      t += a[i][j] ^ b[i][j];
    }
    if (t & 1) return false;
  }
  return true;
}

void main() {
  auto r = new InputReader;
  immutable h = r.next!uint;
  immutable w = r.next!uint;
  auto a = uninitializedArray!(int[][]) (h, w);
  auto b = uninitializedArray!(int[][]) (h, w);
  foreach (i; 0 .. h) foreach (j; 0 .. w) a[i][j] = r.next!uint;
  foreach (i; 0 .. h) foreach (j; 0 .. w) b[i][j] = r.next!uint;
  writeln (check (a, b, h, w) ? "Yes" : "No");
}

import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.range, 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)); }

int M, N;
int[][] A, B;

void main() {
  try {
    for (; ; ) {
      M = readInt();
      N = readInt();
      A = new int[][](M, N);
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        A[x][y] = readInt();
      }
      B = new int[][](M, N);
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        B[x][y] = readInt();
      }

      auto a = new int[][](M, N);
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        a[x][y] = A[x][y];
      }
      foreach (x; 0 .. M - 1) foreach (y; 0 .. N - 1) {
        if (a[x][y] != B[x][y]) {
          a[x][y] ^= 1;
          a[x][y + 1] ^= 1;
          a[x + 1][y] ^= 1;
          a[x + 1][y + 1] ^= 1;
        }
      }
      bool ans = true;
      foreach (x; 0 .. M) foreach (y; 0 .. N) {
        ans = ans && (a[x][y] == B[x][y]);
      }
      writeln(ans ? "Yes" : "No");
    }
  } catch (EOFException e) {
  }
}


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 bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		bool mode;
		ans[ti] = true;
		foreach (i; 0..n)
		{
			if (!mode)
			{
				if (a[i] < i)
					mode = true;
			}
			if (mode)
			{
				a[i].chmin(a[i-1]-1);
				if (a[i] < 0)
					ans[ti] = false;
			}
		}
	}

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

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;
    }

    long readLong() {
        import std.conv : to;

        return readToken.to!long;
    }

    string[] tokens;
}

bool solve(int n, int[] a) {
    bool ok = true;
    bool[] prefixOK = new bool[n];

    for (int i = 0; i < n; ++i) {
        ok &= a[i] >= i;
        prefixOK[i] = ok;
    }
    ok = true;
    for (int i = n; i--;) {
        ok &= a[i] >= n - 1 - i;
        if (prefixOK[i] && ok) {
            return true;
        }
    }
    return false;
}

void main() {
    IO io;
    int T = io.readInt;
    while (T--) {
        int n = io.readInt;
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = io.readInt();
        }
        writeln(solve(n, a) ? "Yes" : "No");
    }
}

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

DList!string _words;

void read(T...)(ref T t)
{
  void singleRead(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);
  }
  static foreach(i; 0 .. T.length)
    {
      static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))
        {
          foreach(ref element; t[i])
            read(element);
        }
      else
        {
          singleRead(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 = E.init)
{
  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;
}

void main()
{
  auto t = next!long;
  foreach(tc; 0 .. t)
    {
      auto n = next!long;
      auto a = new long[n.ind];
      read(a);
      auto inc = long(0);
      for(inc = 0; inc < n && a.at(inc) >= inc; inc++)
        {}
      if (inc == n)
        {
          writeln("Yes");
          continue;
        }
      auto dec = long(0);
      for(dec = n - 1; dec >= 0 && a.at(dec) >= (n - 1 - dec); dec--)
        {}
      if (dec == -1)
        {
          writeln("Yes");
          continue;
        }
      if (tc == 6)
        logSym!(n, a, inc, dec);
      if (dec >= inc)
        {
          writeln("No");
        }
      else
        {
          if (inc == dec + 1 && inc == n - 1 - dec)
            {
              writeln("No");
            }
          else
            {
              writeln("Yes");
            }
        }
    }
}


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

immutable int logLimit = 21;
immutable int limit = 1 << logLimit;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int h, c, t;
		readf !(" %s %s %s") (h, c, t);
		int res = 1;

		long fun (int x)
		{
			auto y = x / 2;
			auto z = x - y;
			auto num = c * 1L * y + h * 1L * z;
			return num;
		}

		void go (int x)
		{
			auto prev = fun (res);
			auto next = fun (x);
			if (abs (prev - t * 1L * res) * x >
			    abs (next - t * 1L * x) * res)
			{
				res = x;
			}
		}

		go (2);

		int lo = 2;
		int hi = limit;
		foreach (step; 0..logLimit)
		{
			auto me = (lo + hi) / 2;
			auto cur = me * 2 + 1;
			if (fun (cur) > t * 1L * cur)
			{
				lo = me + 1;
			}
			else
			{
				hi = me;
			}
		}

		foreach (i; lo - 1..lo + 2)
		{
			go (2 * i + 1);
		}

		writeln (res);
	}
}

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;

alias ll = long;
int isz(long t){ return to!int(t); }
static string[] tempstr;
T rd(T = long)() { while(!tempstr.length) tempstr = readln.chomp.split; string res = tempstr[0]; tempstr.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

double dist(ll treq, ll cups, ll c, ll h){
    ll haf = (cups - 1) / 2;
    double val = c*haf + h*(haf + 1);
    val /= cups;
    return abs(val - treq);
}

void play(){
    ll h, c, treq;
    h = rd; c = rd; treq = rd;
    /* double mid = (h + c) / 2.0; */

    if(treq >= h || h == c){
        writeln(1); return;
    }if(2*treq <= h + c){
        writeln(2); return;
    }

    // Multiple of (H - C)
    /* double temptake = (treq - c) / (h - c); */
    /*
    */
    ll num = (h - c);
    ll den = (2*treq - h - c);

    ll res = num / den;
    if(res % 2 == 0) ++res;
    if(dist(treq, res, c, h) > dist(treq, res - 2, c, h)){
        res -= 2;
    }else if (dist(treq, res, c, h) > dist(treq, res+2, c, h)){
        res += 2;
    }
    writeln(res);
}

int main(){
    ll t = 1;
    t = rd;        // Toggle!
    while(t--) play();  // Let's play!
    stdout.flush;
    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 = 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) { x.modm(y.modpow(mod - 2)); }

T binarySearch(alias pred, T)(T ok, T ng)
{
	while (abs(ok-ng) > 1)
	{
		auto mid = (ok+ng)/2;
		if (unaryFun!pred(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto h = RD;
		auto c = RD;
		auto tt = RD;

		bool f(long x)
		{
			return h*x + c*(x-1) > tt*(x*2-1);
		}
		auto r = binarySearch!(f)(0L, int.max);

		if (r == 0)
		{
			if (abs((tt - h)*2) < abs(tt*2 - (h+c)))
				ans[ti] = 1;
			else
				ans[ti] = 2;
		}
		else if (r == int.max-1)
		{
			ans[ti] = 2;
		}
		else
		{
			auto d1 = cast(double)(h*r + c*(r-1))/(r*2-1) - tt;
			auto d2 = cast(double)(h*(r+1) + c*r)/(r*2+1) - tt;
			debug writeln("r:", r, " h*(r+1):", h*(r+1), " c*r:", c*r, " d1:", d1, " d2:", d2);
			if (abs(d1) <= abs(d2))
				ans[ti] = r*2 - 1;
			else
				ans[ti] = r*2 + 1;
		}
	}

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

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;

alias ll = long;
int isz(long t){ return to!int(t); }
static string[] tempstr;
T rd(T = long)() { while(!tempstr.length) tempstr = readln.chomp.split; string res = tempstr[0]; tempstr.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

double[] ratios;
void preprocess(){
    foreach(i; 0..100000){
        ratios ~= (i + 1) / (2*i + 1);
    }
}

void play(){
    ll h, c, treq;
    h = rd; c = rd; treq = rd;
    double mid = (h + c) / 2.0;

    if(treq == h || h == c){
        writeln(1); return;
    }if(treq <= mid){
        writeln(2); return;
    }

    // Multiple of (H - C)
    /* double temptake = (treq - c) / (h - c); */
    /*
    ll lo = 0; ll hi = 100_000;
    while(hi - lo > 1){
        ll midd = (lo + hi)/2;
        if(ratios[midd] < temptake){
            hi = midd;
        }else{
            lo = midd;
        }
    }
    if(abs(ratios[lo] - temptake) < abs(ratios[hi] - temptake)){
        lo = hi;
    }
    */
    double num = (h - c);
    double den = (2*treq - h - c);
    debug writeln(num , " ", den);
    double margin = num / den;
    debug writeln(margin);
    ll res = to!ll(margin);
    if(res % 2 == 0) ++res;
    if(abs(margin - res - 2) < abs(margin - res)){
        res -= 2;
    }
    writeln(res);
}

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

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;

alias ll = long;
int isz(long t){ return to!int(t); }
static string[] tempstr;
T rd(T = long)() { while(!tempstr.length) tempstr = readln.chomp.split; string res = tempstr[0]; tempstr.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

double[] ratios;
void preprocess(){
    foreach(i; 0..100000){
        ratios ~= (i + 1) / (2*i + 1);
    }
}

void play(){
    ll h, c, treq;
    h = rd; c = rd; treq = rd;
    double mid = (h + c) / 2.0;

    if(treq == h || h == c){
        writeln(1); return;
    }if(treq <= mid){
        writeln(2); return;
    }

    // Multiple of (H - C)
    /* double temptake = (treq - c) / (h - c); */
    /*
    ll lo = 0; ll hi = 100_000;
    while(hi - lo > 1){
        ll midd = (lo + hi)/2;
        if(ratios[midd] < temptake){
            hi = midd;
        }else{
            lo = midd;
        }
    }
    if(abs(ratios[lo] - temptake) < abs(ratios[hi] - temptake)){
        lo = hi;
    }
    */
    double num = (h - c);
    double den = (treq - mid);
    debug writeln(num , " ", den);
    double margin = num / (2.0 * den);
    debug writeln(margin);
    ll res = to!ll(margin);
    if(res % 2 == 0) ++res;
    writeln(res);
}

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

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;

alias ll = long;
int isz(long t){ return to!int(t); }
static string[] tempstr;
T rd(T = long)() { while(!tempstr.length) tempstr = readln.chomp.split; string res = tempstr[0]; tempstr.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

double[] ratios;
void preprocess(){
    foreach(i; 0..100000){
        ratios ~= (i + 1) / (2*i + 1);
    }
}

void play(){
    ll h, c, treq;
    h = rd; c = rd; treq = rd;
    double mid = (h + c) / 2.0;

    if(treq >= h || h == c){
        writeln(1); return;
    }if(treq <= mid){
        writeln(2); return;
    }

    // Multiple of (H - C)
    /* double temptake = (treq - c) / (h - c); */
    /*
    */
    ll num = (h - c);
    ll den = (2*treq - h - c);
    debug writeln(num , " ", den);

    ll lo = 0; ll hi = 100_000;
    while(hi - lo > 1){
        ll midd = (lo + hi)/2;
        ll midval = 2*midd + 1;
        if(den * midval > num){
            hi = midd;
        }else{
            lo = midd;
        }
    }
    ll midval = 2 * lo + 1;
    debug writeln(midval);
    if(abs(den * midval - num) > abs(den * (midval + 2) - num)){
        midval += 2;
    }

    /* double margin = num / den; */
    /* debug writeln(margin); */
    /* ll res = to!ll(margin); */
    /* if(res % 2 == 0) ++res; */
    /* if(abs(margin - res + 2) < abs(margin - res)){ */
    /*     res -= 2; */
    /* }else if (abs(margin - res - 2) < abs(margin - res)){ */
    /*     res += 2; */
    /* } */
    /* writeln(res); */
    writeln(midval);
}

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

// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;

alias ll = long;
int isz(long t){ return to!int(t); }
static string[] tempstr;
T rd(T = long)() { while(!tempstr.length) tempstr = readln.chomp.split; string res = tempstr[0]; tempstr.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

double[] ratios;
void preprocess(){
    foreach(i; 0..100000){
        ratios ~= (i + 1) / (2*i + 1);
    }
}

void play(){
    ll h, c, treq;
    h = rd; c = rd; treq = rd;
    double mid = (h + c) / 2.0;

    if(treq == h || h == c){
        writeln(1); return;
    }if(treq <= mid){
        writeln(2); return;
    }

    // Multiple of (H - C)
    /* double temptake = (treq - c) / (h - c); */
    /*
    ll lo = 0; ll hi = 100_000;
    while(hi - lo > 1){
        ll midd = (lo + hi)/2;
        if(ratios[midd] < temptake){
            hi = midd;
        }else{
            lo = midd;
        }
    }
    if(abs(ratios[lo] - temptake) < abs(ratios[hi] - temptake)){
        lo = hi;
    }
    */
    double num = (h - c);
    double den = (2*treq - h - c);
    debug writeln(num , " ", den);
    double margin = num / den;
    debug writeln(margin);
    ll res = to!ll(margin);
    if(res % 2 == 0) ++res;
    if(abs(margin - res + 2) < abs(margin - res)){
        res -= 2;
    }else if (abs(margin - res - 2) < abs(margin - res)){
        res += 2;
    }
    writeln(res);
}

int main(){
    ll t = 1;
    /* preprocess(); */
    t = rd;        // Toggle!
    while(t--) play();  // Let's play!
    stdout.flush;
    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 = 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) { x.modm(y.modpow(mod - 2)); }

T binarySearch(alias pred, T)(T ok, T ng)
{
	while (abs(ok-ng) > 1)
	{
		auto mid = (ok+ng)/2;
		if (unaryFun!pred(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto h = RD;
		auto c = RD;
		auto tt = RD;

		bool f(long x)
		{
			return h*x + c*(x-1) > tt*(x*2-1);
		}
		auto r = binarySearch!(f)(0L, int.max);

		if (r == 0)
		{
			ans[ti] = 1;
		}
		else if (r == int.max-1)
		{
			ans[ti] = 2;
		}
		else
		{
			auto d1 = h*r + c*(r-1) - tt*2;
			auto d2 = (h+1)*r + c*r - tt*2;
			if (d1 <= d2)
				ans[ti] = r*2 + 1;
			else
				ans[ti] = (r+1)*2 + 1;
		}
	}

	foreach (e; ans)
		writeln(e);
	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(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) { x.modm(y.modpow(mod - 2)); }

T binarySearch(alias pred, T)(T ok, T ng)
{
	while (abs(ok-ng) > 1)
	{
		auto mid = (ok+ng)/2;
		if (unaryFun!pred(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto h = RD;
		auto c = RD;
		auto tt = RD;

		bool f(long x)
		{
			return h*x + c*(x-1) > tt*(x*2-1);
		}
		auto r = binarySearch!(f)(0L, int.max);

		if (r == 0)
		{
			ans[ti] = 1;
		}
		else if (r == int.max-1)
		{
			ans[ti] = 2;
		}
		else
		{
			auto d1 = h*r + c*(r-1) - tt*2;
			auto d2 = h*(r+1) + c*r - tt*2;
			if (d1 <= d2)
				ans[ti] = r*2 + 1;
			else
				ans[ti] = (r+1)*2 + 1;
		}
	}

	foreach (e; ans)
		writeln(e);
	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 bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto k = RD!int;
		auto s = RD!string;

		if (k == 0)
			ans[ti] = true;
		else if (n <= k*2)
			continue;
		else
		{
			int l, r = n-1;
			int cnt;
			while (l < r)
			{
				if (s[l] != s[r])
					break;
				++l; --r;
				++cnt;
			}
			ans[ti] = cnt >= k;
		}
	}

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

// Vicfred
// https://codeforces.com/contest/1496/problem/A
// string manipulation
import std.algorithm;
import std.stdio;
import std.conv;
import std.string;

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

  uint n, k;
  string s;
  while(t--) {
    readf("%s %s\n", &n, &k);
    readf("%s\n", &s);

    string S = s[0..k];

    if(k > (n-1)/2)
      writeln("NO");
    else if(k == 0 || s[0..k] == s[$-k..$].dup.reverse) {
      "YES".writeln;
    } else {
      "NO".writeln;
    }
  }
}

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

void theCode(){
    int n;
    n = scan!int;
    int k = scan!int;
    dchar[] arr = scan!(dchar[]);
    bool f = 1;
    for(int i = 0; i < k; ++i){
        if(arr[i] != arr[n - i - 1]){
            f = 0; break;
        }
    }
    if((n % 2 == 0 && k == n/2) || !f){
        writeln("NO");
    }else{
        writeln("YES");
    }
}

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

/*********  That's All Folks!  *********/
import std.stdio, std.random, std.functional, std.container, std.algorithm;
import std.numeric, std.range, std.typecons, std.string, std.math, std.conv;
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");

// Vicfred
// https://codeforces.com/contest/1496/problem/A
// string manipulation
import std.algorithm;
import std.stdio;
import std.conv;
import std.string;
import core.stdc.string : strlen;

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

    uint n, k;
    string s;
while(t--) {
    readf("%s %s\n", &n, &k);
    readf("%s\n", &s);

    if(k == 0) {
        "YES".writeln;
        continue;
    }

    if(2*k == n) {
        "NO".writeln;
        continue;
    }

    if(s[0..k] == s[$-k..$].dup.reverse) {
        "YES".writeln;
    } else {
        "NO".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(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 k = RD!int;
		auto s = RD!string;

		if (k == 0)
			ans[ti] = true;
		else if (n <= k*2)
			continue;
		else
		{
			int l, r = n-1;
			bool ok = true;
			while (l < r)
			{
				if (s[l] != s[r])
				{
					ok = false;
					break;
				}
				++l; --r;
			}
			ans[ti] = ok;
		}
	}

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


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.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    auto D = S.map!(c => c == 'D').sum;
    auto R = N - D;
    auto dead = new bool[](N);

    int can_kill_D, can_kill_R;

    while (D > 0 && R > 0) {
        foreach (i, c; enumerate(S)) {
            if (dead[i])
                continue;
            if (c == 'D' && can_kill_D > 0) {
                D--;
                can_kill_D--;
                dead[i] = true;
            }
            else if (c == 'D') {
                can_kill_R++;
            }
            else if (c == 'R' && can_kill_R > 0) {
                R--;
                can_kill_R--;
                dead[i] = true;
            }
            else if (c == 'R') {
                can_kill_D++;
            }
        }
    }

    writeln(D > 0 ? "D" : "R");

}

import core.bitop;
import core.checkedint;
import core.simd;
import core.stdc.stdlib;
import core.stdc.string;
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.bitmanip;
import std.complex;
import std.container;
import std.conv;
import std.datetime;
import std.format;
import std.functional;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.regex;
import std.stdio;
import std.string;
import std.typecons;
import std.variant;

__gshared:

bool read(T...)(T ptrs) if (ptrs.length > 0) {
    return readf(' ' ~ replicate("%s ", ptrs.length), ptrs) == ptrs.length;
}

T[ ] allocate(T)(size_t n) {
    return (cast(T*)malloc(n * T.sizeof))[0 .. n];
}

auto pairwise(R)(R range) if (isForwardRange!R) {
    return lockstep(range, dropOne(range));
}

int n;
char[200_001][2] s;

void main() {
    while (read(&n)) {
        auto s2 = s[0][ ];
        readln(s2);
        int cur = 0;
        int dcount, rcount;
        int delta = 0;
        do {
            int nextN = 0;
            dcount = rcount = 0;
            foreach (i; 0 .. n)
                if (s[cur][i] == 'D') {
                    if (delta++ >= 0) {
                        s[!cur][nextN++] = 'D';
                        dcount++;
                    }
                } else
                    if (delta-- <= 0) {
                        s[!cur][nextN++] = 'R';
                        rcount++;
                    }
            cur = !cur;
            n = nextN;
        } while (dcount && rcount);
        if (dcount)
            write("D\n");
        else
            write("R\n");
    }
}


import std.stdio;

bool is_prime (int n)
{
	for (int i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			return false;
		}
	}
	return true;
}

void main ()
{
	int n;
main_loop:
	while (readf (" %s", &n) > 0)
	{
		for (int k = 4; k <= n - 4; k++)
		{
			if (!is_prime (k) && !is_prime (n - k))
			{
				writeln (k, ' ', n - k);
				continue main_loop;
			}
		}
		assert (false);
	}
}

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

int main()
{
	debug
	{
		freopen(".input","r",stdin);
		freopen(".output","w",stdout);
	}

	//int n = to!(int)(readln()[0..$-1]);
	int n;
	readf("%s",&n);

	for(int i=4;i<=n-4;i++)
	{
		bool nt = false;

		for(int j=2;j<i/2;j++)
		{
			if(i % j == 0)
			{
				for(int k=2;k<n-i;k++)
				{
					if((n-i) % k == 0)
					{
						nt = true;
						break;
					}
				}

				if(nt)
					break;
			}
		}

		if(nt)
		{
			writeln(to!(string)(i) ~ " " ~ to!(string)(n-i));
			break;
		}
	}

	return 0;
}

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

int main()
{
    debug
    {
        freopen(".input","r",stdin);
        freopen(".output","w",stdout);
    }

    int n = to!(int)(readln()[0..$-1]);

    for(int i=4;i<=n-4;i++)
    {
        bool nt = false;

        for(int j=2;j<i/2;j++)
        {
            if(i % j == 0)
            {
                for(int k=2;k<n-i;k++)
                {
                    if((n-i) % k == 0)
                    {
                        nt = true;
                        break;
                    }
                }

                if(nt)
                    break;
            }
        }

        if(nt)
        {
            writeln(to!(string)(i) ~ " " ~ to!(string)(n-i));
            break;
        }
    }

    return 0;
}

import core.thread;
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;

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

//	chmin/chmax
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	int opCmp(    const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	int opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }
	string toString() const { return "(" ~ to!string(x) ~ ", " ~ to!string(y) ~ ")"; }
}
auto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

int N;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;

		bool[] isnp = new bool[N + 1];
		foreach (i; 2 .. isnp.length) if (!isnp[i]) for (int j = i * i; j < isnp.length; j += i) isnp[j] = true;

		for (int x = 2; x <= N - 2; ++x) {
			const y = N - x;
			if (isnp[x] && isnp[y]) {
				writeln(x, " ", y);
				break;
			}
		}
	}
	} catch (EOFException) {}
}

import std.stdio;
import std.string;
import std.algorithm;
import core.stdc.stdio;
import std.bigint;
import std.format;
import std.math;

string readline()
{
	string result = readln();
	if (result[result.length - 1] == '\n') result.length--;
	return result;
}

bool isPrime(long x)
{
	foreach (long i; 2..(x/2 + 1))
	{
		if (x % i == 0)
			return false;
	}
	return true;
}

int main(string[] argv)
{
	long n;
	scanf("%d", &n);
	long x, y;
	x = n / 2;
	y = n / 2;
	if (x + y != n) y++;
	foreach (long i; 0..x)
	{
		if (!isPrime(x - i) && !isPrime(y + i))
		{
			printf("%d ", x - i);
			printf("%d", y + i);
			return 0;
		}
	}
	return 0;
}

import std.stdio;
import std.string;
import std.algorithm;
import core.stdc.stdio;
import std.bigint;
import std.format;
import std.math;

string readline()
{
	string result = readln();
	if (result[result.length - 1] == '\n') result.length--;
	return result;
}

bool isPrime(long x)
{
	foreach (long i; 2..(x/2))
	{
		if (x % i == 0)
			return false;
	}
	return true;
}

int main(string[] argv)
{
	long n;
	scanf("%d", &n);
	long x, y;
	x = n / 2;
	y = n / 2;
	if (x + y != n) y++;
	foreach (long i; 0..x)
	{
		x -= i;
		y += i;
		if (!isPrime(x) && !isPrime(y))
		{
			printf("%d ", x);
			printf("%d", y);
			return 0;
		}
	}
	return 0;
}

import std.stdio;
import std.string;
import std.algorithm;
import core.stdc.stdio;
import std.bigint;
import std.format;
import std.math;

string readline()
{
	string result = readln();
	if (result[result.length - 1] == '\n') result.length--;
	return result;
}

bool isPrime(long x)
{
	foreach (long i; 2..(x/2 + 1))
	{
		if (x % i == 0)
			return false;
	}
	return true;
}

int main(string[] argv)
{
	long n;
	scanf("%d", &n);
	long x, y;
	x = n / 2;
	y = n / 2;
	if (x + y != n) y++;
	foreach (long i; 0..x)
	{
		x -= 1;
		y += 1;
		if (!isPrime(x) && !isPrime(y))
		{
			printf("%d ", x);
			printf("%d", y);
			return 0;
		}
	}
	return 0;
}


immutable multi = true;

void solve(int tc)
{
  return writeln((readInt!int + readInt!int*0 + readInt!int)&1);
}

// main {{{
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.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 long[](t);
	foreach (ti; 0..t)
	{
		auto a = RD;
		auto b = RD;
		auto c = RD;

		auto tot = a + b*2 + c*3;
		auto half = tot / 2;
		debug writeln(half);
		half -= min(c, half / 3) * 3;
		debug writeln(half);
		half -= min(b, half / 2) * 2;
		debug writeln(half);
		half -= min(a, half);
		debug writeln(half);
		ans[ti] = half * 2 + tot % 2;
	}

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

immutable multi = true;

void solve(int tc)
{
  return writeln((readInt!int + readInt!int + readInt!int)&1);
}

// main {{{
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.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 n;
  @("n") long[] a;
  @("n") long[] b;

  void solve(long tc = -1)
  {
    logSym!this;
    auto oa = a.fold!min(long.max);
    auto ob = b.fold!min(long.max);
    auto res = long(0);
    foreach(i; 0 .. n)
      {
        auto opa = a.at(i) - oa;
        auto opb = b.at(i) - ob;
        auto common = min(opa, opb);
        logSym!(opa, opb, common);
        res += opa + opb - common;
      }
    writeln(res);
  }
}

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 w)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(w)
          {
            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)
              {
                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, 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 long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		auto b = RDA;

		long min_a = long.max;
		long min_b = long.max;
		foreach (i; 0..n)
		{
			min_a.chmin(a[i]);
			min_b.chmin(b[i]);
		}

		foreach (i; 0..n)
		{
			auto da = a[i] - min_a;
			auto db = b[i] - min_b;
			ans[ti] += max(da, db);
		}
	}

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

import std.stdio;
import std.algorithm : map, min, minElement, sum;
import std.range : zip;
import std.string : strip, split;
import std.conv : to;

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

  foreach (i; 0..t) {
    int n;
    readf!"%d\n"(n);
    auto a = readln.strip.split.map!(to!long);
    auto b = readln.strip.split.map!(to!long);

    auto mina = a.minElement;
    auto minb = b.minElement;

    auto c = zip(a, b)
      .map!(a => (a[0] - mina) + (a[1] - minb) - min(a[0] - mina, a[1] - minb))
      .sum;

    writefln("%d", c);
  }
}


// Code By H~$~C

module main;

import core.stdc.stdlib, core.stdc.string;
import std.stdio, std.array, std.string, std.math, std.uni;
import std.algorithm, std.range, std.random, std.container;
import std.conv, std.typecons, std.functional;

immutable Maxn = 200005;

struct node {
  this()() {
    mn = lnf;
    tag = 0;
  }
  this()(in node x) { *this = x; }
  long mn, tag;
  void apply(int l, int r, long x) {
    mn += x, tag += x;
  }
}
void pullup(ref node a, in node b, in node c) {
  a.mn = min(b.mn, c.mn);
}
struct segment_tree {
  int N;
  node[] tr;
  private void pushup(int p) {
    pullup(tr[p], tr[p * 2], tr[p * 2 + 1]);
  }
  private void modify_(T...)(int p, int l, int r, int L, int R, T args) {
    if (L == l && r == R) return tr[p].apply(l, r, args);
    pushdown(p, l, r);
    int mid = (l + r) >> 1;
    if (R <= mid) modify_(p * 2, l, mid, L, R, args);
    else if (L > mid) modify_(p * 2 + 1, mid + 1, r, L, R, args);
    else {
      modify_(p * 2, l, mid, L, mid, args);
      modify_(p * 2 + 1, mid + 1, r, mid + 1, R, args);
    }
    pushup(p);
  }
  private node query_(int p, int l, int r, int L, int R) {
    if (L == l && r == R) return tr[p];
    pushdown(p, l, r);
    int mid = (l + r) >> 1;
    if (R <= mid) return query_(p * 2, l, mid, L, R);
    if (L > mid) return query_(p * 2 + 1, mid + 1, r, L, R);
    node left = query_(p * 2, l, mid, L, mid);
    node right = query_(p * 2 + 1, mid + 1, r, mid + 1, R);
    node ans; pullup(ans, left, right); return ans;
  }
  public void build(T...)(int len, T args) {
    N = len;
    tr.length = (N + 1) << 2;
    build(1, 1, N, args);
  }
  public void modify(T...)(int L, int R, T args) {
    if (L > R) return ;
    modify_(1, 1, N, L, R, args);
  }
  public node query(int L, int R) {
    if (L > R) return node();
    return query_(1, 1, N, L, R);
  }
  private void pushdown(int p, int l, int r) {
    int mid = (l + r) >> 1;
    if (tr[p].tag != 0) {
      tr[p * 2].apply(l, mid, tr[p].tag);
      tr[p * 2 + 1].apply(mid + 1, r, tr[p].tag);
      tr[p].tag = 0;
    }
  }
  private void build(int p, int l, int r, in long[] args) {
    if (l == r) {
      tr[p].apply(l, r, args[l]);
      return ;
    }
    int mid = (l + r) >> 1;
    build(p * 2, l, mid, args);
    build(p * 2 + 1, mid + 1, r, args);
    pushup(p);
  }
}
segment_tree sgt;

void solve(in int testcase) {
  int n; n.read;
  long[Maxn] arr;
  arr[1 .. n + 1] = readarray!long;
  sgt.build(n, arr);
  int q; q.read;
  while (q--) {
    int[] fuck = readarray!int.map!(a => a + 1).array;
    if (fuck.length == 2) {
      int l = fuck[0], r = fuck[1];
      if (l <= r) sgt.query(l, r).mn.writeln;
      else min(sgt.query(1, r).mn, sgt.query(l, n).mn).writeln;
    }
    else {
      int l = fuck[0], r = fuck[1];
      int x = fuck[2] - 1;
      if (l <= r) sgt.modify(l, r, x);
      else sgt.modify(1, r, x), sgt.modify(l, n, x);
    }
  }
}

// ************************************************************

T reader(T)() { return readToken().to!T; }
void read(T)(ref T t) { t = reader!T; }
T[] readarray(T)() { return readln.splitter.map!(to!T).array; }
void chmax(T)(ref T a, T b) { a = max(a, b); }
void chmin(T)(ref T a, T b) { a = min(a, b); }
alias less = (a, b) => a < b;
alias greater = (a, b) => a > b;
T min_element(T)(in T[] a) { return a.element!less; }
T max_element(T)(in T[] a) { return a.element!greater; }
alias unique = uniq;

// constant or some variables
immutable int inf = 0x3f3f3f3f;
immutable long lnf = 0x3f3f3f3f3f3f3f3f;
immutable typeof(null) NULL = null;
string[] _tokens;

// functions
T element(alias pred, T)(in T[] a) {
  int pos = 0;
  for (int i = 1; i < cast(int)(a.length); ++i)
    if (binaryFun!pred(a[i], a[pos])) pos = i;
  return a[pos];
}
string readToken() {
  for (; _tokens.empty; ) {
    if (stdin.eof) return "";
    _tokens = readln.split;
  }
  auto token = _tokens.front;
  _tokens.popFront;
  return token;
}
int binary_bearch(alias pred, T)(in T[] as) {
  int l = -1, h = cast(int)(as.length), mid;
  for (; l + 1 < h; ) {
    mid = (l + h) >> 1;
    (unaryFun!pred(as[mid]) ? h : l) = mid;
  }
  return h;
}
int lower_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => a == val || pred(val, a));
}
int upper_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => pred(val, a));
}

void main(string[] args) {
  int tests = 1;
//  tests.read();
  foreach(test; 1 .. tests + 1) solve(test);
}

// Cheese-Cracker: cheese-cracker.github.io
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; }
/*******************************It's a Me, Mario!*******************************************/

ll[] arr, segtree, delta;
const ll LMAX = to!ll(1e15);

ll build(int v, ll l, ll r){
    if(l == r){ return (segtree[v] = arr[to!int(l)]); }

    ll midd = (l + r)/2;
    return (segtree[v] = min(build(2*v, l, midd), build(2*v + 1, midd + 1, r)));
}

void apply(int v){
    segtree[2*v] += delta[v];
    segtree[2*v+1] += delta[v];
    delta[2*v] += delta[v];
    delta[2*v+1] += delta[v];
    delta[v] = 0;
}

ll query(int v, ll l, ll r, ll L, ll R){
    if(L > R){ return LMAX; }
    if(L <= l && r <= R){
        return segtree[v];
    }
    apply(v);
    ll midd = (l + r)/2;
    ll lq = query(2*v, l, midd, L, min(midd, R));
    ll hq = query(2*v + 1, midd+1, r, max(midd+1, L), R);
    /* debug writeln(lq, " ", hq); */
    return min(lq, hq);
}

void update(int v, ll l, ll r, ll L, ll R, ll incr){
    if(L > R || l > R || r < L || l > r){ return; }
    if(L <= l && r <= R){
        segtree[v] += incr;
        delta[v] += incr;
        return;
    }
    /* writeln(v, " ", l, " ", r, " ", L, " ", R); */
    apply(v);
    ll midd = (l + r)/2;
    update(2*v, l, midd, L, R, incr);
    update(2*v+1, midd+1, r, L, R, incr);

    // Note: Even if we HAVE to take Min of Segtree Values NOT update return values.
    // Since it may not update and return INF
    segtree[v] = min(segtree[2*v], segtree[2*v+1]);
}

void play(){
    int n, m;
    n = rd!int;
    segtree.length = 4*n+1;
    delta.length = 4*n+1;
    arr = rdarr;
    build(1, 0, n-1);
    m = rd!int;
    while(m--){
        ll[] reds = rdarr;
        ll l = reds[0], r = reds[1];
        if(reds.length == 3){
            if(l > r){
                update(1, 0, n-1, l, n-1, reds[2]);
                update(1, 0, n-1, 0, r, reds[2]);
            }else{
                update(1, 0, n-1, l, r, reds[2]);
            }
        }else{
            ll res;
            if(l > r){
                res = min(query(1, 0, n-1, l, n-1), query(1, 0, n-1, 0, r));
            }else{
                res = query(1, 0, n-1, l, r);
            }
            writeln(res);
        }
        /* debug{ writeln(segtree);} */
    }
}

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

// Cheese-Cracker: cheese-cracker.github.io
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; }
/*******************************It's a Me, Mario!*******************************************/

ll[] arr, segtree, delta;

ll build(int v, ll l, ll r){
    if(l == r){ return (segtree[v] = arr[to!int(l)]); }

    ll midd = (l + r)/2;
    return (segtree[v] = min(build(2*v, l, midd), build(2*v + 1, midd + 1, r)));
}

ll query(int v, ll l, ll r, ll L, ll R){
    if(l > r || r < L || l > R){ return to!ll(1e8); }
    if(L <= l && r <= R){
        return segtree[v];
    }
    if(delta[v]) apply(v);
    ll midd = (l + r)/2;
    return min(query(2*v, l, midd, L, R), query(2*v + 1, midd+1, r, L, R));
}

void apply(int v){
    segtree[2*v] += delta[v];
    segtree[2*v+1] += delta[v];
    delta[2*v] = (delta[2*v+1] = delta[v]);
    delta[v] = 0;
}

ll update(int v, ll l, ll r, ll L, ll R, ll incr){
    if(l > r || r < L || l > R){ return to!ll(1e8); }
    if(L <= l && r <= R){
        segtree[v] += incr;
        delta[v] += incr;
        return segtree[v];
    }
    if(delta[v]) apply(v);
    ll midd = (l + r)/2;
    return segtree[v] = min(update(2*v, l, midd, L, R, incr), update(2*v+1, midd+1, r, L, R, incr));
}

void play(){
    int n, m;
    n = rd!int;
    segtree.length = 4*n+1;
    delta.length = 4*n+1;
    arr = rdarr;
    build(1, 0, n-1);
    m = rd!int;
    while(m--){
        ll[] reds = rdarr;
        ll l = reds[0], r = reds[1];
        if(reds.length == 3){
            if(l > r){
                update(1, 0, n-1, l, n-1, reds[2]);
                update(1, 0, n-1, 0, r, reds[2]);
            }else{
                update(1, 0, n-1, l, r, reds[2]);
            }
        }else{
            ll res;
            if(l > r){
                res = min(query(1, 0, n-1, l, n-1), query(1, 0, n-1, 0, r));
            }else{
                res = query(1, 0, n-1, l, r);
            }
            writeln(res);
        }
        debug{ writeln(segtree);}
    }
}

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

// Cheese-Cracker: cheese-cracker.github.io
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; }
/*******************************It's a Me, Mario!*******************************************/

ll[] arr, segtree, delta;
const ll LMAX = to!ll(1e12);

ll build(int v, ll l, ll r){
    if(l == r){ return (segtree[v] = arr[to!int(l)]); }

    ll midd = (l + r)/2;
    return (segtree[v] = min(build(2*v, l, midd), build(2*v + 1, midd + 1, r)));
}

ll query(int v, ll l, ll r, ll L, ll R){
    if(l > r || r < L || l > R){ return LMAX; }
    if(L <= l && r <= R){
        return segtree[v];
    }
    if(delta[v]) apply(v);
    ll midd = (l + r)/2;
    return min(query(2*v, l, midd, L, R), query(2*v + 1, midd+1, r, L, R));
}

void apply(int v){
    segtree[2*v] += delta[v];
    segtree[2*v+1] += delta[v];
    delta[2*v] = (delta[2*v+1] = delta[v]);
    delta[v] = 0;
}

ll update(int v, ll l, ll r, ll L, ll R, ll incr){
    if(l > r || r < L || l > R){ return LMAX; }
    if(L <= l && r <= R){
        segtree[v] += incr;
        delta[v] += incr;
        return segtree[v];
    }
    if(delta[v]) apply(v);
    ll midd = (l + r)/2;
    return segtree[v] = min(update(2*v, l, midd, L, R, incr), update(2*v+1, midd+1, r, L, R, incr));
}

void play(){
    int n, m;
    n = rd!int;
    segtree.length = 4*n+1;
    delta.length = 4*n+1;
    arr = rdarr;
    build(1, 0, n-1);
    m = rd!int;
    while(m--){
        ll[] reds = rdarr;
        ll l = reds[0], r = reds[1];
        if(reds.length == 3){
            if(l > r){
                update(1, 0, n-1, l, n-1, reds[2]);
                update(1, 0, n-1, 0, r, reds[2]);
            }else{
                update(1, 0, n-1, l, r, reds[2]);
            }
        }else{
            ll res;
            if(l > r){
                res = min(query(1, 0, n-1, l, n-1), query(1, 0, n-1, 0, r));
            }else{
                res = query(1, 0, n-1, l, r);
            }
            writeln(res);
        }
        debug{ writeln(segtree);}
    }
}

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

// Code By H~$~C

module main;

import core.stdc.stdlib, core.stdc.string;
import std.stdio, std.array, std.string, std.math, std.uni;
import std.algorithm, std.range, std.random, std.container;
import std.conv, std.typecons, std.functional;

immutable Maxn = 200005;

struct node {
  this()() {
    mn = lnf;
    tag = 0;
  }
  this()(in node x) { *this = x; }
  long mn, tag;
  void apply(int l, int r, long x) {
    mn += x, tag += x;
  }
}
void pullup(ref node a, in node b, in node c) {
  a.mn = min(b.mn, c.mn);
}
struct segment_tree {
  int N;
  node[] tr;
  private void pushup(int p) {
    pullup(tr[p], tr[p * 2], tr[p * 2 + 1]);
  }
  private void modify_(T...)(int p, int l, int r, int L, int R, T args) {
    if (L == l && r == R) return tr[p].apply(l, r, args);
    pushdown(p, l, r);
    int mid = (l + r) >> 1;
    if (R <= mid) modify_(p * 2, l, mid, L, R, args);
    else if (L > mid) modify_(p * 2 + 1, mid + 1, r, L, r, args);
    else {
      modify_(p * 2, l, mid, L, mid, args);
      modify_(p * 2 + 1, mid + 1, r, mid + 1, R, args);
    }
    pushup(p);
  }
  private node query_(int p, int l, int r, int L, int R) {
    if (L == l && r == R) return tr[p];
    pushdown(p, l, r);
    int mid = (l + r) >> 1;
    if (R <= mid) return query_(p * 2, l, mid, L, R);
    if (L > mid) return query_(p * 2 + 1, mid + 1, r, L, R);
    node left = query_(p * 2, l, mid, L, mid);
    node right = query_(p * 2 + 1, mid + 1, r, mid + 1, R);
    node ans; pullup(ans, left, right); return ans;
  }
  public void build(T...)(int len, T args) {
    N = len;
    tr.length = (N + 1) << 2;
    build(1, 1, N, args);
  }
  public void modify(T...)(int L, int R, T args) {
    if (L > R) return ;
    modify_(1, 1, N, L, R, args);
  }
  public node query(int L, int R) {
    if (L > R) return node();
    return query_(1, 1, N, L, R);
  }
  private void pushdown(int p, int l, int r) {
    int mid = (l + r) >> 1;
    if (tr[p].tag != 0) {
      tr[p * 2].apply(l, mid, tr[p].tag);
      tr[p * 2 + 1].apply(mid + 1, r, tr[p].tag);
      tr[p].tag = 0;
    }
  }
  private void build(int p, int l, int r, in long[] args) {
    if (l == r) {
      tr[p].apply(l, r, args[l]);
      return ;
    }
    int mid = (l + r) >> 1;
    build(p * 2, l, mid, args);
    build(p * 2 + 1, mid + 1, r, args);
    pushup(p);
  }
}
segment_tree sgt;

void solve(in int testcase) {
  int n; n.read;
  long[Maxn] arr;
  arr[1 .. n + 1] = readarray!long;
  sgt.build(n, arr);
  int q; q.read;
  while (q--) {
    int[] fuck = readarray!int.map!(a => a + 1).array;
    if (fuck.length == 2) {
      int l = fuck[0], r = fuck[1];
      if (l <= r) sgt.query(l, r).mn.writeln;
      else min(sgt.query(1, r).mn, sgt.query(l, n).mn).writeln;
    }
    else {
      int l = fuck[0], r = fuck[1];
      int x = fuck[2] - 1;
      if (l <= r) sgt.modify(l, r, x);
      else sgt.modify(1, r, x), sgt.modify(l, n, x);
    }
  }
}

// ************************************************************

T reader(T)() { return readToken().to!T; }
void read(T)(ref T t) { t = reader!T; }
T[] readarray(T)() { return readln.splitter.map!(to!T).array; }
void chmax(T)(ref T a, T b) { a = max(a, b); }
void chmin(T)(ref T a, T b) { a = min(a, b); }
alias less = (a, b) => a < b;
alias greater = (a, b) => a > b;
T min_element(T)(in T[] a) { return a.element!less; }
T max_element(T)(in T[] a) { return a.element!greater; }
alias unique = uniq;

// constant or some variables
immutable int inf = 0x3f3f3f3f;
immutable long lnf = 0x3f3f3f3f3f3f3f3f;
immutable typeof(null) NULL = null;
string[] _tokens;

// functions
T element(alias pred, T)(in T[] a) {
  int pos = 0;
  for (int i = 1; i < cast(int)(a.length); ++i)
    if (binaryFun!pred(a[i], a[pos])) pos = i;
  return a[pos];
}
string readToken() {
  for (; _tokens.empty; ) {
    if (stdin.eof) return "";
    _tokens = readln.split;
  }
  auto token = _tokens.front;
  _tokens.popFront;
  return token;
}
int binary_bearch(alias pred, T)(in T[] as) {
  int l = -1, h = cast(int)(as.length), mid;
  for (; l + 1 < h; ) {
    mid = (l + h) >> 1;
    (unaryFun!pred(as[mid]) ? h : l) = mid;
  }
  return h;
}
int lower_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => a == val || pred(val, a));
}
int upper_bound(alias pred = less, T)(in T[] as, T val) {
  return as.binary_bearch!(a => pred(val, a));
}

void main(string[] args) {
  int tests = 1;
//  tests.read();
  foreach(test; 1 .. tests + 1) solve(test);
}