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

immutable int NA = -1;

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 x = a.count !(v => v % 2 == 0).to !(int);
		auto y = n - x;
		debug {writeln (x, " ", y);}
		auto f = new int [2] [] [] (x + 1, y + 1);
		foreach (ref g; f)
		{
			foreach (ref h; g)
			{
				h[] = NA;
			}
		}

		int go (int i, int j, int b)
		{
			if (f[i][j][b] == NA)
			{
				if (i == x && j == y)
				{
					return !b ^ ((i + j) & 1);
				}
				int res = 0;
				if (i < x)
				{
					res |= !go (i + 1, j, b);
				}
				if (j < y)
				{
					res |= !go (i, j + 1,
					    !b ^ ((i + j) & 1));
				}
				f[i][j][b] = res;
			}
			return f[i][j][b];
		}

		writeln (go (0, 0, 0) ? "Alice" : "Bob");
	}
}

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

void solve() {
    int N = readln.chomp.to!int;
    auto A = readln.chomp.split(" ").map!(to!int).array;

    auto init = tuple(0, 0);
    foreach (a; A) {
        if (a % 2 == 0) {
            init[0]++;
        } else {
            init[1]++;
        }
    }

    bool[Tuple!(int,int,int,int)] cache;
    int f(int p, int s, int e, int o) {
        // p: 0:alice, 1:bob
        // s: alice's hand
        auto key = tuple(p, s, e, o);
        if (key in cache) return cache[key];
        if (e == 0 && o == 0) {
            return (p == 0 && s == 0) || (p == 1 && s == 1);
        }
        if (p == 0) {
            bool a_win = false;
            // alice's turn
            if (e >= 1) { a_win = a_win || !f(!p, s, e-1, o); }
            if (o >= 1) { a_win = a_win || !f(!p, !s, e, o-1); }
            return cache[key] = a_win;
        } else {
            bool b_win = false;
            if (e >= 1) { b_win = b_win || !f(!p, s, e-1, o); }
            if (o >= 1) { b_win = b_win || !f(!p, s, e, o-1); }
            return cache[key] = b_win;
        }
    }
    writeln(f(0, 0, init[0], init[1]) ? "Alice" : "Bob");
}

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

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

enum LIM = 105;

void main() {
  auto ali = new bool[][][](LIM, LIM, 2);
  auto bob = new bool[][][](LIM, LIM, 2);
  foreach (m; 0 .. LIM) foreach (n; 0 .. LIM) foreach (s; 0 .. 2) {
    if (m == 0 && n == 0) {
      ali[m][n][s] = (s == 0);
      bob[m][n][s] = (s != 0);
    } else {
      if (m > 0 && !bob[m - 1][n][s ^ 0]) ali[m][n][s] = true;
      if (n > 0 && !bob[m][n - 1][s ^ 1]) ali[m][n][s] = true;
      if (m > 0 && !ali[m - 1][n][s]) bob[m][n][s] = true;
      if (n > 0 && !ali[m][n - 1][s]) bob[m][n][s] = true;
    }
  }
  debug {
    foreach (m; 0 .. 10) write(m, ": ", ali[m]);
    foreach (m; 0 .. 10) write(m, ": ", bob[m]);
  }

  try {
    for (; ; ) {
      const numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        const N = readInt;
        auto A = new int[N];
        foreach (i; 0 .. N) {
          A[i] = readInt;
        }

        int[2] cnt;
        foreach (i; 0 .. N) {
          ++cnt[A[i] & 1];
        }
        const ans = ali[cnt[0]][cnt[1]][0];
        writeln(ans ? "Alice" : "Bob");
      }
    }
  } catch (EOFException e) {
  }
}

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

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 x = a.count !(v => v % 2 == 0).to !(int);
		auto y = n - x;
		debug {writeln (x, " ", y);}
		auto f = new bool [2] [] [] (x + 1, y + 1);
		f[x][y][0] = true;
		foreach_reverse (t; 0..x + y)
		{
			foreach (i; 0..x + 1)
			{
				int j = t - x;
				if (!(0 <= j && j <= y))
				{
					continue;
				}
				foreach (b; 0..2)
				{
					if (t & 1) // Bob moves
					{
						f[i][j][b] = true;
						if (i < x)
						{
							f[i][j][b] &= f[i + 1][j][b ^ 0];
						}
						if (j < y)
						{
							f[i][j][b] &= f[i][j + 1][b ^ 0];
						}
					}
					else // Alice moves
					{
						f[i][j][b] = false;
						if (i < x)
						{
							f[i][j][b] |= f[i + 1][j][b ^ 0];
						}
						if (j < y)
						{
							f[i][j][b] |= f[i][j + 1][b ^ 1];
						}
					}
				}
			}
		}
		debug {writefln !("%(%(%(%d%) %)\n%)") (f);}
		writeln (f[0][0][0] ? "Alice" : "Bob");
	}
}


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

string FMT_F = "%.10f";

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; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
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; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long 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 main()
{
	auto q = RD!int;
	auto ans = new long[](q);
	foreach (i; 0..q)
	{
		auto n = RD!int;
		auto a = RDA;
		auto s = a.sum;
		ans[i] = s / n + (s % n != 0 ? 1 : 0);
	}

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

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


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 N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;

    if (A.sum % 2 == 1) {
        writeln("NO");
        return;
    }

    if (A.reduce!max > A.sum - A.reduce!max) {
        writeln("NO");
    } else {
        writeln("YES");
    }
}

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

const int MAX_N = 100000;
int n;

void main() {
  readln.strip.formattedRead(" %s", n);

  auto a = readln.strip.split.map!(a => parse!long(a));

  long total = a.sum;

  bool ok = total % 2 == 0;

  ok &= a.all!(v => v*2 <= total);

  if (ok) {
    writeln("YES");
  } else {
    writeln("NO");
  }
}


import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		auto s = new char [n];
		if (k > n)
		{
			s = cast (char []) "-1";
		}
		else if (k == 1)
		{
			if (n == 1)
			{
				s = cast (char []) "a";
			}
			else
			{
				s = cast (char []) "-1";
			}
		}
		else
		{
			foreach (i; 0..n)
			{
				s[i] = 'a' + (i & 1);
			}
			foreach (i; 0..k - 2)
			{
				s[$ - 1 - i] = cast (char) ('a' + (k - 1 - i));
			}
		}
		writeln (s);
	}
}

module sigod.codeforces.p289C;

import std.array;
import std.stdio;

void main()
{
	int n, k;
	stdin.readf("%s %s", &n, &k);

	stdout.writeln(solve(n, k));
}

string solve(int n, int k)
{
	if (n < k) return "-1";
	if (k == 1) {
		if (n == 1) return "a";
		else return "-1";
	}

	auto result = appender!string();
	result.reserve(n);

	int g = n - max(k - 2, 0);

	foreach (i; 0 .. g / 2) {
		result.put("ab");
	}

	if (g % 2 != 0) result.put('a');

	foreach (i; 99 .. 99 + max(k - 2, 0)) {
		result.put(cast(char) i);
	}

	return result.data();
}

unittest {
	assert(solve(7, 4) == "ababacd");
	assert(solve(4, 7) == "-1");
}

pure int max(int a, int b)
{
	if (a > b) return a;
	else return b;
}


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 double[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		a.sort;

		ans[ti] = cast(double)(a[0..$-1].sum) / (n-1);
		ans[ti] += a[$-1];
	}

	foreach (e; ans)
		writefln(FMT_F, e);
	stdout.flush;
	debug readln;
}

immutable multi = true;

void solve(int tc)
{
	auto a = ra!long;
	sort(a);
	auto sp = a.sum;
	double ans = -1e11;
	long ss = 0;
	int pl = cast(int)a.length;
	foreach_reverse(ai; a)
	{
		sp -= ai;
		ss += ai;
		pl--;
		if (pl > 0)
		ans = max(ans, sp/(cast(double)pl) + ss/(cast(double)(a.length - pl)));
	}
	writef!"%.12s\n"(ans);
}

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

immutable multi = true;

void solve(int tc)
{
	auto a = ra!long;
	sort(a);
	auto sp = a.sum;
	double ans = -1e11;
	long ss = 0;
	int pl = cast(int)a.length;
	foreach_reverse(ai; a)
	{
		sp -= ai;
		ss += ai;
		pl--;
		if (pl > 0)
		ans = max(ans, sp/(cast(double)pl) + ss/(cast(double)(a.length - pl)));
	}
	ans.writeln;
}

// 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;
}
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.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);
        if (n % 2 == 0) {
            writeln((k - 1) % n + 1);
        } else if (k <= n) {
            writeln(k == n ? 2 : k + (k >= (n+1)/2 ? 1 : 0));
        } else {
            --k;
            auto p = (k / n) % (n / 2) * 2;
            k %= n;
            auto d = (n - p - 1) / 2;
            writeln((p + k + (k >= d + n/2 ? 2 : k >= d ? 1 : 0)) % n + 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)); }

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

		if (n % 2)
		{
			auto loop = n / 2;
			auto x = (k-1) / loop;
			ans[ti] = (k-1+x) % n + 1;
		}
		else
		{
			ans[ti] = (k-1) % n + 1;
		}
	}

	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, k;
		readf !(" %s %s") (n, k);
		writeln ((k - 1 + ((n & 1) ? (k - 1) / (n / 2) : 0)) % n + 1);
	}
}

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);
        if (n % 2 == 0) {
            writeln((k - 1) % n + 1);
        } else if (k <= n) {
            writeln(k == n ? 2 : k + (k >= (n+1)/2 ? 1 : 0));
        } else {
            --k;
            auto p = (k / n) % (n / 2) * 2;
            k %= n;
            auto d = (n - p - 1) / 2;
            writeln((p + k + (k >= n-1 ? 2 : k >= d ? 1 : 0)) % n + 1);
        }
    }
}

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);
        if (n % 2 == 0) {
            writeln((k - 1) % n + 1);
        } else if (k <= n) {
            writeln(k == n ? 2 : k + (k >= (n+1)/2 ? 1 : 0));
        } else {
            --k;
            auto p = (k / n) % (n / 2) * 2;
            k %= n;
            auto d = (n - p) / 2;
            writeln((p + k + (k >= n-1 ? 2 : k >= d ? 1 : 0)) % n + 1);
        }
    }
}


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

bool solve (int n, int k, int [] s)
{
	if (k == 1)
	{
		return true;
	}
	if (k == n)
	{
		s = [0] ~ s;
		k += 1;
	}
	auto a = new long [n];
	foreach (i; 1..k)
	{
		a[n - i] = s[k - i] - s[k - i - 1];
	}
	foreach (i; k..n + 1)
	{
		a[n - i] = a[n - i + 1];
	}
	auto total = sum (a);
	debug {writeln (a, " ", total);}
	if (k == n && total != s.back)
	{
		return false;
	}
	return (total >= s.back && isSorted (a));
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;
		auto s = readln.splitter.map !(to !(int)).array;
		writeln (solve (n, k, s) ? "YES" : "NO");
	}
}

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

int N, K;
long[] S;

bool solve() {
  if (K == 1) {
    return true;
  }
  auto as = new long[N + 1];
  foreach_reverse (i; N - K + 1 .. N) {
    as[i] = S[i + 1] - S[i];
  }
  foreach_reverse (i; 0 .. N - K + 1) {
    as[i] = as[i + 1];
  }
  debug {
    writeln("K = ", K);
    writeln("S = ", S);
    writeln("as = ", as);
  }
  foreach (i; 0 .. N - 1) {
    if (!(as[i] <= as[i + 1])) {
      return false;
    }
  }
  const S0 = S[N] - as.sum;
  return (S0 <= 0);
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        N = readInt;
        K = readInt;
        S = new long[N + 1];
        foreach (i; N - K + 1 .. N + 1) {
          S[i] = readLong;
        }

        const ans = solve;
        writeln(ans ? "YES" : "NO");
      }
    }
  } catch (EOFException e) {
  }
}

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

bool solve (int n, int k, int [] s)
{
	if (k == 1)
	{
		return true;
	}
	auto a = new long [n];
	foreach (i; 1..k)
	{
		a[n - i] = s[k - i] - s[k - i - 1];
	}
	foreach (i; k..n + 1)
	{
		a[n - i] = a[n - i + 1];
	}
	auto total = sum (a);
	debug {writeln (a, " ", total);}
	if (k == n && total != s.back)
	{
		return false;
	}
	return (total >= s.back && isSorted (a));
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;
		auto s = readln.splitter.map !(to !(int)).array;
		writeln (solve (n, k, s) ? "YES" : "NO");
	}
}

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

int N, K;
long[] S;

bool solve() {
  if (K == 1) {
    return true;
  }
  auto as = new long[N + 1];
  foreach_reverse (i; N - K + 1 .. N) {
    as[i] = S[i + 1] - S[i];
  }
  foreach_reverse (i; 0 .. N - K + 1) {
    as[i] = as[i + 1];
  }
  debug {
    writeln("K = ", K);
    writeln("S = ", S);
    writeln("as = ", as);
  }
  const S0 = S[N] - as.sum;
  return (S0 <= 0);
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        N = readInt;
        K = readInt;
        S = new long[N + 1];
        foreach (i; N - K + 1 .. N + 1) {
          S[i] = readLong;
        }

        const ans = solve;
        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)); }
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 n = RD!int;
		auto s = RD!string;

		foreach (c; s)
		{
			if (c == 'U')
				ans[ti] ~= "D";
			else if (c == 'L')
				ans[ti] ~= "L";
			else if (c == 'R')
				ans[ti] ~= "R";
			else
				ans[ti] ~= "U";
		}
	}

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

immutable multi = true;

void solve(int tc)
{
	auto n = readInt!int;
	auto grid = readString;
	string ans;
	int i = 0;
	while (i < n)
	{
		switch(grid[i])
		{
		case 'U':
			ans ~= 'D';
			break;
		case 'D':
			ans ~= 'U';
			break;
		case 'L':
			ans ~= "LR";
			i++;
			break;
		default:
			assert(0);
		}
		i++;
	}
	assert(ans.length == grid.length);
	writeln(ans);
}

//{{{
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, std.array, std.container, std.conv, std.format, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long n;
    readf!" %d "(n);
    auto s = readln.strip;
    char[] s2;
    foreach (ch ; s) {
      if (ch == 'R')
        s2 ~= 'R';
      else if (ch == 'L')
        s2 ~= 'L';
      else if (ch == 'U')
        s2 ~= 'D';
      else
        s2 ~= 'U';
    }
    writeln(s2.idup);
  }
}


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 p = n.iota.array;
		makeIndex (a, p);
		if (a[p[0]] + a[p[1]] <= a[p[$ - 1]])
		{
			auto q = [p[0], p[1], p[$ - 1]];
			sort (q);
			q[] += 1;
			writefln !("%(%s %)") (q);
		}
		else
		{
			writeln (-1);
		}
	}
}

// Vicfred
// https://codeforces.com/contest/1398/problem/A
// math
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

    while(t--) {
        long n = readln.chomp.to!long;
        long[] a = readln.split.map!(to!long).array;

        if(a[$-1] >= a[0] + a[1])
            writefln("1 2 %s", n);
        else
            "-1".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 int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA!int;
		if (a[0]+a[1] > a[$-1])
			continue;
		ans[ti] = [1, 2, n];
	}

	foreach (e; ans)
	{
		if (e.empty)
			writeln(-1);
		else
			writeln(e[0], " ", e[1], " ", e[2]);
	}
	stdout.flush;
	debug readln;
}

// Vicfred
// https://codeforces.com/contest/1398/problem/A
// math
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

    while(t--) {
        long n = readln.chomp.to!long;
        long[] a = readln.split.map!(to!long).array;

        if(a[$-1] > a[0] + a[1])
            writefln("1 2 %s", n);
        else
            "-1".writeln;
    }
}


immutable multi = true;

void solve(int tc)
{
  auto n = readInt!int;
  auto a = ma(n, readInt!int);
  int height = 1;
  foreach(i, ai; a)
    {
      final switch(ai)
	{
	case 0:
	  if (i > 0 && a[i-1] == 0) return writeln(-1);
	  break;
	case 1:
	  if (i > 0 && a[i-1] == 1) height += 5;
	  else height += 1;
	  break;
	}
    }
  height.writeln;
}

// 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;
void main() {
	auto t = readln.strip.to!int;
	Attempt: foreach(tt; 0 .. t) {
		uint cm = 1;
		readln;
		auto ai = readln.split.to!(int[]);
		if(ai[0] == 1) {
			cm++;
		}
		if(ai.length >= 2) {
			foreach(i, a; ai[1 .. $]) {
				if(a == 0 && ai[i] == 0) {
					writeln("-1");
					continue Attempt;
				} else if(a == 1 && ai[i] == 1) {
					cm += 5;
				} else if(a == 1) {
					cm++;
				}
			}
		}
		writeln(cm);
	}
}

import std;
void main() {
	writeln("started");
	auto t = readln.strip.to!int;
	Attempt: foreach(tt; 0 .. t) {
		uint cm = 1;
		readln;
		auto ai = readln.split.to!(int[]);
		if(ai[0] == 1) {
			cm++;
		}
		if(ai.length >= 2) {
			foreach(i, a; ai[1 .. $]) {
				if(a == 0 && ai[i] == 0) {
					writeln("-1");
					continue Attempt;
				} else if(a == 1 && ai[i] == 1) {
					cm += 5;
				} else if(a == 1) {
					cm++;
				}
			}
		}
		writeln(cm);
	}
}


import std.stdio, std.range, std.conv, std.algorithm, std.string;
import std.regex, std.math;

void main() {
  int n = readln.chomp.to!int;
  auto rc = regex(r"^R(\d+)C(\d+)$");
  auto alnum = regex(r"^([A-Z]+)(\d+)$");

  foreach (i; 0..n) {
    string coord = readln.chomp;
    auto rccap = coord.matchFirst(rc);
    if (!rccap.empty) {
      int row = rccap[1].to!int;
      int col = rccap[2].to!int;
      auto newcol = numToAl(col);
      writeln(newcol ~ rccap[1]);
    } else {
      auto alnumcap = coord.matchFirst(alnum);
      writeln("R" ~ alnumcap[2] ~ "C" ~ alToNum(alnumcap[1]).to!string);
    }
  }
}

int alToNum(string row) {
  int ans;

  foreach (int i, c; (cast(char[])row).reverse) {
    int al = c - 'A' + 1;
    ans += al * pow(26, i);
  }

  return ans;
}

char[] numToAl(int row) {
  char[] ans;
  while (row > 0) {
    ans ~= ((row - 1) % 26) + 'A';
    row = (row - 1) / 26;
  }
  return ans.reverse;
}

import std.stdio, std.regex, std.conv;

static immutable string excelMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static immutable int base = excelMap.length;

ulong excelToDec(string excel) {
    ulong dec = 0, pow = 1;

    for (int i = excel.length-1; i >= 0; --i) {
        dec += (excel[i]-'A'+1) * pow;
        pow *= base;
    }

    return dec;
}

string decToExcel(ulong dec) {
    string s;

    while (dec) {
        s = cast(char)(excelMap[--dec%base]) ~ s;
        dec /= base;
    }

    return s;
}

void main() {
    int n;
    readf("%d\n", &n);

    for (int i = 0; i < n; ++i) {
        auto s = readln();
        auto m = match(s, r"^R([0-9]+)C([0-9]+)");
        if (m) {
            writefln("%s%s", decToExcel(to!int(m.captures[2])), m.captures[1]);
        } else {
            m = match(s, r"^([A-Z]+)([0-9]+)");
            writefln("R%sC%s", m.captures[2], excelToDec(m.captures[1]));
        }
    }
}

import std.stdio;
import std.algorithm;
import std.regex;

void tr1(in string s) {
    int r, c;
    s.ptr.sscanf("R%dC%d".ptr, &r, &c);
    char[] cs;
    while (c > 0) {
        if (c % 26 == 0) {
            cs ~= 'Z';
            c = (c - 26) / 26;
        } else {
            cs ~= ('A' + c % 26 - 1);
            c /= 26;
        }
    }
    cs.reverse();
    writef("%s%d\n", cs, r);
}

void tr2(in string s) {
    auto m = s.match(regex("([A-Z]+)([0-9]+)")).captures;
    auto cs = m[1], rs = m[2];
    int t = 0;
    foreach (i, c; cs) {
        t = t * 26 + c - 'A' + 1;
    }
    writef("R%sC%d\n", rs, t);
}

void tr(in string s) {
    if (!s.match(regex("R[0-9]+C[0-9]+")).empty()) {
    //if (s[0] == 'R') {
        tr1(s);
    } else {
        tr2(s);
    }
}

void main() {
    int n; readf("%d\n", &n);
    foreach (_; 0 .. n) {
        tr(stdin.readln());
    }
}

import std.stdio;
import std.algorithm;
import std.regex;
import std.math;
import std.conv;

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

struct Cell
{
	public int column;
	public int row;

	public int from_string(string col)
	{
		int res = 0;
		for (int i = col.length - 1; i >= 0; i--)
		{
			res += ((col[i] - 'A') + 1) * pow(26, col.length - i - 1);
		}
		return res;
	}

	public string toMode1()
	{
		string s = "R" ~ to!string(row) ~ "C" ~ to!string(column);
		return s;
	}

	public string toMode2()
	{
		int c = column;
		string s = "";
		while (c > 0)
		{
			c--;
			int lc = c % 26;
			if (lc < 0) lc += 26;
			s ~= cast(char)(lc + 'A');
			c = c / 26;
		}
		char[] ms = s.dup;
		reverse(ms);
		return to!string(ms) ~ to!string(row);
	}
}

int main(string[] argv)
{
	int n;
	scanf("%d\n", &n);
	auto mode1 = r"^R([0-9]+)C([0-9]+$)".regex;
	auto mode2 = r"^([A-Z]+)([0-9]+)$".regex;
	foreach (int i; 0..n)
	{
		string expression = readline();
		Cell c;
		auto m = matchFirst(expression, mode1);
		if (m.empty)
		{
			m = matchFirst(expression, mode2);
			c.column = c.from_string(m[1]);
			c.row = to!int(m[2]);
			write(c.toMode1(), "\n");
		} else {
			c.row = to!int(m[1]);
			c.column = to!int(m[2]);
			write(c.toMode2(), "\n");
		}
	}
	return 0;
}

import std.stdio, std.regex, std.conv;

immutable rx1 = r"^([A-Z]+)(\d+)$";
immutable rx2 = r"^R(\d+)C(\d+)$";

void main() {
	long n;
	readf("%s\n", &n);
	foreach (i; 0 .. n) {
		string s;
		readf("%s\n", &s);
		auto m = match(s, rx1);
		if (m) {
			long col = 0;
			foreach(c; m.captures[1]) {
				col *= 26;
				col += c - 'A' + 1;
			}
			writefln("R%sC%d", m.captures[2], col);
		} else {
			m = match(s, rx2);
			long col = to!long(m.captures[2]);
			string res = "";
			while(col) {
				if (col % 26) {
					res = ((col % 26) - 1 + 'A') ~ res;
				} else {
					res = 'Z' ~ res;
					col -= 26;
				}
				col /= 26;
			}
			writefln("%s%s", res, m.captures[1]);
		}
	}
}

import std.stdio;
import std.algorithm;
import std.regex;

void tr1(in string s) {
    int r, c;
    s.ptr.sscanf("R%dC%d".ptr, &r, &c);
    char[] cs;
    while (c > 0) {
        if (c % 26 == 0) {
            cs ~= 'Z';
            c = (c - 26) % 26;
        } else {
            cs ~= ('A' + c % 26 - 1);
            c /= 26;
        }
    }
    cs.reverse();
    writef("%s%d\n", cs, r);
}

void tr2(in string s) {
    auto m = s.match(regex("([A-Z]+)([0-9]+)")).captures;
    auto cs = m[1], rs = m[2];
    int t = 0;
    foreach (i, c; cs) {
        t = t * 26 + c - 'A' + 1;
    }
    writef("R%sC%d\n", rs, t);
}

void tr(in string s) {
    if (s[0] == 'R') {
        tr1(s);
    } else {
        tr2(s);
    }
}

void main() {
    int n; readf("%d\n", &n);
    foreach (_; 0 .. n) {
        tr(stdin.readln());
    }
}

import std.stdio;
import std.algorithm;
import std.regex;

void tr1(in string s) {
    int r, c;
    s.ptr.sscanf("R%dC%d".ptr, &r, &c);
    char[] cs;
    while (c > 0) {
        if (c % 26 == 0) {
            cs ~= 'Z';
            c = (c - 26) % 26;
        } else {
            cs ~= ('A' + c % 26 - 1);
            c /= 26;
        }
    }
    cs.reverse();
    writef("%s%d\n", cs, r);
}

void tr2(in string s) {
    auto m = s.match(regex("([A-Z]+)([0-9]+)")).captures;
    auto cs = m[1], rs = m[2];
    int t = 0;
    foreach (i, c; cs) {
        t = t * 26 + c - 'A' + 1;
    }
    writef("R%sC%d\n", rs, t);
}

void tr(in string s) {
    if (!s.match(regex("R[0-9]+C[0-9]+")).empty()) {
    //if (s[0] == 'R') {
        tr1(s);
    } else {
        tr2(s);
    }
}

void main() {
    int n; readf("%d\n", &n);
    foreach (_; 0 .. n) {
        tr(stdin.readln());
    }
}

import std.stdio, std.regex, std.conv;

static immutable string excelMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static immutable int base = excelMap.length;

ulong excelToDec(string excel) {
    ulong dec = 0, pow = 1;

    for (int i = excel.length-1; i >= 0; --i) {
        dec += (excel[i]-'A'+1) * pow;
        pow *= base;
    }

    return dec;
}

string decToExcel(ulong dec) {
    string s;

    while (dec) {
        s = cast(char)(excelMap[--dec%base]) ~ s;
        dec /= base;
    }

    return s;
}

void main() {
    writeln(decToExcel(494));

    int n;
    readf("%d\n", &n);

    for (int i = 0; i < n; ++i) {
        auto s = readln();
        auto m = match(s, r"^R([0-9]+)C([0-9]+)");
        if (m) {
            writefln("%s%s", decToExcel(to!int(m.captures[2])), m.captures[1]);
        } else {
            m = match(s, r"^([A-Z]+)([0-9]+)");
            writefln("R%sC%s", m.captures[2], excelToDec(m.captures[1]));
        }
    }
}

import std.stdio, std.regex, std.conv;

static immutable string excelMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static immutable int base = excelMap.length;

ulong excelToDec(string excel) {
    ulong dec = 0, pow = 1;

    for (int i = excel.length-1; i >= 0; --i) {
        dec += (excel[i]-'A'+1) * pow;
        pow *= base;
    }

    return dec;
}

string decToExcel(ulong dec) {
    string s;

    while (dec) {
        s = cast(char)(excelMap[dec%base]-1) ~ s;
        dec /= base;
    }

    return s;
}

void main() {
    int n;
    readf("%d\n", &n);

    for (int i = 0; i < n; ++i) {
        auto s = readln();
        auto m = match(s, r"^R([0-9]+)C([0-9]+)");
        if (m) {
            writefln("%s%s", decToExcel(to!int(m.captures[2])), m.captures[1]);
        }
        else {
            m = match(s, r"^([A-Z]+)([0-9]+)");
            writefln("R%sC%s", m.captures[2], excelToDec(m.captures[1]));
        }
    }
}

import std.stdio, std.regex, std.conv;

static immutable string excelMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static immutable int base = excelMap.length;

ulong excelToDec(string excel) {
    ulong dec = 0, pow = 1;

    for (int i = excel.length-1; i >= 0; --i) {
        dec += (excel[i]-'A'+1) * pow;
        pow *= base;
    }

    return dec;
}

string decToExcel(ulong dec) {
    string s;

    while (dec) {
        s = cast(char)(excelMap[dec%base]-1) ~ s;
        dec /= base;
    }

    return s;
}

void main() {
    int n;
    readf("%d\n", &n);

    for (int i = 0; i < n; ++i) {
        auto s = readln();
        writeln(s);
        auto m = match(s, r"^R([0-9]+)C([0-9]+)");
        if (m)
            writefln("%s%s", decToExcel(to!int(m.captures[2])), m.captures[1]);
        else
            m = match(s, r"^([A-Z]+)([0-9]+)");
            writefln("R%sC%s", m.captures[2], excelToDec(m.captures[1]));
    }
}

import std.stdio, std.regex, std.conv;

static immutable string excelMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static immutable int base = excelMap.length;

ulong excelToDec(string excel) {
    ulong dec = 0, pow = 1;

    for (int i = excel.length-1; i >= 0; --i) {
        dec += (excel[i]-'A'+1) * pow;
        pow *= base;
    }

    return dec;
}

string decToExcel(ulong dec) {
    string s;

    while (dec) {
        s = cast(char)(excelMap[dec%base]-1) ~ s;
        dec /= base;
    }

    return s;
}

void main() {
    int n;
    readf("%d\n", &n);

    for (int i = 0; i < n; ++i) {
        auto s = readln();
        auto m = match(s, r"^R([0-9]+)C([0-9]+)");
        if (m)
            writefln("%s%s", decToExcel(to!int(m.captures[2])), m.captures[1]);
        else
            m = match(s, r"^([A-Z]+)([0-9]+)");
            writefln("R%sC%s", m.captures[2], excelToDec(m.captures[1]));
    }
}

import std.stdio;
import std.algorithm;
import std.regex;
import std.math;
import std.conv;

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

struct Cell
{
	public int column;
	public int row;

	public int from_string(string col)
	{
		int res = 0;
		for (int i = col.length - 1; i >= 0; i--)
		{
			res += ((col[i] - 'A') + 1) * pow(26, col.length - i - 1);
		}
		return res;
	}

	public string toMode1()
	{
		string s = "R" ~ to!string(row) ~ "C" ~ to!string(column);
		return s;
	}

	public string toMode2()
	{
		int c = column;
		string s = "";
		while (c > 0)
		{
			s ~= cast(char)((c % 26) + 'A' - 1);
			c = c / 26;
		}
		char[] ms = s.dup;
		reverse(ms);
		return to!string(ms) ~ to!string(row);
	}
}

int main(string[] argv)
{
	int n;
	scanf("%d\n", &n);
	auto mode1 = r"^R([0-9]+)C([0-9]+$)".regex;
	auto mode2 = r"^([A-Z]+)([0-9]+)$".regex;
	foreach (int i; 0..n)
	{
		string expression = readline();
		Cell c;
		auto m = matchFirst(expression, mode1);
		if (m.empty)
		{
			m = matchFirst(expression, mode2);
			c.column = c.from_string(m[1]);
			c.row = to!int(m[2]);
			write(c.toMode1(), "\n");
		} else {
			c.row = to!int(m[1]);
			c.column = to!int(m[2]);
			write(c.toMode2(), "\n");
		}
	}
	return 0;
}

import std.stdio, std.range, std.conv, std.algorithm, std.string;
import std.regex, std.math;

void main() {
  int n = readln.chomp.to!int;
  auto rc = regex(r"^R(\d+)C(\d+)$");
  auto alnum = regex(r"^([A-Z]+)(\d+)$");

  foreach (i; 0..n) {
    string coord = readln.chomp;
    auto rccap = coord.matchFirst(rc);
    if (!rccap.empty) {
      int row = rccap[1].to!int;
      int col = rccap[2].to!int;
      auto newcol = numToAl(col);
      writeln(newcol ~ rccap[1]);
    } else {
      auto alnumcap = coord.matchFirst(alnum);
      writeln("R" ~ alnumcap[2] ~ "C" ~ alToNum(alnumcap[1]).to!string);
    }
  }
}

int alToNum(string row) {
  int ans;

  foreach (int i, c; (cast(char[])row).reverse) {
    int al = c - 'A' + 1;
    ans += al * pow(26, i);
  }

  return ans;
}

char[] numToAl(int row) {
  char[] ans;
  while (row > 25) {
    ans ~= (row % 26) + 'A' - 1;
    row /= 26;
  }

  ans ~= (row + 'A' - 1);
  return ans.reverse;
}


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

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

    auto g = new int [][] (n+1);
    foreach (_; 0..m) {
        auto a = readln.split.map!(to!int).array;
        (2).iota.each!(i => g[a[i]] ~= a[1-i]);
    }

    auto vis = false.repeat(n+1).array;

    bool dfs (int v, int fr, int fin) {
        vis[v] = true;
        if (g[v].length != 2) return false;

        foreach (u; g[v]) {
            if (u == fr) continue;
            if (vis[u]) return u == fin;
            return dfs(u, v, fin);
        }

        assert(false);
    }

    int ans = 0;
    foreach (i; 1..n+1) {
        debug { writeln(g[i]); }
        if (vis[i]) continue;
        ans += dfs(i, -1, i);
    }

    writeln(ans);
}

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

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, m; readV(n, m);

  auto g = Graph!int(n), uf = UnionFind!int(n);
  foreach (i; 0..m) {
    int a, b; readV(a, b); --a; --b;
    g.addEdgeB(a, b);
    uf.unite(a, b);
  }

  writeln(uf.groups.count!(gi => gi.all!(vi => g[vi].length == 2)));
}

struct Graph(N = int)
{
  alias Node = N;
  Node n;
  Node[][] g;
  alias g this;
  this(Node n) { this.n = n; g = new Node[][](n); }
  void addEdge(Node u, Node v) { g[u] ~= v; }
  void addEdgeB(Node u, Node v) { g[u] ~= v; g[v] ~= u; }
}

struct UnionFind(T)
{
  import std.algorithm, std.range;

  T[] p; // parent
  const T s; // sentinel
  const T n;
  T countForests; // number of forests
  T[] countNodes; // number of nodes in forests

  this(T n)
  {
    this.n = n;
    s = n;
    p = new T[](n);
    p[] = s;
    countForests = n;
    countNodes = new T[](n);
    countNodes[] = 1;
  }

  T opIndex(T i)
  {
    if (p[i] == s) {
      return i;
    } else {
      p[i] = this[p[i]];
      return p[i];
    }
  }

  bool unite(T i, T j)
  {
    auto pi = this[i], pj = this[j];
    if (pi != pj) {
      p[pj] = pi;
      --countForests;
      countNodes[pi] += countNodes[pj];
      return true;
    } else {
      return false;
    }
  }

  auto countNodesOf(T i) { return countNodes[this[i]]; }
  bool isSame(T i, T j) { return this[i] == this[j]; }

  auto groups()
  {
    auto g = new T[][](n);
    foreach (i; 0..n) g[this[i]] ~= i;
    return g.filter!(l => !l.empty);
  }
}

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

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

    auto g = new int [][] (n+1);
    foreach (_; 0..m) {
        auto a = readln.split.map!(to!int).array;
        (2).iota.each!(i => g[a[i]] ~= a[1-i]);
    }

    auto vis = false.repeat(n+1).array;

    int[] bfs (int s) {
        auto r = [s];
        auto q = SList!int(s);
        while (!q.empty()) {
            auto v = q.front();
            q.removeFront();
            if (vis[v]) continue;
            vis[v] = true;
            r ~= v;
            foreach (u; g[v]) if (!vis[u]) q.insertFront(u);
        }
        return r;
    }

    auto isCycle = (int[] comp) => comp.length > 2 && comp.all!(v => g[v].length == 2);
    int ans = 0;
    foreach (i; 1..n+1) {
        debug { writeln(g[i]); }
        if (vis[i]) continue;
        ans += isCycle(bfs(i).array);
    }

    writeln(ans);
}

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

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

    auto g = new int [][] (n+1);
    foreach (_; 0..m) {
        auto a = readln.split.map!(to!int).array;
        (2).iota.each!(i => g[a[i]] ~= a[1-i]);
    }

    auto vis = false.repeat(n+1).array;

    void dfs (int v, ref int[] cur) {
        vis[v] = true;
        cur ~= v;

        foreach (u; g[v]) {
            if (!vis[u]) dfs(u, cur);
        }
    }

    auto isCycle = (int[] comp) => comp.length > 2 && comp.all!(v => g[v].length == 2);
    int ans = 0;
    foreach (i; 1..n+1) {
        debug { writeln(g[i]); }
        if (vis[i]) continue;
        int[] comp;
        dfs(i, comp);
        ans += isCycle(comp);
    }

    writeln(ans);
}

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

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

    auto g = new int [][] (n+1);
    foreach (_; 0..m) {
        auto a = readln.split.map!(to!int).array;
        (2).iota.each!(i => g[a[i]] ~= a[1-i]);
    }

    auto vis = false.repeat(n+1).array;

    SList!int bfs (int s) {
        auto r = SList!int(s);
        auto q = SList!int(s);
        while (!q.empty()) {
            auto v = q.front();
            q.removeFront();
            if (vis[v]) continue;
            vis[v] = true;
            r.insertFront(v);
            foreach (u; g[v]) if (!vis[u]) q.insertFront(u);
        }
        return r;
    }

    auto isCycle = (int[] comp) => comp.length > 2 && comp.all!(v => g[v].length == 2);
    int ans = 0;
    foreach (i; 1..n+1) {
        debug { writeln(g[i]); }
        if (vis[i]) continue;
        ans += isCycle(bfs(i).array);
    }

    writeln(ans);
}

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

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

    auto g = new int [][] (n+1);
    foreach (_; 0..m) {
        auto a = readln.split.map!(to!int).array;
        (2).iota.each!(i => g[a[i]] ~= a[1-i]);
    }

    auto vis = false.repeat(n+1).array;

    int[] bfs (int s) {
        auto r = Array!int(s);
        auto q = SList!int(s);
        while (!q.empty()) {
            auto v = q.front();
            q.removeFront();
            if (vis[v]) continue;
            vis[v] = true;
            r ~= v;
            foreach (u; g[v]) if (!vis[u]) q.insertFront(u);
        }
        return r.array;
    }

    int[][] comps;
    foreach (i; 1..n+1) {
        debug { writeln(g[i]); }
        if (vis[i]) continue;
        comps ~= bfs(i);
    }

    auto isCycle = (int[] comp) => comp.length > 2 && comp.all!(v => g[v].length == 2);
    auto ans = comps.count!(isCycle);

    writeln(ans);
}

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

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

    auto g = new int [][] (n+1);
    foreach (_; 0..m) {
        auto a = readln.split.map!(to!int).array;
        (2).iota.each!(i => g[a[i]] ~= a[1-i]);
    }

    auto vis = false.repeat(n+1).array;

    void dfs (int v, ref int[] cur) {
        vis[v] = true;
        cur ~= v;

        foreach (u; g[v]) {
            if (!vis[u]) dfs(u, cur);
        }
    }

    int[][] comps;
    foreach (i; 1..n+1) {
        debug { writeln(g[i]); }
        if (vis[i]) continue;
        int[] comp;
        dfs(i, comp);
        comps ~= comp;
    }

    auto isCycle = (int[] comp) => comp.length > 2 && comp.all!(v => g[v].length == 2);
    auto ans = comps.count!(isCycle);

    writeln(ans);
}

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

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

    auto g = new int [][] (n+1);
    foreach (_; 0..m) {
        auto a = readln.split.map!(to!int).array;
        (2).iota.each!(i => g[a[i]] ~= a[1-i]);
    }

    auto vis = false.repeat(n+1).array;

    void dfs (int v, ref int[] cur) {
        vis[v] = true;
        cur ~= v;

        foreach (u; g[v]) {
            if (vis[u]) continue;
            return dfs(u, cur);
        }
    }

    int[][] comps;
    foreach (i; 1..n+1) {
        debug { writeln(g[i]); }
        if (vis[i]) continue;
        int[] comp;
        dfs(i, comp);
        comps ~= comp;
    }

    auto isCycle = (int[] comp) => comp.length > 2 && comp.all!(v => g[v].length == 2);
    auto ans = comps.count!(isCycle);

    writeln(ans);
}


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 = read!int;
    int M = N / 3;
    int[] G;
    for (int i = 0; i < M; i++) {
        int x = ask(3*i+1, 3*i+2, 3*i+3);
        G ~= x;
    }
    int find_ic() {
        for (int i = 0; i+1 < M; i++) {
            if (G[i] != G[i + 1]) {
                // 3*i+1 ~ 3*i+6
                int[] p;
                for (int k = 3*i+1; k <= 3*i+4; k++) {
                    int x = ask(k, k+1, k+2);
                    if (!p.empty && p.back != x) {
                        // (k, k+1) is (i,c) or (c,i)
                        return k;
                    } else {
                        p ~= x;
                    }
                }
            }
        }
        assert(false);
    }

    int k = find_ic();
    int[] Is, Cs;
    for (int i = 1; i <= N; i++) {
        if (i == k || i == k+1) continue;
        int x = ask(k, k+1, i);
        if (x == 0) {
            Is ~= i;
        } else {
            Cs ~= i;
        }
    }
    int x = ask(Is.back, Cs.back, k);
    if (x == 0) {
        Is ~= k;
        Cs ~= k + 1;
    } else {
        Is ~= k + 1;
        Cs ~= k;
    }
    writefln("! %s %(%s %)", Is.length, Is);
    stdout.flush;
}

int ask(int a, int b, int c) {
    writefln("? %s %s %s", a, b, c);
    stdout.flush;
    return read!int;
}

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 euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

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;
	foreach (ti; 0..t)
	{
		auto n = RD!int;

		auto ans = new long[](n);
		ans[] = -1;
		auto r = new long[](n);
		foreach (i; 1..n-1)
		{
			writeln("? ", i, " ", i+1, " ", i+2);
			stdout.flush;
			r[i] = RD;
		}
		long x, y;
		foreach (i; 1..n-2)
		{
			if (r[i] != r[i+1])
			{
				ans[i-1] = r[i];
				ans[i+2] = r[i+1];
				x = i-1;
				y = i+2;
			}
		}
		foreach (i; 0..n)
		{
			if (ans[i] != -1) continue;
			writeln("? ", x+1, " ", y+1, " ", i+1);
			stdout.flush;
			ans[i] = RD;
		}
		long[] arr;
		foreach (i; 0..n)
		{
			if (ans[i] == 0)
				arr ~= i+1;
		}
		writeln("! ", arr.length, " ", arr.map!(to!string).join(" "));
		stdout.flush;
	}

	debug readln;
}

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

void solve (int n)
{
	assert (n % 3 == 0);

	int ask (int a, int b, int c)
	{
		writeln ("? ", a, " ", b, " ", c);
		stdout.flush ();
		return readln.strip.to !(int);
	}

	int [] q;
	for (int i = 0; i < n; i += 3)
	{
		q ~= ask (i + 1, i + 2, i + 3);
	}

	auto t0 = q.countUntil (0) * 3;
	auto t1 = q.countUntil (1) * 3;
	auto six = [t0 + 1, t0 + 2, t0 + 3, t1 + 1, t1 + 2, t1 + 3];
	int pos = 1;
	while (ask (six[pos + 0], six[pos + 1], six[pos + 2]) == 0)
	{
		pos += 1;
	}

	int p0 = six[pos - 1];
	int p1 = six[pos + 2];

	auto v = new bool [n + 1];
	for (int i = 0; i < n; i += 3)
	{
		auto three = [i + 1, i + 2, i + 3];
		if (q[i / 3] == 0)
		{
			int x = ask (three[0], three[1], p1);
			int y = ask (three[0], three[2], p1);
			int z = (x == 1 && y == 1) ? 0 :
			        (x == 0 && y == 0) ? 0 : 1;
			v[three[0]] = 0;
			v[three[1]] = 0;
			v[three[2]] = 0;
			if (x == 1 && y == 1) v[three[0]] = 1;
			if (x == 1 && z == 1) v[three[1]] = 1;
			if (y == 1 && z == 1) v[three[2]] = 1;
		}
		else
		{
			int x = ask (three[0], three[1], p0);
			int y = ask (three[0], three[2], p0);
			int z = (x == 0 && y == 0) ? 1 :
			        (x == 1 && y == 1) ? 1 : 0;
			v[three[0]] = 1;
			v[three[1]] = 1;
			v[three[2]] = 1;
			if (x == 0 && y == 0) v[three[0]] = 0;
			if (x == 0 && z == 0) v[three[1]] = 0;
			if (y == 0 && z == 0) v[three[2]] = 0;
		}
	}

	auto answer = iota (1, n + 1).filter !(i => v[i] == 0).array;
	writefln ("! %s %(%s %)", answer.length, answer);
	stdout.flush ();
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		solve (n);
	}
}

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

void solve (int n)
{
	assert (n % 3 == 0);

	int ask (int a, int b, int c)
	{
		writeln ("? ", a, " ", b, " ", c);
		stdout.flush ();
		return readln.strip.to !(int);
	}

	int [] q;
	for (int i = 0; i < n; i += 3)
	{
		q ~= ask (i + 1, i + 2, i + 3);
	}

	auto t0 = q.countUntil (0) * 3;
	auto t1 = q.countUntil (1) * 3;
	auto six = [t0 + 1, t0 + 2, t0 + 3, t1 + 1, t1 + 2, t1 + 3];
	int pos = 1;
	while (ask (six[pos + 0], six[pos + 1], six[pos + 2]) == 0)
	{
		pos += 1;
	}

	int p0 = six[pos - 1];
	int p1 = six[pos + 2];

	auto v = new bool [n + 1];
	for (int i = 0; i < n; i += 3)
	{
		auto three = [i + 1, i + 2, i + 3];
		if (q[i / 3] == 0)
		{
			int x = ask (three[0], three[1], p1);
			int y = ask (three[0], three[2], p1);
			int z = (x == 0 && y == 0) ? 0 : 1;
			v[three[0]] = 0;
			v[three[1]] = 0;
			v[three[2]] = 0;
			if (x == 1 && y == 1) v[three[0]] = 1;
			if (x == 1 && z == 1) v[three[1]] = 1;
			if (y == 1 && z == 1) v[three[2]] = 1;
		}
		else
		{
			int x = ask (three[0], three[1], p0);
			int y = ask (three[0], three[2], p0);
			int z = (x == 1 && y == 1) ? 1 : 0;
			v[three[0]] = 1;
			v[three[1]] = 1;
			v[three[2]] = 1;
			if (x == 0 && y == 0) v[three[0]] = 0;
			if (x == 0 && z == 0) v[three[1]] = 0;
			if (y == 0 && z == 0) v[three[2]] = 0;
		}
	}

	auto answer = iota (1, n + 1).filter !(i => v[i] == 0).array;
	writefln ("! %s %(%s %)", answer.length, answer);
	stdout.flush ();
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		solve (n);
	}
}

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

void solve (int n)
{
	assert (n % 3 == 0);

	int askImpl () (int a, int b, int c)
	{
		writeln ("? ", a, " ", b, " ", c);
		stdout.flush ();
		return readln.strip.to !(int);
	}

	alias ask = memoize !(askImpl !());

	int [] q;
	for (int i = 0; i < n; i += 3)
	{
		q ~= ask (i + 1, i + 2, i + 3);
	}

	auto t0 = q.countUntil (0) * 3;
	auto t1 = q.countUntil (1) * 3;
	auto six = [t0 + 1, t0 + 2, t0 + 3, t1 + 1, t1 + 2, t1 + 3];
	int pos = 1;
	while (ask (six[pos + 0], six[pos + 1], six[pos + 2]) == 0)
	{
		pos += 1;
	}

	int p0 = six[pos - 1];
	int p1 = six[pos + 2];

	auto v = new bool [n + 1];
	for (int i = 0; i < n; i += 3)
	{
		auto three = [i + 1, i + 2, i + 3];
		if (q[i / 3] == 0)
		{
			int x = ask (three[0], three[1], p1);
			int y = ask (three[0], three[2], p1);
			int z = (x == 0 && y == 0) ? 0 : 1;
			v[three[0]] = 0;
			v[three[1]] = 0;
			v[three[2]] = 0;
			if (x == 1 && y == 1) v[three[0]] = 1;
			if (x == 1 && z == 1) v[three[1]] = 1;
			if (y == 1 && z == 1) v[three[2]] = 1;
		}
		else
		{
			int x = ask (three[0], three[1], p0);
			int y = ask (three[0], three[2], p0);
			int z = (x == 1 && y == 1) ? 1 : 0;
			v[three[0]] = 1;
			v[three[1]] = 1;
			v[three[2]] = 1;
			if (x == 0 && y == 0) v[three[0]] = 0;
			if (x == 0 && z == 0) v[three[1]] = 0;
			if (y == 0 && z == 0) v[three[2]] = 0;
		}
	}

	auto answer = iota (1, n + 1).filter !(i => v[i] == 0).array;
	writefln ("! %s %(%s %)", answer.length, answer);
	stdout.flush ();
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		solve (n);
	}
}

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

void solve (int n)
{
	assert (n % 3 == 0);

	int askImpl () (int a, int b, int c)
	{
		writeln ("? ", a, " ", b, " ", c);
		stdout.flush ();
		return readln.strip.to !(int);
	}

	alias ask = memoize !(askImpl !());

	int [] q;
	for (int i = 0; i < n; i += 3)
	{
		q ~= ask (i + 1, i + 2, i + 3);
	}

	auto t0 = q.countUntil (0) * 3;
	auto t1 = q.countUntil (1) * 3;
	auto six = [t0 + 1, t0 + 2, t0 + 3, t1 + 1, t1 + 2, t1 + 3];
	int pos = 1;
	while (ask (six[pos + 0], six[pos + 1], six[pos + 2]) == 0)
	{
		pos += 1;
	}

	int p0 = six[pos - 1];
	int p1 = six[pos + 2];

	auto v = new bool [n + 1];
	for (int i = 0; i < n; i += 3)
	{
		auto three = [i + 1, i + 2, i + 3];
		if (q[i / 3] == 0)
		{
			int x = ask (three[0], three[1], p1);
			int y = ask (three[0], three[2], p1);
			int z = (x == 0 && y == 0) ? 0 : 1;
			v[three[0]] = 0;
			v[three[1]] = 0;
			v[three[2]] = 0;
			if (x == 1 && y == 1) v[three[0]] = 1;
			if (x == 1 && z == 1) v[three[1]] = 1;
			if (y == 1 && z == 1) v[three[2]] = 1;
		}
		else
		{
			int x = ask (three[0], three[1], p0);
			int y = ask (three[0], three[2], p0);
			int z = (x == 1 && y == 1) ? 1 : 0;
			v[three[0]] = 1;
			v[three[1]] = 1;
			v[three[2]] = 1;
			if (x == 0 && y == 0) v[three[0]] = 0;
			if (x == 0 && z == 0) v[three[1]] = 0;
			if (y == 0 && z == 0) v[three[2]] = 0;
		}
	}

	writefln ("! %(%s %)", iota (1, n + 1).filter !(i => v[i] == 0));
	stdout.flush ();
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		solve (n);
	}
}

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

void solve (int n)
{
	assert (n % 3 == 0);

	int askImpl () (int a, int b, int c)
	{
		writeln ("? ", a, " ", b, " ", c);
		stdout.flush ();
		return readln.strip.to !(int);
	}

	alias ask = memoize !(askImpl !());

	int [] q;
	for (int i = 0; i < n; i += 3)
	{
		q ~= ask (i + 1, i + 2, i + 3);
	}

	auto t0 = q.countUntil (0) * 3;
	auto t1 = q.countUntil (1) * 3;
	auto six = [t0 + 1, t0 + 2, t0 + 3, t1 + 1, t1 + 2, t1 + 3];
	int pos = 1;
	while (ask (six[pos + 0], six[pos + 1], six[pos + 2]) == 0)
	{
		pos += 1;
	}

	int p0 = six[pos - 1];
	int p1 = six[pos + 2];

	auto v = new bool [n + 1];
	for (int i = 0; i < n; i += 3)
	{
		auto three = [i + 1, i + 2, i + 3];
		if (q[i / 3] == 0)
		{
			int x = ask (three[0], three[1], p1);
			int y = ask (three[0], three[2], p1);
			int z = (x == 0 && y == 0) ? 0 : 1;
			v[three[0]] = 0;
			v[three[1]] = 0;
			v[three[2]] = 0;
			if (x == 1 && y == 1) v[three[0]] = 1;
			if (x == 1 && z == 1) v[three[1]] = 1;
			if (y == 1 && z == 1) v[three[2]] = 1;
		}
		else
		{
			int x = ask (three[0], three[1], p0);
			int y = ask (three[0], three[2], p0);
			int z = (x == 1 && y == 1) ? 1 : 0;
			v[three[0]] = 1;
			v[three[1]] = 1;
			v[three[2]] = 1;
			if (x == 0 && y == 0) v[three[0]] = 0;
			if (x == 0 && z == 0) v[three[1]] = 0;
			if (y == 0 && z == 0) v[three[2]] = 0;
		}
	}

	writefln ("! %(%s %)", iota (1, n + 1).filter !(i => v[i]));
	stdout.flush ();
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		solve (n);
	}
}


import std.algorithm, std.container, std.stdio, std.typecons;

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		alias Island = Tuple !(long, q{lo}, long, q{hi});
		auto s = new Island [n];
		foreach (ref p; s)
		{
			readf (" %s %s", &p.lo, &p.hi);
		}

		alias Segment = Tuple !(long, q{hi}, long, q{lo}, int, q{num});
		auto t = new Segment [n - 1];
		foreach (i; 0..n - 1)
		{
			t[i] = Segment (s[i + 1].hi - s[i].lo,
			    s[i + 1].lo - s[i].hi, i);
		}
		sort (t);

		alias Bridge = Tuple !(long, q{len}, int, q{num});
		auto b = redBlackTree !(Bridge);
		foreach (j; 0..m)
		{
			long d;
			readf (" %s", &d);
			b.insert (Bridge (d, j));
		}

		auto ans = new int [n - 1];
		foreach (i; 0..n - 1)
		{
			auto temp = Bridge (t[i].lo, -1);
			auto r = b.upperBound (temp);
			if (r.empty)
			{
				ans = null;
				break;
			}
			auto cur = r.front;
			if (cur.len > t[i].hi)
			{
				ans = null;
				break;
			}
			ans[t[i].num] = cur.num + 1;
			b.removeKey (cur);
		}

		if (ans is null)
		{
			writeln ("No");
		}
		else
		{
			writeln ("Yes");
			writefln ("%(%s %)", ans);
		}
	}
}

import core.bitop;
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;

void main ()
{
	int n;
	int m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		alias Island = Tuple !(long, q{lo}, long, q{hi});
		auto s = new Island [n];
		foreach (ref p; s)
		{
			readf (" %s %s", &p.lo, &p.hi);
		}

		alias Segment = Tuple !(long, q{hi}, long, q{lo}, int, q{num});
		auto t = new Segment [n - 1];
		foreach (i; 0..n - 1)
		{
			t[i] = Segment (s[i + 1].hi - s[i].lo,
			    s[i + 1].lo - s[i].hi, i);
		}
		sort !(q{a < b}, SwapStrategy.stable) (t);

		alias Bridge = Tuple !(long, q{len}, int, q{num});
		auto b = redBlackTree !(Bridge);
		foreach (j; 0..m)
		{
			long d;
			readf (" %s", &d);
			b.insert (Bridge (d, j));
		}
		debug {writeln (b[].map !(text).join (" "));}

		auto ans = new int [n - 1];
		foreach (i; 0..n - 1)
		{
			auto temp = Bridge (t[i].lo, -1);
			auto r = b.upperBound (temp);
			if (r.empty)
			{
				ans = null;
				break;
			}
			auto cur = r.front;
			if (cur.len > t[i].hi)
			{
				ans = null;
				break;
			}
			ans[t[i].num] = cur.num + 1;
			b.removeKey (cur);
		}

		if (ans is null)
		{
			writeln ("No");
		}
		else
		{
			writeln ("Yes");
			writefln ("%(%s %)", ans);
		}
	}
}


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

string FMT_F = "%.10f";

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; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
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; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long 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 main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (i; 0..t)
	{
		auto a = RD!int;
		auto b = RD!int;
		auto x = min(a, b);
		auto y = cast(long)max(a, b);
		auto arr = new bool[](x);
		foreach (j; 1..10^^5)
		{
			auto z = (y*j) % x;
			arr[cast(int)z] = true;
		}

		bool ok = true;
		foreach (j; 0..arr.length)
		{
			if (arr[j] == false)
			{
				ok = false;
				break;
			}
		}
		ans[i] = ok;
	}

	foreach (e; ans)
	{
		writeln(e ? "Finite" : "Infinite");
	}
	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.string, core.stdc.stdlib;

void main() {
    auto T = readln.chomp.to!int;
    while (T--) {
        auto s = readln.split.map!(to!int);
        auto A = s[0];
        auto B = s[1];
        writeln(gcd(A, B) == 1 ? "Finite" : "Infinite");
    }
}

//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;
import std.numeric;

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;
    }
  }
  final T[] nextA(T) (int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader;
  foreach (t; 0 .. r.next!uint) {
    auto a = r.next!uint;
    auto b = r.next!uint;
    writeln (gcd (a, b) == 1 ? "Finite" : "Infinite");
  }
}

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

string FMT_F = "%.10f";

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; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
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; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long 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 main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (i; 0..t)
	{
		auto a = RD!int;
		auto b = RD!int;
		int[] open = [0];
		auto limit = (10^^6)+1;
		auto close = new bool[](limit);
		close[0] = true;
		while (!open.empty)
		{
			auto n = open.front; open.popFront;
			auto na = (n+a);
			auto nb = (n+b);
			if (na < limit) if (close[na] == false)
			{
				close[na] = true;
				open ~= na;
			}
			if (nb < limit) if (close[nb] == false)
			{
				close[nb] = true;
				open ~= nb;
			}
		}
		bool ok = true;
		foreach (j; close.length-min(a,b)..close.length)
		{
			if (close[j] == false)
			{
				ok = false;
				break;
			}
		}
		ans[i] = ok;
	}

	foreach (e; ans)
	{
		writeln(e ? "Finite" : "Infinite");
	}
	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.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

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; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
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; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long 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 main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (i; 0..t)
	{
		auto a = RD!int;
		auto b = RD!int;
		int[] open = [0];
		auto limit = (10^^4)+1;
		auto close = new bool[](limit);
		close[0] = true;
		while (!open.empty)
		{
			auto n = open.front; open.popFront;
			auto na = (n+a);
			auto nb = (n+b);
			if (na < limit) if (close[na] == false)
			{
				close[na] = true;
				open ~= na;
			}
			if (nb < limit) if (close[nb] == false)
			{
				close[nb] = true;
				open ~= nb;
			}
		}
		bool ok = true;
		foreach (j; close.length-min(a,b)..close.length)
		{
			if (close[j] == false)
			{
				ok = false;
				break;
			}
		}
		ans[i] = ok;
	}

	foreach (e; ans)
	{
		writeln(e ? "Finite" : "Infinite");
	}
	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.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

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; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
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; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long 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 main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (i; 0..t)
	{
		auto a = RD!int;
		auto b = RD!int;
		int[] open = [0];
		auto limit = (10^^4)+1;
		auto close = new bool[](limit);
		close[0] = true;
		while (!open.empty)
		{
			auto n = open.front; open.popFront;
			auto na = (n+a);
			auto nb = (n+b);
			if (na < limit) if (close[na] == false)
			{
				close[na] = true;
				open ~= na;
			}
			if (nb < limit) if (close[nb] == false)
			{
				close[nb] = true;
				open ~= nb;
			}
		}
		bool ok = true;
		foreach (j; close.length-max(a,b)..close.length)
		{
			if (close[j] == false)
			{
				ok = false;
				break;
			}
		}
		ans[i] = ok;
	}

	foreach (e; ans)
	{
		writeln(e ? "Finite" : "Infinite");
	}
	stdout.flush();
	debug readln();
}


// Vicfred
// https://codeforces.com/contest/1555/problem/A
// basic math
import std.algorithm;
import std.stdio;

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

while(t--) {
    long n;
    readf("%s\n", &n);
    long ans = max(6L, n + 1L) / 2L * 5L;
    ans.writeln;
}
}

import std.stdio;
import std.ascii;
import std.algorithm;
import std.range;
import core.stdc.stdio;

void main()
{
	int t = readInt!int; while (t--) solve;
}
void solve()
{
	long n = readInt!long;
	if (n <= 6)
	{
		return 15.writeln;
	}
	n += n % 2;
	((n/2)*5).writeln;
}

/* INPUT ROUTINES */
int currChar;
static this()
{
	currChar = getchar();
}

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

void popChar()
{
	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;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
	long rep;
	this(long num)
	{
		rep = num;
	}

	Z!m opBinary(string operator)(Z!m rhs)
	{
		static if (operator == "+")
		{
			long result = rhs.rep + this.rep;
			if (result >= m)
				result -= m;
			return Z!m(result);
		}
		else static if (operator == "-")
		{
			long result = this.rep - rhs.rep;
			if (result < 0)
				result += m;
			return Z!m(result);
		}
		else static if (operator == "*")
		{
			long result = this.rep * rhs.rep;
			if (result >= m)
				result %= m;
			return Z!m(result);
		}
		else
			static assert(text("Operator ", operator, " not supported"));
	}

	Z!m opBinary(string operator)(long exponent) if (operator == "^^")
	{
		assert(exponent >= 0);
		Z!m base = this;
		Z!m result = 1;
		while (exponent)
		{
			if (exponent & 1)
				result = result * base;
			base = base * base;
			exponent >>= 1;
		}
		return result;
	}

	invariant
	{
		assert(rep >= 0 && rep < m);
	}
}

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

void theCode(){
    ll n = scan;
    ll tim = (n / 2) * 5;
    if(n % 2 != 0) tim += 5;
    tim = max(tim, 15);
    writeln(tim);
}

void main(){
    long 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");

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()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long n;
    readf!" %d "(n);
    n = (n + 1) / 2;
    if (n < 3)
      n = 3;
    writeln(n * 5);
  }
}