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, z;
		readf !(" %s %s %s") (n, k, z);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;

		auto f = new int [] [] (k + 2, z + 1);
		foreach (ref g; f)
		{
			g[] = int.min;
		}
		f[0][0] = a[0];
		foreach (i; 0..k)
		{
			for (int j = 0; j * 2 <= i && j <= z; j++)
			{
				f[i + 1][j] = max (f[i + 1][j],
				    f[i][j] + a[i + 1 - j * 2]);
				if (j < z)
				{
					f[i + 2][j + 1] = max (f[i + 2][j + 1],
					    f[i][j] + a[i + 1 - j * 2] +
					    a[i - j * 2]);
				}
			}
		}

		writeln (f[k].maxElement);
	}
}

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 k = RD!int;
		auto z = RD!int;
		auto a = RDA!int;

		foreach (i; 0..min((k-1)/2, z)+1)
		{
			long cnt;
			foreach (j; 0..k+1-i*2)
			{
				cnt += a[j];
			}
			foreach (j; 1..k+1-i*2)
			{
				auto best = a[j-1] + a[j];
				ans[ti].chmax(cnt + best * i);
				if (j != k-i*2 && i < z)
					ans[ti].chmax(cnt + best * i - a[k-i*2] + a[k-i*2-2]);
			}
		}
	}

	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) { 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 k = RD!int;
		auto z = RD!int;
		auto a = RDA!int;

		foreach (i; 0..min(k/2, z)+1)
		{
			long cnt;
			foreach (j; 0..k+1-i*2)
			{
				cnt += a[j];
			}
			long best;
			foreach (j; 1..k+1-i*2)
			{
				best.chmax(a[j-1] + a[j]);
			}
			ans[ti].chmax(cnt + best * i);
			if (i != 0)
				ans[ti].chmax(cnt + best * (i-1) + a[k-i*2] + a[k-i*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) { 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 k = RD!int;
		auto z = RD!int;
		auto a = RDA!int;

		foreach (i; 0..min((k-1)/2, z)+1)
		{
			long cnt;
			foreach (j; 0..k+1-i*2)
			{
				cnt += a[j];
			}
			foreach (j; 1..k+1-i*2)
			{
				auto best = a[j-1] + a[j];
				ans[ti].chmax(cnt + best * i);
				if (i != 0 && i < z)
					ans[ti].chmax(cnt + best * i - a[k-i*2] + a[k-i*2-2]);
			}
		}
	}

	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) { 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 k = RD!int;
		auto z = RD!int;
		auto a = RDA!int;

		foreach (i; 0..min((k-1)/2, z)+1)
		{
			long cnt;
			foreach (j; 0..k+1-i*2)
			{
				cnt += a[j];
			}
			foreach (j; 1..k+1-i*2)
			{
				auto best = a[j-1] + a[j];
				ans[ti].chmax(cnt + best * i);
				if (i < z)
					ans[ti].chmax(cnt + best * i - a[k-i*2] + a[k-i*2-2]);
			}
		}
	}

	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) { 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 k = RD!int;
		auto z = RD!int;
		auto a = RDA!int;

		foreach (i; 0..min((k-1)/2, z)+1)
		{
			long cnt;
			foreach (j; 0..k+1-i*2)
			{
				cnt += a[j];
			}
			foreach (j; 1..k+1-i*2)
			{
				auto best = a[j-1] + a[j];
				ans[ti].chmax(cnt + best * i);
				if (j == k-i*2-1 && i != 0 && i < z)
					ans[ti].chmax(cnt + best * i - a[k-i*2] + a[k-i*2-2]);
			}
		}
	}

	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) { 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 k = RD!int;
		auto z = RD!int;
		auto a = RDA!int;

		foreach (i; 0..z+1)
		{
			long cnt;
			foreach (j; 0..k+1-i*2)
			{
				cnt += a[j];
			}
			long best;
			foreach (j; 1..k+1-i*2)
			{
				best.chmax(a[j-1] + a[j]);
			}
			cnt += best * i;
			ans[ti].chmax(cnt);
		}
	}

	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) { 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 k = RD!int;
		auto z = RD!int;
		auto a = RDA!int;

		foreach (i; 0..min(k/2, z*2)+1)
		{
			long cnt;
			foreach (j; 0..k+1-i)
			{
				cnt += a[j];
			}
			long best;
			foreach (j; 1..k+1-i)
			{
				best.chmax(a[j-1] + a[j]);
			}
			cnt += best * (i/2);
			if (i % 2)
			{
				if (a[k-i] < a[k-i-2])
					cnt += a[k-i-2] - a[k-i];
			}
			ans[ti].chmax(cnt);
		}
	}

	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, m;
		readf !(" %s %s") (n, m);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto b = readln.splitter.map !(to !(int)).array;
		auto c = readln.splitter.map !(to !(int)).array;
		auto need = new int [] [n + 1];
		auto can = new int [] [n + 1];
		foreach (i; 0..n)
		{
			if (a[i] == b[i])
			{
				can[b[i]] ~= i;
			}
			else
			{
				need[b[i]] ~= i;
			}
		}
		bool ok = true;
		auto answer = new int [m];
		foreach_reverse (j, x; c)
		{
			if (!need[x].empty)
			{
				answer[j] = need[x].front;
				need[x].popFront ();
			}
			else if (!can[x].empty)
			{
				answer[j] = can[x].front;
			}
			else if (j < m - 1)
			{
				answer[j] = answer[m - 1];
			}
			else
			{
				ok = false;
			}
		}
		ok &= need.all !(empty);
		if (ok)
		{
			writefln !("YES\n%(%s %)") (answer.map !(q{a + 1}));
		}
		else
		{
			writeln ("NO");
		}
	}
}

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, M; get(N, M);
        int[] aa, bb, cc; get(aa); get(bb); get(cc);
        auto ww = new int[][N + 1];
        auto rr = new int[](N + 1);
        rr[] = -1;
        foreach (i; 0..N) {
            auto a = aa[i], b = bb[i];
            if (a == b) {
                rr[a] = i.to!int;
            } else {
                ww[b] ~= i.to!int;
            }
        }

        auto res = new int[](M);
        int[] rest;
        foreach (i, c; cc) {
            if (ww[c].empty) {
                if (rr[c] == -1) {
                    rest ~= i.to!int;
                } else {
                    while (!rest.empty) {
                        res[rest.front] = rr[c];
                        rest.popFront();
                    }
                    res[i] = rr[c];
                }
            } else {
                while (!rest.empty) {
                    res[rest.front] = ww[c].front;
                    rest.popFront();
                }
                res[i] = ww[c].front;
                rr[c] = ww[c].front;
                ww[c].popFront();
            }
        }
        if (!rest.empty) goto ng;
        foreach (w; ww) if (!w.empty) goto ng;
        writefln!"YES\n%(%d %)"(res.map!"a + 1");
        continue;
        ng:
        writeln("NO");
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		auto a = RDA(-1);
		auto b = RDA(-1);
		auto c = RDA(-1);

		auto used = new int[](n);
		used[] = -1;
		auto pos = new int[][](n);
		foreach (i; 0..n)
		{
			used[b[i]] = i;
			if (a[i] != b[i])
			{
				pos[b[i]] ~= i;
			}
		}

		ans[ti].length = m;
		int[] s;
		foreach (i; 0..m)
		{

			if (pos[c[i]].empty)
			{
				if (used[c[i]] == -1)
					s ~= i;
				else
				{
					auto j = used[c[i]];
					while (!s.empty)
					{
						auto k = s.front; s.popFront;
						ans[ti][k] = j+1;
					}
					ans[ti][i] = j+1;
				}
			}
			else
			{
				auto j = pos[c[i]].front; pos[c[i]].popFront;
				while (!s.empty)
				{
					auto k = s.front; s.popFront;
					ans[ti][k] = j+1;
				}
				ans[ti][i] = j+1;
			}
		}
		if (!s.empty)
			ans[ti].length = 0;
		foreach (e; pos)
		{
			if (!e.empty)
			{
				ans[ti].length = 0;
				break;
			}
		}
	}

	foreach (e; ans)
	{
		if (e.empty)
			writeln("NO");
		else
		{
			writeln("YES");
			e.map!(to!string).join(" ").writeln;
		}
	}
	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, m;
		readf !(" %s %s") (n, m);
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto b = readln.splitter.map !(to !(int)).array;
		auto c = readln.splitter.map !(to !(int)).array;
		auto need = new int [] [n + 1];
		auto can = new int [] [n + 1];
		foreach (i; 0..n)
		{
			if (a[i] == b[i])
			{
				can[b[i]] ~= i;
			}
			else
			{
				need[b[i]] ~= i;
			}
		}
		bool ok = true;
		auto answer = new int [m];
		foreach_reverse (j, x; c)
		{
			if (!need[x].empty)
			{
				answer[j] = need[x].front;
				need[x].popFront ();
			}
			else if (!can[x].empty)
			{
				answer[j] = can[x].front;
			}
			else if (j < m - 1)
			{
				answer[j] = answer[m - 1];
			}
			else
			{
				ok = false;
			}
		}
		if (ok)
		{
			writefln !("YES\n%(%s %)") (answer.map !(q{a + 1}));
		}
		else
		{
			writeln ("NO");
		}
	}
}


import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
	int n = read.to!int;

	long[] as;
	foreach(i; 0 .. n) as ~= read.to!long;

	as.sort();

	int[long] ac;
	foreach(a; as){
		if(a !in ac) ac[a] = 0;
		ac[a] += 1;
	}
	long[] ks = ac.keys;
	int f = 0;
	foreach(k; ks){
		if(ac[k] >= 3) f = 9;
		else if(ac[k] == 2){
			if(f == 1) f = 9;
			else if((k - 1) in ac) f = 9;
			else if(k == 0) f = 9;
			else if(f == 0) f = 1;
		}
	}
	if(f == 9){
		"cslnb".writeln;
		return;
	}

	long x;
	foreach(i, a; as) x += a - i;

	if(x % 2 == 1) "sjfnb".writeln;
	else "cslnb".writeln;

}

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

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

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

        arr.sort();

        if (arr.length == 2 && arr[0] == 0 && arr[1] <= 1) {
            writeln("cslnb");
            return;
        }

        auto copy = false;
        for (int i = 0; i+1 < arr.length; ++i) {
            if (arr[i] == arr[i+1]) {
                if (copy
                    || arr[i] == 0
                    || (i > 0 && arr[i-1] + 1 == arr[i])) {
                    writeln("cslnb");
                    return;
                }

                copy = true;
            }
        }

        auto opt = n.iota;

        debug { opt.writeln; }

        auto steps = zip(arr, opt).map!"a[0] - a[1]".sum(0L);

        if (steps % 2 == 1) {
            writeln("sjfnb");
        } else {
            writeln("cslnb");
        }
    }

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;

immutable long MOD = 10^^9 + 7;

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

    if (A.map!(a => a == 0).all) {
        writeln("cslnb");
        return;
    }

    int[long] mp;
    foreach (a; A) mp[a] += 1;
    int two_count = 0;
    long two = -1;

    foreach (k; mp.keys) {
        if (mp[k] >= 3) {
            writeln("cslnb");
            return;
        }
        if (mp[k] == 2) {
            two_count += 1;
            two = k;
        }
    }

    if (two_count >= 2) {
        writeln("cslnb");
        return;
    }
    if (two_count == 1 && (two - 1) in mp) {
        writeln("cslnb");
        return;
    }
    if (two_count == 1 && two == 0) {
        writeln("cslnb");
        return;
    }

    long sm = 0;
    long mx = -1;
    A.sort();

    foreach (a; A) {
        sm += (a - mx - 1) % 2;
        mx += 1;
    }

    writeln(sm % 2 ? "sjfnb" : "cslnb");
}

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;

immutable long MOD = 10^^9 + 7;

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

    if (A.map!(a => a == 0).all) {
        writeln("cslnb");
        return;
    }

    int[long] mp;
    foreach (a; A) mp[a] += 1;
    int two_count = 0;
    long two = -1;

    foreach (k; mp.keys) {
        if (mp[k] >= 3) {
            writeln("cslnb");
            return;
        }
        if (mp[k] == 2) {
            two_count += 1;
            two = k;
        }
    }

    if (two_count >= 2) {
        writeln("cslnb");
        return;
    }
    if (two_count == 1 && (two - 1) in mp) {
        writeln("cslnb");
        return;
    }

    long sm = 0;
    long mx = -1;
    A.sort();

    foreach (a; A) {
        sm += (a - mx - 1) % 2;
        mx += 1;
    }

    writeln(sm % 2 ? "sjfnb" : "cslnb");
}

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;

immutable long MOD = 10^^9 + 7;

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

    if (A.map!(a => a == 0).all) {
        writeln("cslnb");
        return;
    }

    int[long] mp;
    foreach (a; A) mp[a] += 1;
    int two_count = 0;
    long two = -1;

    foreach (k; mp.keys) {
        if (mp[k] >= 3) {
            writeln("cslnb");
            return;
        }
        if (mp[k] == 2) {
            two_count += 1;
            two = k;
        }
    }

    if (two_count >= 2) {
        writeln("cslnb");
        return;
    }
    if (two_count == 1 && (two - 1) in mp) {
        writeln("cslnb");
        return;
    }

    long sm = 0;
    long mx = -1;
    A.sort();

    foreach (a; A) {
        sm += (a - mx - 1);
        mx += 1;
    }

    writeln(sm % 2 ? "sjfnb" : "cslnb");
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
	int n = read.to!int;

	long[] as;
	foreach(i; 0 .. n) as ~= read.to!long;

	as.sort();

	int[long] ac;
	foreach(a; as){
		if(a !in ac) ac[a] = 0;
		ac[a] += 1;
	}
	long[] ks = ac.keys;
	int f = 0;
	foreach(k; ks){
		if(ac[k] >= 3) f = 9;
		else if(ac[k] == 2){
			if(f == 1) f = 9;
			else if((k - 1) in ac) f = 9;
			else if(k == 0) f = 9;
			else f = 1;
		}
	}
	if(f == 9){
		"cslnb".writeln;
		return;
	}

	long x;
	foreach(i, a; as) x += a - i;

	if(x % 2 == 1) "sjfnb".writeln;
	else "cslnb".writeln;

}

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

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

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

        arr.sort();

        if (arr.length == 2 && arr[0] == 0 && arr[1] <= 1) {
            writeln("cslnb");
            return;
        }

        auto copy = false;
        for (int i = 0; i+1 < arr.length; ++i) {
            if (arr[i] == arr[i+1]) {
                if (copy || (i > 0 && arr[i-1] + 1 == arr[i])) {
                    writeln("cslnb");
                    return;
                }

                copy = true;
            }
        }

        auto opt = n.iota;

        debug { opt.writeln; }

        auto steps = zip(arr, opt).map!"a[0] - a[1]".sum(0L);

        if (steps % 2 == 1) {
            writeln("sjfnb");
        } else {
            writeln("cslnb");
        }
    }

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

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

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

    arr.sort();

    if (arr.length == 2 && arr[0] == 0 && arr[1] == 0) {
        writeln("cslnb");
        return;
    }

    auto copy = zip(arr, arr.dropOne, arr.drop(2)).filter!"a[1] == a[2]".array;
    if (copy.length > 1
        || (copy.length == 1
            && (copy[0][0] == copy[0][2] || copy[0][0] + 1 == copy[0][1]))) {
        writeln("cslnb");
        return;
    }

    auto opt = n.iota;

    debug { opt.writeln; }

    auto steps = zip(arr, opt).map!"a[0] - a[1]".sum(0L);

    if (steps % 2 == 1) {
        writeln("sjfnb");
    } else {
        writeln("cslnb");
    }
}


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

bool solve (int [] a)
{
	sort (a);
	while (a.length > 0)
	{
		if (a.length == 1 || a[$ - 2] != a[$ - 1])
		{
			return true;
		}
		a.length -= 2;
	}
	return false;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		writeln (solve (a) ? "Conan" : "Agasa");
	}
}

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;

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

    int[int] C;
    foreach (a; A) {
        if (a in C) C[a] += 1;
        else C[a] = 1;
    }

    auto K = C.keys.dup.sort!"a > b"().array;
    foreach (k; K) {
        if (C[k] % 2) return true;
    }

    return false;
}

void main() {
    writeln(solve ? "Conan" : "Agasa");
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.stdio, std.string, std.traits, std.typecons,
	std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
/// struct vector as c++ vector
struct Vec(T)
{
	private Array!T buf;
	alias buf this;
	this(this)
	{
		buf = buf.dup;
	}
	/// construct from length
	this(U)(U length)
			if (is(U == int) || is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint))
	{
		buf.length = length;
	}
	/// construct from length and default value
	this(U, X)(U length, X val)
			if (isImplicitlyConvertible!(X, T) || (is(U == int)
				|| is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint)))
	{
		buf.length = length;
		foreach (ref x; buf[])
		{
			x = val;
		}
	}
	/// construct from other array
	this(U)(U[] values...) if (isImplicitlyConvertible!(U, T))
	{
		buf = Array!(T)(values);
	}
	/// construct from other range
	this(Range)(Range r)
			if (isInputRange!Range && isImplicitlyConvertible!(ElementType!Range,
				T) && !is(Range == T[]))
	{
		buf = Array!(T)(r);
	}
	/// integer length
	int size() @property const
	{
		return cast(int) buf.length;
	}
}
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///lcm
		T lcm(T)(auto ref T a, auto ref T b)
		{
			return a / gcd(a, b) * b;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///BigInt greatest common divizor
		BigInt biggcd(BigInt a, BigInt b)
		{
			BigInt res = 1;
			while (b)
			{
				if ((a & 1) && (b & 1))
				{
					a -= b;
					a >>= 1;
				}
				else if (a & 1)
				{
					b >>= 1;
				}
				else if (b & 1)
				{
					a >>= 1;
				}
				else
				{
					res <<= 1;
					a >>= 1;
					b >>= 1;
				}
				if (a < b)
					swap(a, b);
			}
			return res * a;
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	///write an array
	void putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)
	{
		writefln("%(%s" ~ ch ~ "%)", a);
	}
	///write a matrix
	void putarr(X)(in X a)
			if (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))
	{
		writefln("%(%(%s %)\n%)", a);
	}
	///get an array
	bool getarr(X)(X a, in size_t n)
	{
		bool b = 1;
		foreach (ref i; a[0 .. n])
			b = input(&i);
		return b;
	}

	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------

void main()
{
	int n;
	read(n);
	auto a = arread!int;
	sort(a);
	int pos = n - 1;
	int last = n - 1;
	while (pos >= 0)
	{
		while (pos >= 0 && a[pos] == a[last])
			pos--;
		if ((last - pos) % 2 == 1)
		{
			writeln("Conan");
			return;
		}
		last = pos;
	}
	writeln("Agasa");
}

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

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

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

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

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

      bool ans = false;
      foreach (g; A.group) {
        if (g[1] % 2 != 0) {
          ans = true;
        }
      }
      writeln(ans ? "Conan" : "Agasa");
    }
  } catch (EOFException e) {
  }
}

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

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

    if (A.map!(a => a == A[0]).all) {
        if (N % 2) {
            return true;
        } else {
            return false;
        }
    } else {
        return true;
    }

}

void main() {
    writeln(solve ? "Conan" : "Agasa");
}


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

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

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

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

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const M = readInt();
        const N = readInt();
        auto A = new string[M];
        foreach (x; 0 .. M) {
          A[x] = readToken();
        }

        auto a = new int[][](M, N);
        foreach (x; 0 .. M) foreach (y; 0 .. N) {
          a[x][y] = A[x][y] - '0';
        }

        int[][] ans;
        void oper(int x0, int y0, int x1, int y1, int x2, int y2) {
          ans ~= [x0, y0, x1, y1, x2, y2];
          a[x0][y0] ^= 1;
          a[x1][y1] ^= 1;
          a[x2][y2] ^= 1;
        }

        foreach (x; 0 .. M - 2) foreach (y; 0 .. N - 2) {
          if (a[x][y]) {
            oper(x, y, x, y + 1, x + 1, y);
          }
        }
        foreach (x; 0 .. M - 2) {
          const y = N - 2;
          if (a[x][y]) {
            if (a[x][y + 1]) {
              oper(x, y, x, y + 1, x + 1, y);
            } else {
              oper(x, y, x + 1, y, x + 1, y + 1);
            }
          } else {
            if (a[x][y + 1]) {
              oper(x, y + 1, x + 1, y, x + 1, y + 1);
            } else {
              oper(x, y, x, y + 1, x + 1, y);
              oper(x, y, x, y + 1, x + 1, y);
            }
          }
        }
        foreach (y; 0 .. N - 2) {
          const x = M - 2;
          if (a[x][y]) {
            if (a[x + 1][y]) {
              oper(x, y, x + 1, y, x, y + 1);
            } else {
              oper(x, y, x, y + 1, x + 1, y + 1);
            }
          } else {
            if (a[x + 1][y]) {
              oper(x + 1, y, x, y + 1, x + 1, y + 1);
            } else {
              oper(x, y, x + 1, y, x, y + 1);
              oper(x, y, x + 1, y, x, y + 1);
            }
          }
        }
        {
          const x = M - 2, y = N - 2;
          foreach (p; 0 .. 1 << 4) {
            auto bs = new int[4];
            foreach (i; 0 .. 4) {
              if (p & 1 << i) {
                foreach (j; 0 .. 4) {
                  if (i != j) {
                    bs[j] ^= 1;
                  }
                }
              }
            }
            debug {
              writeln(p, ": ", bs);
            }
            bool ok = true;
            foreach (j; 0 .. 4) {
              ok = ok && (a[x + j / 2][y + j % 2] == bs[j]);
            }
            if (ok) {
              if (p & 1 << 0) oper(x, y + 1, x + 1, y, x + 1, y + 1);
              if (p & 1 << 1) oper(x, y, x + 1, y, x + 1, y + 1);
              if (p & 1 << 2) oper(x, y, x, y + 1, x + 1, y + 1);
              if (p & 1 << 3) oper(x, y, x, y + 1, x + 1, y);
            }
          }
        }

        writeln(ans.length);
        foreach (row; ans) {
          foreach (i; 0 .. 6) {
            if (i > 0) write(" ");
            write(row[i] + 1);
          }
          writeln;
        }
        debug {
          writeln("a = ", a);
        }
      }
    }
  } catch (EOFException e) {
  }
}

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 rows, cols;
		readf !(" %s %s") (rows, cols);
		readln;
		uint [] [] board;
		foreach (row; 0..rows)
		{
			board ~= readln.strip.map !(q{a - '0'}).array;
		}

		int [] [] answer;

		void go (int row, int col,
		    int row1, int col1, int row2, int col2)
		{
			answer ~= [row, col, row1, col1, row2, col2];
			board[row][col] ^= 1;
			board[row1][col1] ^= 1;
			board[row2][col2] ^= 1;
		}

		foreach_reverse (row; 0..rows)
		{
			foreach_reverse (col; 0..cols)
			{
				if ((row == rows - 1 && rows % 2 == 1) ||
				    (col == cols - 1 && cols % 2 == 1))
				{
					if (board[row][col])
					{
						auto row1 = max (row - 1, 0);
						auto col1 = max (col - 1, 0);
						auto row2 = row1 + 1;
						auto col2 = col1;
						if (row2 == row &&
						    col2 == col)
						{
							row2 = row1;
							col2 = col1 + 1;
						}
						go (row, col,
						    row1, col1, row2, col2);
					}
				}
			}
		}

		void doSquare (int row, int col)
		{
			while (true)
			{
				auto total = board[row + 0][col + 0] +
				    board[row + 1][col + 0] +
				    board[row + 0][col + 1] +
				    board[row + 1][col + 1];
				if (total == 0)
				{
					break;
				}
				int [] seqRow;
				int [] seqCol;
				foreach_reverse (value; 0..2)
				{
					foreach (rowT; row..row + 2)
					{
						foreach (colT; col..col + 2)
						{
							if (board[rowT][colT]
							    == value)
							{
								seqRow ~= rowT;
								seqCol ~= colT;
							}
						}
					}
				}
				if (total == 2)
				{
					seqRow.popFront ();
					seqCol.popFront ();
				}
				go (seqRow[0], seqCol[0],
				    seqRow[1], seqCol[1],
				    seqRow[2], seqCol[2]);
			}
		}

		for (int row = 0; row + 1 < rows; row += 2)
		{
			for (int col = 0; col + 1 < cols; col += 2)
			{
				doSquare (row, col);
			}
		}

		foreach (row; 0..rows)
		{
			foreach (col; 0..cols)
			{
				if (board[row][col])
				{
					assert (false);
				}
			}
		}

		writeln (answer.length);
		foreach (ref line; answer)
		{
			writefln !("%(%s %)") (line.map !(q{a + 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 long[][][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		auto s = new char[][](n);
		foreach (i; 0..n)
			s[i] = RD!(char[]);

		foreach (y; 0..n-1)
		{
			foreach (x; 0..m-1)
			{
				debug writeln("y:", y, " x:", x);
				void draw(long[] pos)
				{
					ans[ti] ~= [pos[0]+1, pos[1]+1, pos[2]+1, pos[3]+1, pos[4]+1, pos[5]+1];
					foreach (i; 0..3)
					{
						auto yy = cast(int)pos[i*2];
						auto xx = cast(int)pos[i*2+1];
						s[yy][xx] = s[yy][xx] == '0' ? '1' : '0';
					}
				}
				void fin()
				{
					long[] tmp;
					foreach (i; 0..2)
					{
						foreach (j; 0..2)
						{
							if (s[y+i][x+j] == '1')
								tmp ~= [y+i, x+j];
						}
					}
					draw(tmp);
				}
				void fin2()
				{
					long[] tmp;
					bool mode;
					foreach (i; 0..2)
					{
						foreach (j; 0..2)
						{
							if (s[y+i][x+j] == '1')
							{
								if (mode) continue;
								mode = true;
								tmp ~= [y+i, x+j];
							}
							else
								tmp ~= [y+i, x+j];
						}
					}
					draw(tmp);
					fin();
				}
				if (y == n-2 && x == m-2)
				{
					long cnt;
					foreach (i; 0..2)
					{
						foreach (j; 0..2)
						{
							if (s[y+i][x+j] == '1')
								++cnt;
						}
					}
					if (cnt == 4)
					{
						draw([y, x, y, x+1, y+1, x+1]);
						draw([y, x, y+1, x, y+1, x+1]);
						draw([y+1, x, y, x+1, y+1, x+1]);
						fin();
					}
					else if (cnt == 3)
					{
						fin();
					}
					else if (cnt == 2)
					{
						fin2();
					}
					else if (cnt == 1)
					{
						long[] tmp;
						int mode;
						foreach (i; 0..2)
						{
							foreach (j; 0..2)
							{
								if (s[y+i][x+j] == '0')
								{
									if (mode == 2) continue;
									++mode;
									tmp ~= [y+i, x+j];
								}
								else
									tmp ~= [y+i, x+j];
							}
						}
						draw(tmp);
						fin2();
					}
				}
				else if (y == n-2)
				{
					if (s[y][x] == '1' && s[y+1][x] == '1')
						draw([y, x, y+1, x, y, x+1]);
					else if (s[y][x] == '1')
						draw([y, x, y, x+1, y+1, x+1]);
					else if (s[y+1][x] == '1')
						draw([y+1, x, y, x+1, y+1, x+1]);
				}
				else if (x == m-2)
				{
					if (s[y][x] == '1' && s[y][x+1] == '1')
						draw([y, x, y, x+1, y+1, x+1]);
					else if (s[y][x] == '1')
						draw([y, x, y+1, x, y+1, x+1]);
					else if (s[y][x+1] == '1')
						draw([y+1, x, y, x+1, y+1, x+1]);
				}
				else
				{
					if (s[y][x] == '0') continue;
					draw([y, x, y, x+1, y+1, x+1]);
				}
			}
		}
		debug
		{
			foreach (i; 0..n)
				writeln(s[i]);
		}
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		foreach (y; 0..n-1)
		{
			foreach (x; 0..m-1)
			{
				debug writeln("y:", y, " x:", x);
				void draw(long[] pos)
				{
					ans[ti] ~= [pos[0]+1, pos[1]+1, pos[2]+1, pos[3]+1, pos[4]+1, pos[5]+1];
					foreach (i; 0..3)
					{
						auto yy = cast(int)pos[i*2];
						auto xx = cast(int)pos[i*2+1];
						s[yy][xx] = s[yy][xx] == '0' ? '1' : '0';
					}
				}
				void fin()
				{
					long[] tmp;
					foreach (i; 0..2)
					{
						foreach (j; 0..2)
						{
							if (s[y+i][x+j] == '1')
								tmp ~= [y+i, x+j];
						}
					}
					draw(tmp);
				}
				void fin2()
				{
					long[] tmp;
					bool mode;
					foreach (i; 0..2)
					{
						foreach (j; 0..2)
						{
							if (s[y+i][x+j] == '1')
							{
								if (mode) continue;
								mode = true;
								tmp ~= [y+i, x+j];
							}
							else
								tmp ~= [y+i, x+j];
						}
					}
					draw(tmp);
					fin();
				}
				if (y == n-2 && x == m-2)
				{
					writeln(s);
					long cnt;
					foreach (i; 0..2)
					{
						foreach (j; 0..2)
						{
							if (s[y+i][x+j] == '1')
								++cnt;
						}
					}
					if (cnt == 4)
					{
						draw([y, x, y, x+1, y+1, x+1]);
						draw([y, x, y+1, x, y+1, x+1]);
						draw([y+1, x, y, x+1, y+1, x+1]);
						fin();
					}
					else if (cnt == 3)
					{
						fin();
					}
					else if (cnt == 2)
					{
						fin2();
					}
					else if (cnt == 1)
					{
						long[] tmp;
						int mode;
						foreach (i; 0..2)
						{
							foreach (j; 0..2)
							{
								if (s[y+i][x+j] == '0')
								{
									if (mode == 2) continue;
									++mode;
									tmp ~= [y+i, x+j];
								}
								else
									tmp ~= [y+i, x+j];
							}
						}
						draw(tmp);
						fin2();
					}
				}
				else if (y == n-2)
				{
					if (s[y][x] == '1' && s[y+1][x] == '1')
						draw([y, x, y+1, x, y, x+1]);
					else if (s[y][x] == '1')
						draw([y, x, y, x+1, y+1, x+1]);
					else if (s[y+1][x] == '1')
						draw([y+1, x, y, x+1, y+1, x+1]);
				}
				else if (x == m-2)
				{
					if (s[y][x] == '1' && s[y][x+1] == '1')
						draw([y, x, y, x+1, y+1, x+1]);
					else if (s[y][x] == '1')
						draw([y, x, y+1, x, y+1, x+1]);
					else if (s[y][x+1] == '1')
						draw([y+1, x, y, x+1, y+1, x+1]);
				}
				else
				{
					if (s[y][x] == '0') continue;
					draw([y, x, y, x+1, y+1, x+1]);
				}
			}
		}
		debug
		{
			foreach (i; 0..n)
				writeln(s[i]);
		}
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		foreach (y; 0..n-1)
		{
			foreach (x; 0..m-1)
			{
				void draw(long[] pos)
				{
					ans[ti] ~= [pos[0]+1, pos[1]+1, pos[2]+1, pos[3]+1, pos[4]+1, pos[5]+1];
					foreach (i; 0..3)
					{
						auto yy = cast(int)pos[i*2];
						auto xx = cast(int)pos[i*2+1];
						s[yy][xx] = s[yy][xx] == '0' ? '1' : '0';
					}
				}
				void fin()
				{
					long[] tmp;
					foreach (i; 0..2)
					{
						foreach (j; 0..2)
						{
							if (s[y+i][x+j] == '1')
								tmp ~= [y+i, x+j];
						}
					}
					draw(tmp);
				}
				void fin2()
				{
					long[] tmp;
					bool mode;
					foreach (i; 0..2)
					{
						foreach (j; 0..2)
						{
							if (s[y+i][x+j] == '1')
							{
								if (mode) continue;
								mode = true;
								tmp ~= [y+i, x+j];
							}
							else
								tmp ~= [y+i, x+j];
						}
					}
					draw(tmp);
					fin();
				}
				if (y == n-2 && x == m-2)
				{
					long cnt;
					foreach (i; 0..2)
					{
						foreach (j; 0..2)
						{
							if (s[y+i][x+j] == '1')
								++cnt;
						}
					}
					if (cnt == 4)
					{
						draw([y, x, y, x+1, y+1, x+1]);
						draw([y, x, y+1, x, y+1, x+1]);
						draw([y+1, x, y, x+1, y+1, x+1]);
						fin();
					}
					else if (cnt == 3)
					{
						fin();
					}
					else if (cnt == 2)
					{
						fin2();
					}
					else if (cnt == 1)
					{
						long[] tmp;
						int mode;
						foreach (i; 0..2)
						{
							foreach (j; 0..2)
							{
								if (s[y+i][x+j] == '0')
								{
									if (mode == 2) continue;
									++mode;
									tmp ~= [y+i, x+j];
								}
								else
									tmp ~= [y+i, x+j];
							}
						}
						fin2();
					}
				}
				else if (y == n-2)
				{
					if (s[y][x] == '1' && s[y+1][x] == '1')
						draw([y, x, y+1, x, y, x+1]);
					else if (s[y][x] == '1')
						draw([y, x, y, x+1, y+1, x+1]);
					else if (s[y+1][x] == '1')
						draw([y+1, x, y, x+1, y+1, x+1]);
				}
				else if (x == m-2)
				{
					if (s[y][x] == '1' && s[y][x+1] == '1')
						draw([y, x, y, x+1, y+1, x+1]);
					else if (s[y][x] == '1')
						draw([y, x, y+1, x+1, y+1, x+1]);
					else if (s[y][x+1] == '1')
						draw([y+1, x, y, x+1, y+1, x+1]);
				}
				else
				{
					if (s[y][x] == '0') continue;
					draw([y, x, y, x+1, y+1, x+1]);
				}
			}
		}
	}

	foreach (e; ans)
	{
		writeln(e.length);
		foreach (ee; e)
		{
			ee.map!(to!string).join(" ").writeln;
		}
	}
	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 rows, cols;
		readf !(" %s %s") (rows, cols);
		readln;
		uint [] [] board;
		foreach (row; 0..rows)
		{
			board ~= readln.strip.map !(q{a - '0'}).array;
		}

		int [] [] answer;

		void go (int row, int col,
		    int row1, int col1, int row2, int col2)
		{
			answer ~= [row, col, row1, col1, row2, col2];
			board[row][col] ^= 1;
			board[row1][col1] ^= 1;
			board[row2][col2] ^= 1;
		}

		foreach (row; 0..rows)
		{
			foreach (col; 0..cols)
			{
				if ((row == rows - 1 && rows % 2 == 1) ||
				    (col == cols - 1 && cols % 2 == 1))
				{
					if (board[row][col])
					{
						auto row1 = max (row - 1, 0);
						auto col1 = max (col - 1, 0);
						auto row2 = row1 + 1;
						auto col2 = col1;
						if (row2 == row && col2 == col)
						{
							row2 = row1;
							col2 = col1 + 1;
						}
						if (row2 == row && col2 == col)
						{
							assert (false);
						}
						go (row, col,
						    row1, col1, row2, col2);
					}
				}
			}
		}

		void doSquare (int row, int col)
		{
			while (true)
			{
				auto total = board[row + 0][col + 0] +
				    board[row + 1][col + 0] +
				    board[row + 0][col + 1] +
				    board[row + 1][col + 1];
				if (total == 0)
				{
					break;
				}
				int [] seqRow;
				int [] seqCol;
				foreach_reverse (value; 0..2)
				{
					foreach (rowT; row..row + 2)
					{
						foreach (colT; col..col + 2)
						{
							if (board[rowT][colT]
							    == value)
							{
								seqRow ~= rowT;
								seqCol ~= colT;
							}
						}
					}
				}
				if (total == 2)
				{
					seqRow = seqRow[1..$] ~ seqRow[0];
					seqCol = seqCol[1..$] ~ seqCol[0];
				}
				go (seqRow[0], seqCol[0],
				    seqRow[1], seqCol[1],
				    seqRow[2], seqCol[2]);
			}
		}

		for (int row = 0; row + 1 < rows; row += 2)
		{
			for (int col = 0; col + 1 < cols; col += 2)
			{
				doSquare (row, col);
			}
		}

		writeln (answer.length);
		foreach (ref line; answer)
		{
			writefln !("%(%s %)") (line.map !(q{a + 1}));
		}
	}
}

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 rows, cols;
		readf !(" %s %s") (rows, cols);
		readln;
		uint [] [] board;
		foreach (row; 0..rows)
		{
			board ~= readln.strip.map !(q{a - '0'}).array;
		}

		int [] [] answer;

		void go (int row, int col,
		    int row1, int col1, int row2, int col2)
		{
			answer ~= [row, col, row1, col1, row2, col2];
			board[row][col] ^= 1;
			board[row1][col1] ^= 1;
			board[row2][col2] ^= 1;
		}

		foreach_reverse (row; 0..rows)
		{
			foreach_reverse (col; 0..cols)
			{
				if ((row == rows - 1 && rows % 2 == 1) ||
				    (col == cols - 1 && cols % 2 == 1))
				{
					if (board[row][col])
					{
						auto row1 = max (row - 1, 0);
						auto col1 = max (col - 1, 0);
						auto row2 = row1 + 1;
						auto col2 = col1;
						if (row2 == rows - 1 ||
						    col2 == cols - 1)
						{
							row2 = row1;
							col2 = col1 + 1;
						}
						go (row, col,
						    row1, col1, row2, col2);
					}
				}
			}
		}

		void doSquare (int row, int col)
		{
			while (true)
			{
				auto total = board[row + 0][col + 0] +
				    board[row + 1][col + 0] +
				    board[row + 0][col + 1] +
				    board[row + 1][col + 1];
				if (total == 0)
				{
					break;
				}
				int [] seqRow;
				int [] seqCol;
				foreach_reverse (value; 0..2)
				{
					foreach (rowT; row..row + 2)
					{
						foreach (colT; col..col + 2)
						{
							if (board[rowT][colT]
							    == value)
							{
								seqRow ~= rowT;
								seqCol ~= colT;
							}
						}
					}
				}
				if (total == 2)
				{
					seqRow = seqRow[1..$] ~ seqRow[0];
					seqCol = seqCol[1..$] ~ seqCol[0];
				}
				go (seqRow[0], seqCol[0],
				    seqRow[1], seqCol[1],
				    seqRow[2], seqCol[2]);
			}
		}

		for (int row = 0; row + 1 < rows; row += 2)
		{
			for (int col = 0; col + 1 < cols; col += 2)
			{
				doSquare (row, col);
			}
		}

		writeln (answer.length);
		foreach (ref line; answer)
		{
			writefln !("%(%s %)") (line.map !(q{a + 1}));
		}
	}
}


import std;

void main () {
    immutable tests = (){ uint t; readf!"%s\n"(t); return t; }();

    TEST_LOOP: foreach (test_index; 0 .. tests) {
        immutable n = (){ uint n; readf!"%s\n"(n); return n; }();

        immutable vec =
            readln.chomp
            .split(' ')
            .to!(uint[]);

        immutable frec = (){
            uint[uint] ret;
            vec.each!(x => ++ ret[x]);
            return ret.assumeUnique;
        }();

        ulong previousCost;
        immutable(int)[] ans; ans.reserve(n);
        uint[200_000] stack; /* Imagine having a stack in the standard library */
        assert(stack.length >= n);
        size_t top;

        if (0 !in frec) {
            writefln!"0 %(%s %)"(repeat(-1, n));
            continue;
        }

        write(frec[0]);
        previousCost = 0;
        foreach (_; 1 .. frec[0])
            stack[top ++] = 0;

        foreach (i; 1 .. n + 1) {
            if (i !in frec) {
                write(' ', previousCost);
                if (top != 0) {
                    previousCost += i - stack[-- top];
                } else {
                    writefln!" %(%s %)"(repeat(-1, n - i));
                    continue TEST_LOOP;
                }
            } else {
                write(' ', previousCost + frec[i]);
                foreach (_; 1 .. frec[i])
                    stack[top ++] = i;
            }
        }
    }
}
// ""

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

enum long INF = 1L<<50;

void solve() {
    int N = read!int;
    auto A = readarray!int;

    int[int] m;
    foreach (a; A) {
        m[a] = m.get(a, 0) + 1;
    }

    auto s = new RedBlackTree!(int, "a < b", true)();
    auto f = new long[N + 1];
    for (int k = 0; k < N; k++) {
        if (k in m) {
            foreach (_; 0 .. m[k]) {
                s.insert(k);
            }
        }
        if (s.empty) {
            f[k + 1] = INF;
        } else {
            int sm = s.back;
            f[k + 1] = f[k] + (k - sm);
            s.removeKey(sm);
        }
    }
    auto ans = new long[N + 1];
    for (int k = 0; k <= N; k++) {
        ans[k] = f[k] + m.get(k, 0);
    }
    writefln("%(%s %)", ans.map!(x => x >= INF ? -1 : x).array);
}

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

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

enum int INF = 1<<28;

void solve() {
    int N = read!int;
    auto A = readarray!int;
    sort(A);

    int[int] m;
    foreach (a; A) {
        m[a] = m.get(a, 0) + 1;
    }

    auto s = new RedBlackTree!(int, "a < b", true)();
    auto f = new int[N + 1];
    for (int k = 0; k < N; k++) {
        if (k in m) {
            foreach (_; 0 .. m[k]) {
                s.insert(k);
            }
        }
        if (s.empty) {
            f[k + 1] = INF;
        } else {
            int sm = s.back;
            f[k + 1] = f[k] + (k - sm);
            s.removeKey(sm);
        }
    }
    auto ans = new int[N + 1];
    for (int k = 0; k <= N; k++) {
        ans[k] = f[k] + m.get(k, 0);
    }
    writefln("%(%s %)", ans.map!(x => x >= INF ? -1 : x).array);
}

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

import std;

void main () {
    immutable tests = (){ uint t; readf!"%s\n"(t); return t; }();

    TEST_LOOP: foreach (test_index; 0 .. tests) {
        immutable n = (){ uint n; readf!"%s\n"(n); return n; }();

        immutable vec =
            readln.chomp
            .split(' ')
            .to!(uint[]);

        immutable frec = (){
            uint[uint] ret;
            vec.each!(x => ++ ret[x]);
            return ret.assumeUnique;
        }();

        uint previousCost;
        immutable(int)[] ans; ans.reserve(n);
        uint[200_000] stack; /* Imagine having a stack in the standard library */
        assert(stack.length >= n);
        size_t top;

        if (0 !in frec) {
            writefln!"0 %(%s %)"(repeat(-1, n));
            continue;
        }

        write(frec[0]);
        previousCost = 0;
        foreach (_; 1 .. frec[0])
            stack[top ++] = 0;

        foreach (i; 1 .. n + 1) {
            if (i !in frec) {
                write(' ', previousCost);
                if (top != 0) {
                    previousCost += i - stack[-- top];
                } else {
                    writefln!" %(%s %)"(repeat(-1, n - i));
                    continue TEST_LOOP;
                }
            } else {
                write(' ', previousCost + frec[i]);
                foreach (_; 1 .. frec[i])
                    stack[top ++] = i;
            }
        }
    }
}
// ""


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 readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}
void writeA(T)(size_t n,T t){foreach(i,v;t.enumerate){write(v);if(i<n-1)write(" ");}writeln;}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  auto b = new int[](n);
  foreach (i; 0..n)
    b[i] = div(a[i]);

  int[int] z;
  foreach (i, bi; (b ~ [0]).dup.sort.uniq.enumerate) z[bi] = i.to!int;
  auto nz = z.length.to!int, zz = z[0];

  foreach (ref bi; b) bi = z[bi];

  auto r = new int[](n+1), c = new bool[](nz);
  foreach (i; 0..n) {
    c[] = false; c[b[i]] = true;
    auto e = 1;
    r[e]++;
    foreach (j; i+1..n) {
      if (c[zz]) {
        c[zz] = false;
        --e;
      }

      if (e == 0 || b[j] != zz && !c[b[j]]) {
        c[b[j]] = true;
        ++e;
      }

      r[e]++;
    }
  }

  writeA(n, r[1..$]);
}

auto div(int a)
{
  int[] r;
  if (a == 0) return 0;

  if (a < 0) {
    r ~= [-1];
    a = -a;
  }

  foreach (pi; 2..a.nsqrt+1) {
    if (a == 1) break;
    auto c = 0;
    while (a%pi == 0) {
      ++c;
      a /= pi;
    }
    if (c%2 == 1) r ~= pi;
  }

  if (a != 1) r ~= a;

  return r.fold!"a*b"(1);
}

pure T[] primes(T)(T n)
{
  import std.algorithm, std.bitmanip, std.conv, std.range;

  auto sieve = BitArray();
  sieve.length((n+1)/2);
  sieve = ~sieve;

  foreach (p; 1..((nsqrt(n)-1)/2+1))
    if (sieve[p])
      for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)
        sieve[q] = false;

  auto r = sieve.bitsSet.map!(to!T).map!("a*2+1").array;
  r[0] = 2;

  return r;
}

pure T factor(T)(T n, const T[] p)
{
  auto ma = nsqrt(n)+1;
  foreach (pi; p)
    if (pi > ma) return n;
    else if (n%pi == 0) return pi;
  return n;
}

pure T nsqrt(T)(T n)
{
  import std.algorithm, std.conv, std.range, core.bitop;
  if (n <= 1) return n;
  T m = T(1) << (n.bsr/2+1);
  return iota(1, m).map!"a*a".assumeSorted!"a <= b".lowerBound(n).length.to!T;
}

import std.stdio, std.string;
import std.math, std.algorithm;

void solve(int[] a, int n)
{
    auto f = new bool[][](n, n);
    auto c = new int[n];
    foreach (i; 0 .. n)
    {
        c[i] = 0;
        auto num = cast(long)a[i];
        foreach (j; 0 .. i)
        {
            f[j][i] = false;
            auto m = num * a[j];
            if (m > 0)
            {
                auto r = cast(long)sqrt(cast(double)m);
                if (r * r == m)
                {
                    f[j][i] = true;
                    ++ c[i];
                }
            }
        }
    }
    auto res = new int[n + 1];
    fill(res, 0);
    foreach (i; 0 .. n)
    {
        auto cnt = 0;
        auto flag = false;
        foreach (j; i .. n)
        {
            if (a[j] == 0)
            {
                if (cnt == 0)
                {
                    ++ cnt;
                }
            }
            else
            {
                if (i > 0 && f[i - 1][j])
                {
                    -- c[j];
                }
                if (flag == false)
                {
                    if (cnt == 0)
                    {
                        ++ cnt;
                    }
                }
                else if (c[j] == 0)
                {
                    ++ cnt;
                }
            }
            ++ res[cnt];
            if (a[j] != 0)
            {
                flag = true;
            }
        }
    }
    foreach (i; 1 .. n)
    {
        write(res[i], " ");
    }
    writeln(res[n]);
}

int main(string[] args)
{
    int n;
    while (readf("%d\n", &n) == 1)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n);
    }
    return 0;
}

import std.stdio, std.string;
import std.math, std.algorithm;

void solve(int[] a, int n)
{
    auto f = new bool[][](n, n);
    auto c = new int[n];
    foreach (i; 0 .. n)
    {
        c[i] = 0;
        auto num = cast(long)a[i];
        foreach (j; 0 .. i)
        {
            f[j][i] = false;
            auto m = num * a[j];
            if (m >= 0)
            {
                auto r = sqrt(cast(double)m);
                if (r - cast(int)r <= 1e-9)
                {
                    f[j][i] = true;
                    ++ c[i];
                }
            }
        }
    }
    auto res = new int[n + 1];
    fill(res, 0);
    foreach (i; 0 .. n)
    {
        auto cnt = 0;
        foreach (j; i .. n)
        {
            if (i > 0 && f[i - 1][j])
            {
                -- c[j];
            }
            if (c[j] == 0)
            {
                ++ cnt;
            }
            ++ res[cnt];
        }
    }
    foreach (i; 1 .. n)
    {
        write(res[i], " ");
    }
    writeln(res[n]);
}

int main(string[] args)
{
    int n;
    while (readf("%d\n", &n) == 1)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n);
    }
    return 0;
}

import std.stdio, std.string;
import std.math, std.algorithm;

void solve(int[] a, int n)
{
    auto f = new bool[][](n, n);
    auto c = new int[n];
    foreach (i; 0 .. n)
    {
        c[i] = 0;
        auto num = cast(long)a[i];
        foreach (j; 0 .. i)
        {
            auto m = num * a[j];
            if (m >= 0)
            {
                auto r = sqrt(cast(double)m);
                f[j][i] = false;
                if (cast(long)r == r)
                {
                    f[j][i] = true;
                    ++ c[i];
                }
            }
        }
    }
    auto res = new int[n + 1];
    fill(res, 0);
    foreach (i; 0 .. n)
    {
        auto cnt = 0;
        foreach (j; i .. n)
        {
            if (i > 0 && f[i - 1][j])
            {
                -- c[j];
            }
            if (c[j] == 0)
            {
                ++ cnt;
            }
            ++ res[cnt];
        }
    }
    foreach (i; 1 .. n)
    {
        write(res[i], " ");
    }
    writeln(res[n]);
}

int main(string[] args)
{
    int n;
    while (readf("%d\n", &n) == 1)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n);
    }
    return 0;
}

import std.stdio, std.string;
import std.math, std.algorithm;

void solve(int[] a, int n)
{
    auto f = new bool[][](n, n);
    auto c = new int[n];
    foreach (i; 0 .. n)
    {
        c[i] = 0;
        auto num = cast(long)a[i];
        foreach (j; 0 .. i)
        {
            auto m = num * a[j];
            if (m >= 0)
            {
                auto r = sqrt(cast(double)m);
                f[j][i] = false;
                if (r - cast(int)r <= 1e-9)
                {
                    f[j][i] = true;
                    ++ c[i];
                }
            }
        }
    }
    auto res = new int[n + 1];
    fill(res, 0);
    foreach (i; 0 .. n)
    {
        auto cnt = 0;
        foreach (j; i .. n)
        {
            if (i > 0 && f[i - 1][j])
            {
                -- c[j];
            }
            if (c[j] == 0)
            {
                ++ cnt;
            }
            ++ res[cnt];
        }
    }
    foreach (i; 1 .. n)
    {
        write(res[i], " ");
    }
    writeln(res[n]);
}

int main(string[] args)
{
    int n;
    while (readf("%d\n", &n) == 1)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n);
    }
    return 0;
}

import std.stdio, std.string;
import std.math, std.algorithm;

void solve(int[] a, int n)
{
    auto f = new bool[][](n, n);
    auto c = new int[n];
    foreach (i; 0 .. n)
    {
        c[i] = 0;
        auto num = cast(double)a[i];
        foreach (j; 0 .. i)
        {
            f[j][i] = false;
            auto m = num * a[j];
            if (m > 0)
            {
                auto r = cast(long)sqrt(m);
                if (r * r == m)
                {
                    f[j][i] = true;
                    ++ c[i];
                }
            }
        }
    }
    auto res = new int[n + 1];
    fill(res, 0);
    foreach (i; 0 .. n)
    {
        auto cnt = 0;
        auto flag = false;
        foreach (j; i .. n)
        {
            if (a[j] == 0)
            {
                if (cnt == 0) ++ cnt;
            }
            else
            {
                if (i > 0 && f[i - 1][j])
                {
                    -- c[j];
                }
                if (flag == false)
                {
                    if (cnt == 0) ++ cnt;
                }
                else if (c[j] == 0)
                {
                    ++ cnt;
                }
            }
            ++ res[cnt];
            if (a[j] != 0)
            {
                flag = true;
            }
        }
    }
    foreach (i; 1 .. n)
    {
        write(res[i], " ");
    }
    writeln(res[n]);
}

int main(string[] args)
{
    int n;
    while (readf("%d\n", &n) == 1)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n);
    }
    return 0;
}

import std.stdio, std.string;
import std.math, std.algorithm;

void solve(int[] a, int n)
{
    auto f = new bool[][](n, n);
    auto c = new int[n];
    foreach (i; 0 .. n)
    {
        c[i] = 0;
        auto num = cast(long)a[i];
        foreach (j; 0 .. i)
        {
            f[j][i] = false;
            double m = num * a[j];
            if (m >= 0)
            {
                auto r = cast(long)sqrt(cast(double)m);
                if (r * r == m)
                {
                    f[j][i] = true;
                    ++ c[i];
                }
            }
        }
    }
    auto res = new int[n + 1];
    fill(res, 0);
    foreach (i; 0 .. n)
    {
        auto cnt = 0;
        foreach (j; i .. n)
        {
            if (i > 0 && f[i - 1][j])
            {
                -- c[j];
            }
            if (c[j] == 0)
            {
                ++ cnt;
            }
            ++ res[cnt];
        }
    }
    foreach (i; 1 .. n)
    {
        write(res[i], " ");
    }
    writeln(res[n]);
}

int main(string[] args)
{
    int n;
    while (readf("%d\n", &n) == 1)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n);
    }
    return 0;
}

import std.stdio, std.string;
import std.math, std.algorithm;

void solve(int[] a, int n)
{
    auto f = new bool[][](n, n);
    auto c = new int[n];
    foreach (i; 0 .. n)
    {
        c[i] = 0;
        auto num = cast(long)a[i];
        foreach (j; 0 .. i)
        {
            f[j][i] = false;
            auto m = num * a[j];
            if (m >= 0)
            {
                auto r = cast(long)sqrt(cast(double)m);
                if (r * r == m)
                {
                    f[j][i] = true;
                    ++ c[i];
                }
            }
        }
    }
    auto res = new int[n + 1];
    fill(res, 0);
    foreach (i; 0 .. n)
    {
        auto cnt = 0;
        foreach (j; i .. n)
        {
            if (i > 0 && f[i - 1][j])
            {
                -- c[j];
            }
            if (c[j] == 0)
            {
                ++ cnt;
            }
            ++ res[cnt];
        }
    }
    foreach (i; 1 .. n)
    {
        write(res[i], " ");
    }
    writeln(res[n]);
}

int main(string[] args)
{
    int n;
    while (readf("%d\n", &n) == 1)
    {
        auto a = new int[n];
        foreach (i; 0 .. n)
        {
            readf(" %d", &a[i]);
        }
        readln;
        solve(a, n);
    }
    return 0;
}

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 readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  auto p = primes(10^^4);
  auto b = new int[][](n);
  foreach (i; 0..n)
    b[i] = div(a[i], p);

  auto r = new int[](n+1);
  foreach (i; 0..n) {
    auto rbt = redBlackTree!(false, int[])(b[i]);
    r[1]++;
    foreach (j; i+1..n) {
      if (!rbt.empty && rbt.front == [0]) {
        rbt.removeFront();
      }
      if (b[j] != [0]) {
        rbt.insert(b[j]);
      }
      r[rbt.length]++;
    }
  }

  foreach (i; 0..n)
    write(r[i+1], " ");
  writeln;
}

auto div(int a, int[] p)
{
  int[] r;
  if (a == 0) return [0];

  if (a < 0) {
    r ~= [-1];
    a = -a;
  }

  foreach (pi; p) {
    if (a == 1) break;
    auto c = 0;
    while (a%pi == 0) {
      ++c;
      a /= pi;
    }
    if (c%2 == 1) r ~= pi;
  }

  return r;
}

pure T[] primes(T)(T n)
{
  import std.algorithm, std.bitmanip, std.conv, std.range;

  auto sieve = BitArray();
  sieve.length((n+1)/2);
  sieve = ~sieve;

  foreach (p; 1..((nsqrt(n)-1)/2+1))
    if (sieve[p])
      for (auto q = p*3+1; q < (n+1)/2; q += p*2+1)
        sieve[q] = false;

  auto r = sieve.bitsSet.map!(to!T).map!("a*2+1").array;
  r[0] = 2;

  return r;
}

pure T factor(T)(T n, const T[] p)
{
  auto ma = nsqrt(n)+1;
  foreach (pi; p)
    if (pi > ma) return n;
    else if (n%pi == 0) return pi;
  return n;
}

pure T nsqrt(T)(T n)
{
  import std.algorithm, std.conv, std.range, core.bitop;
  if (n <= 1) return n;
  T m = T(1) << (n.bsr/2+1);
  return iota(1, m).map!"a*a".assumeSorted!"a <= b".lowerBound(n).length.to!T;
}


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

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

    Tuple!(int, int)[] pts;
    foreach (i; 0 .. k) {
        int x, y;
        readf("%s %s", &x, &y);
        readln;

        pts ~= tuple(x, y);
    }

    int[][int] up, dwn;
    foreach (i, p; pts) {
        up[p[1] - p[0]] ~= i.to!int;
        dwn[p[1] + p[0]] ~= i.to!int;
    }

    debug { up.writeln; dwn.writeln; }

    auto ans = new long[k];
    ans[] = -1;

    auto vis = new bool[][] (4, max(n+1, m+1));

    Tuple!(int, int) toVis(int x, int y) {
        if (y == 0) { return tuple(0, x); }
        if (y == m) { return tuple(1, x); }
        if (x == 0) { return tuple(2, y); }
        if (x == n) { return tuple(3, y); }

        assert(false);
    }

    vis[0][0] = vis[1][0] = vis[0][n] = vis[1][n] = true;
    int cx = 0, cy = 0, dir = 1;
    long tm = 0;
    do {
        vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]] = true;
        int nx, ny, mv;
        if (dir == 1) {
            mv = min(n - cx, m - cy);
            nx = cx + mv;
            ny = cy + mv;
            dir = ny != m ? 2 : 4;
        } else if (dir == 2) {
            mv = min(cx, m - cy);
            nx = cx - mv;
            ny = cy + mv;
            dir = ny == m ? 3 : 1;
        } else if (dir == 3) {
            mv = min(cx, cy);
            nx = cx - mv;
            ny = cy - mv;
            dir = nx == 0 ? 4 : 2;
        } else {
            mv = min(n - cx, cy);
            nx = cx + mv;
            ny = cy - mv;
            dir = ny == 0 ? 1 : 3;
        }

        bool isUp = (nx - cx).to!long * (ny - cy) > 0;
        int coord = isUp ? ny - nx : ny + nx;
        auto dct = isUp ? &up : &dwn;
        foreach (idx; dct.get(coord, [])) {
            if (ans[idx] != -1) { continue; }

            ans[idx] = tm + abs(pts[idx][0] - cx);
        }

        cx = nx;
        cy = ny;
        tm += mv;

        debug { writeln(cx, ' ', cy, ' ', tm, ' ', dir); }

    } while (!vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]]);

    ans.each!writeln;
}

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 gojo(Int)(Int a, Int b, out Int x, out Int y) {
  if (b != 0) { Int g = gojo(b, a % b, y, x); y -= (a / b) * x; return g; }
  x = 1; y = 0; return a;
}
Tuple!(Int, "b", Int, "m") modSol(Int)(Int b0, Int m0, Int b1, Int m1) {
  Int b, m, x, y;
  const g = gojo(m0, m1, x, y);
  if ((b1 - b0) % g == 0) {
    b = b0 + m0 * ((x * (((b1 - b0) / g) % (m1 / g))) % (m1 / g));
    m = m0 * (m1 / g);
    if ((b %= m) < 0) {
      b += m;
    }
  }
  return Tuple!(Int, "b", Int, "m")(b, m);
}

enum INF = 10L^^18;

void main() {
  try {
    for (; ; ) {
      const M = readLong();
      const N = readLong();
      const K = readInt();
      auto X = new long[K];
      auto Y = new long[K];
      foreach (k; 0 .. K) {
        X[k] = readLong();
        Y[k] = readLong();
      }

      long calc(long x, long y) {
        const res = modSol(x, 2 * M, y, 2 * N);
        debug {
          writeln(x, " ", y, ": ", res);
        }
        return (res.m == 0) ? INF : res.b;
      }

      foreach (k; 0 .. K) {
        long ans = INF;
        foreach (x; [X[k], 2 * M - X[k]]) foreach (y; [Y[k], 2 * N - Y[k]]) {
          const res = calc(x, y);
          chmin(ans, res);
        }
        writeln((ans >= INF) ? -1 : ans);
      }
    }
  } catch (EOFException e) {
  }
}

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

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

    Tuple!(int, int)[] pts;
    foreach (i; 0 .. k) {
        int x, y;
        readf("%s %s", &x, &y);
        readln;

        pts ~= tuple(x, y);
    }

    int[][int] up, dwn;
    foreach (i, p; pts) {
        up[p[1] - p[0]] ~= i.to!int;
        dwn[p[1] + p[0]] ~= i.to!int;
    }

    debug { up.writeln; dwn.writeln; }

    auto ans = new long[k];
    ans[] = -1;

    auto vis = new bool[][] (4, max(n+1, m+1));

    Tuple!(int, int) toVis(int x, int y) {
        if (y == 0) { return tuple(0, x); }
        if (y == m) { return tuple(1, x); }
        if (x == 0) { return tuple(0, y); }
        if (x == n) { return tuple(1, y); }

        assert(false);
    }

    vis[0][0] = vis[1][0] = vis[0][n] = vis[1][n] = true;
    int cx = 0, cy = 0, dir = 1;
    long tm = 0;
    do {
        vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]] = true;
        int nx, ny, mv;
        if (dir == 1) {
            mv = min(n - cx, m - cy);
            nx = cx + mv;
            ny = cy + mv;
            dir = ny != m ? 2 : 4;
        } else if (dir == 2) {
            mv = min(cx, m - cy);
            nx = cx - mv;
            ny = cy + mv;
            dir = ny == m ? 3 : 1;
        } else if (dir == 3) {
            mv = min(cx, cy);
            nx = cx - mv;
            ny = cy - mv;
            dir = nx == 0 ? 4 : 2;
        } else {
            mv = min(n - cx, cy);
            nx = cx + mv;
            ny = cy - mv;
            dir = ny == 0 ? 1 : 3;
        }

        bool isUp = (nx - cx).to!long * (ny - cy) > 0;
        int coord = isUp ? ny - nx : ny + nx;
        auto dct = isUp ? &up : &dwn;
        foreach (idx; dct.get(coord, [])) {
            if (ans[idx] != -1) { continue; }

            ans[idx] = tm + abs(pts[idx][0] - cx);
        }

        cx = nx;
        cy = ny;
        tm += mv;

        debug { writeln(cx, ' ', cy, ' ', tm, ' ', dir); }

    } while (!vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]]);

    ans.each!writeln;
}

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

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

    Tuple!(int, int)[] pts;
    foreach (i; 0 .. k) {
        int x, y;
        readf("%s %s", &x, &y);
        readln;

        pts ~= tuple(x, y);
    }

    int[][int] up, dwn;
    foreach (i, p; pts) {
        up[p[1] - p[0]] ~= i.to!int;
        dwn[p[1] + p[0]] ~= i.to!int;
    }

    debug { up.writeln; dwn.writeln; }

    auto ans = new int[k];
    ans[] = -1;

    auto vis = new bool[][] (4, max(n+1, m+1));

    Tuple!(int, int) toVis(int x, int y) {
        if (y == 0) { return tuple(0, x); }
        if (y == m) { return tuple(1, x); }
        if (x == 0) { return tuple(2, y); }
        if (x == n) { return tuple(3, y); }

        assert(false);
    }

    vis[0][0] = vis[1][0] = vis[0][n] = vis[1][n] = true;
    int cx = 0, cy = 0, dir = 1, tm = 0;
    do {
        vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]] = true;
        int nx, ny, mv;
        if (dir == 1) {
            mv = min(n - cx, m - cy);
            nx = cx + mv;
            ny = cy + mv;
            dir = ny != m ? 2 : 4;
        } else if (dir == 2) {
            mv = min(cx, m - cy);
            nx = cx - mv;
            ny = cy + mv;
            dir = ny == m ? 3 : 1;
        } else if (dir == 3) {
            mv = min(cx, cy);
            nx = cx - mv;
            ny = cy - mv;
            dir = nx == 0 ? 4 : 2;
        } else {
            mv = min(n - cx, cy);
            nx = cx + mv;
            ny = cy - mv;
            dir = ny == 0 ? 1 : 3;
        }

        bool isUp = (nx - cx).to!long * (ny - cy) > 0;
        int coord = isUp ? ny - nx : ny + nx;
        auto dct = isUp ? &up : &dwn;
        foreach (idx; dct.get(coord, [])) {
            if (ans[idx] != -1) { continue; }

            ans[idx] = tm + abs(pts[idx][0] - cx);
        }

        cx = nx;
        cy = ny;
        tm += mv;

        debug { writeln(cx, ' ', cy, ' ', tm, ' ', dir); }

    } while (!vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]]);

    ans.each!writeln;
}

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

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

    Tuple!(int, int)[] pts;
    foreach (i; 0 .. k) {
        int x, y;
        readf("%s %s", &x, &y);
        readln;

        pts ~= tuple(x, y);
    }

    int[][int] up, dwn;
    foreach (i, p; pts) {
        up[p[1] - p[0]] ~= i.to!int;
        dwn[p[1] + p[0]] ~= i.to!int;
    }

    debug { up.writeln; dwn.writeln; }

    auto ans = new int[k];
    ans[] = -1;

    auto vis = new bool[][] (4, max(n+1, m+1));

    Tuple!(int, int) toVis(int x, int y) {
        if (y == 0) { return tuple(0, x); }
        if (y == m) { return tuple(1, x); }
        if (x == 0) { return tuple(0, y); }
        if (x == n) { return tuple(1, y); }

        assert(false);
    }

    vis[0][0] = vis[1][0] = vis[0][n] = vis[1][n] = true;
    int cx = 0, cy = 0, dir = 1, tm = 0;
    do {
        vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]] = true;
        int nx, ny, mv;
        if (dir == 1) {
            mv = min(n - cx, m - cy);
            nx = cx + mv;
            ny = cy + mv;
            dir = ny != m ? 2 : 4;
        } else if (dir == 2) {
            mv = min(cx, m - cy);
            nx = cx - mv;
            ny = cy + mv;
            dir = ny == m ? 3 : 1;
        } else if (dir == 3) {
            mv = min(cx, cy);
            nx = cx - mv;
            ny = cy - mv;
            dir = nx == 0 ? 4 : 2;
        } else {
            mv = min(n - cx, cy);
            nx = cx + mv;
            ny = cy - mv;
            dir = ny == 0 ? 1 : 3;
        }

        bool isUp = (nx - cx).to!long * (ny - cy) > 0;
        int coord = isUp ? ny - nx : ny + nx;
        auto dct = isUp ? &up : &dwn;
        foreach (idx; dct.get(coord, [])) {
            if (ans[idx] != -1) { continue; }

            ans[idx] = tm + abs(pts[idx][0] - cx);
        }

        cx = nx;
        cy = ny;
        tm += mv;

        debug { writeln(cx, ' ', cy, ' ', tm, ' ', dir); }

    } while (!vis[toVis(cx, cy)[0]][toVis(cx, cy)[1]]);

    ans.each!writeln;
}


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

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

    Tuple!(int, int)[] arr;
    foreach (_; 0 .. n) {
        int a, b;
        readf("%s %s", &a, &b);
        readln;

        arr ~= tuple(a, b);
    }

    arr.schwartzSort!(t => t[0] - t[1]).reverse();

    debug { arr.writeln; }

    long total = arr.map!(t => t[0]).sum(0L);
    int ans = 0;
    foreach (e; arr) {
        if (total <= m) break;

        total -= e[0] - e[1];
        ++ans;
    }

    if (total > m) {
        writeln(-1);
        return;
    }

    ans.writeln;
}

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

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

    Tuple!(int, int)[] arr;
    auto fnc = (int[] a) => tuple(a[0], a[1]);
    foreach (_; 0 .. n) {
        int a, b;
        readf("%s %s", &a, &b);
        readln;

        arr ~= tuple(a, b);
    }

    arr.schwartzSort!(t => t[0] - t[1]).reverse();

    debug { arr.writeln; }

    long total = arr.map!(t => t[0]).sum(0L);
    int ans = 0;
    foreach (e; arr) {
        if (total <= m) break;

        total -= e[0] - e[1];
        ++ans;
    }

    if (total > m) {
        writeln(-1);
        return;
    }

    ans.writeln;
}

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

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		readln;
		auto a = new int [n];
		auto b = new int [n];
		foreach (i; 0..n)
		{
			readf (" %s %s", &a[i], &b[i]);
		}
		b[] = a[] - b[];
		sort !(q{a > b}) (b);
		auto total = sum (a, 0L);
		int res = 0;
		while (total > m && !b.empty)
		{
			res += 1;
			total -= b[0];
			b = b[1..$];
		}
		if (total > m)
		{
			res = -1;
		}
		writeln (res);
	}
}