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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto p = readln.splitter.map !(to !(int)).array;
		p[] -= 1;

		void perform (int [] cuts)
		{
			int [] res;
			foreach_reverse (i; 1..cuts.length)
			{
				res ~= p[cuts[i - 1]..cuts[i]];
			}
			p = res;
		}

		int [] [] answer;
		while (!p.isSorted)
		{
			auto q = new int [n];
			foreach (i; 0..n)
			{
				q[p[i]] = i;
			}
			foreach (v; 0..n - 1)
			{
				if (q[v + 1] < q[v] + 1)
				{
					auto pos = q[v + 1];
					while (p[pos + 1] == p[pos] + 1)
					{
						pos += 1;
					}
					auto cuts = only (0, q[v + 1],
					    pos + 1, q[v] + 1, n).uniq.array;
					perform (cuts);
					answer ~= cuts.zip (cuts[1..$])
					    .map !(q{a[1] - a[0]}).array;
					break;
				}
			}
		}
		writeln (answer.length);
		foreach (ref line; answer)
		{
			writefln !("%s %(%s %)") (line.length, line);
		}
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!int;
	auto c = RDA(-1);

	int[][] lrp;
	int[][] ans;
	foreach (_; 0..n)
	{
		{
			lrp.length = 0;
			int l;
			foreach (i; 0..n-1)
			{
				if (c[i]+1 == c[i+1]) continue;
				lrp ~= [c[l], c[i], l];
				l = i+1;
			}
			lrp ~= [c[l], c[$-1], l];
		}
		debug writeln(lrp);
		if (lrp.length == 1) break;

		int[int] list;
		foreach (int j, ref e; lrp)
		{
			auto pos = list.get(e[1]+1, -1);
			if (pos != -1)
			{
				debug writeln(e, " ", lrp[pos]);
				auto ee = lrp[pos];
				auto l = ee[0];
				auto r = ee[1];
				auto p = ee[2];
				auto len = e[1] - e[0] + 1;
				debug writeln("len:", len);
				int[] tmp;
				if (p != 0)
					tmp ~= p;
				tmp ~= e[2] - p;
				tmp ~= len;
				if (e[2]+len < n)
					tmp ~= n - (e[2]+len);
				ans ~= cast(int)tmp.length ~ tmp;

				int[] next;
				int cnt = n;
				foreach_reverse (t; tmp)
				{
					next ~= c[cnt-t..cnt];
					cnt -= t;
				}
				c = next;
				break;
			}
			else
			{
				list[e[0]] = j;
			}
		}
	}

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

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 C = new int[N];
      foreach (i; 0 .. N) {
        C[i] = readInt() - 1;
      }

      auto cs = C.dup;
      int[][] dss;
      int cnt;
      foreach (i; 0 .. N) {
        if (cs[i] != i) {
          foreach (j; 0 .. N) {
            if (cs[j] == i) {
              int[] ds;
              foreach (k; 0 .. i) {
                ds ~= 1;
              }
              ds ~= (j + 1) - i;
              foreach (k; j + 1 .. N) {
                ds ~= 1;
              }
              if (cnt % 2 != 0) {
                ds.reverse;
              }
              ++cnt;
              if (ds.length > 1) {
                dss ~= ds;
              }
              cs[i .. j + 1].reverse;
              break;
            }
          }
        }
      }
      if (cnt % 2 != 0) {
        int[] ds;
        foreach (i; 0 .. N) {
          ds ~= 1;
        }
        ds.reverse;
        if (ds.length > 1) {
          dss ~= ds;
        }
      }

      writeln(dss.length);
      foreach (ds; dss) {
        write(ds.length);
        foreach (d; ds) {
          write(" ", d);
        }
        writeln;
      }

      debug {
        cs = C.dup;
        foreach (ds; dss) {
          int[][] blocks;
          int i;
          foreach (d; ds) {
            blocks ~= cs[i .. i + d];
            i += d;
          }
          assert(i == N);
          blocks.reverse;
          cs = [];
          foreach (block; blocks) {
            cs ~= block;
          }
        }
        assert(cs == iota(N).array, format("C = %s, cs = %s", C, cs));
      }
    }
  } catch (EOFException e) {
  }
}

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 C = new int[N];
      foreach (i; 0 .. N) {
        C[i] = readInt() - 1;
      }

      auto cs = C.dup;
      int[][] dss;
      foreach (i; 0 .. N) {
        if (cs[i] != i) {
          foreach (j; 0 .. N) {
            if (cs[j] == i) {
              int[] ds;
              foreach (k; 0 .. i) {
                ds ~= 1;
              }
              ds ~= (j + 1) - i;
              foreach (k; j + 1 .. N) {
                ds ~= 1;
              }
              if (ds.length > 1) {
                dss ~= ds;
              }
              cs[i .. j + 1].reverse;
              break;
            }
          }
        }
      }
      if (dss.length % 2 != 0) {
        int[] ds;
        foreach (i; 0 .. N) {
          ds ~= 1;
        }
        if (ds.length > 1) {
          dss ~= ds;
        }
      }

      writeln(dss.length);
      foreach (ds; dss) {
        write(ds.length);
        foreach (d; ds) {
          write(" ", d);
        }
        writeln;
      }
    }
  } catch (EOFException e) {
  }
}

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 C = new int[N];
      foreach (i; 0 .. N) {
        C[i] = readInt() - 1;
      }

      auto cs = C.dup;
      int[][] dss;
      int cnt;
      foreach (i; 0 .. N) {
        if (cs[i] != i) {
          foreach (j; 0 .. N) {
            if (cs[j] == i) {
              int[] ds;
              foreach (k; 0 .. i) {
                ds ~= 1;
              }
              ds ~= (j + 1) - i;
              foreach (k; j + 1 .. N) {
                ds ~= 1;
              }
              ++cnt;
              if (ds.length > 1) {
                dss ~= ds;
              }
              cs[i .. j + 1].reverse;
              break;
            }
          }
        }
      }
      if (cnt % 2 != 0) {
        int[] ds;
        foreach (i; 0 .. N) {
          ds ~= 1;
        }
        if (ds.length > 1) {
          dss ~= ds;
        }
      }

      writeln(dss.length);
      foreach (ds; dss) {
        write(ds.length);
        foreach (d; ds) {
          write(" ", d);
        }
        writeln;
      }
    }
  } catch (EOFException e) {
  }
}

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 C = new int[N];
      foreach (i; 0 .. N) {
        C[i] = readInt() - 1;
      }

      auto cs = C.dup;
      int[][] dss;
      foreach (i; 0 .. N) {
        if (cs[i] != i) {
          foreach (j; 0 .. N) {
            if (cs[j] == i) {
              int[] ds;
              foreach (k; 0 .. i) {
                ds ~= 1;
              }
              ds ~= (j + 1) - i;
              foreach (k; j + 1 .. N) {
                ds ~= 1;
              }
              dss ~= ds;
              cs[i .. j + 1].reverse;
              break;
            }
          }
        }
      }
      if (dss.length % 2 != 0) {
        int[] ds;
        foreach (i; 0 .. N) {
          ds ~= 1;
        }
        dss ~= ds;
      }

      writeln(dss.length);
      foreach (ds; dss) {
        write(ds.length);
        foreach (d; ds) {
          write(" ", d);
        }
        writeln;
      }
    }
  } catch (EOFException e) {
  }
}


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

string FMT_F = "%.10f";

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

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

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

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

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

		int l, r;
		foreach (i; 0..n)
		{
			if (a[i] == 1)
			{
				l = i;
				break;
			}
		}
		foreach_reverse (i; 0..n)
		{
			if (a[i] == 1)
			{
				r = i;
				break;
			}
		}
		foreach (i; l..r)
		{
			if (a[i] == 0)
				++ans[ti];
		}
	}

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

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

void play(){
    int n;
    n = rd!int;
    ll[] arr = rdarr;
    int ix = -1, rix = -1;
    foreach(i; 0..n){
        if(arr[i] == 1){ ix = i; break; }
    }
    foreach_reverse(i; 0..n){
        if(arr[i] == 1){ rix = i; break; }
    }
    if(ix == -1){
        writeln(0);
        return;
    }
    int cnt = 0;
    foreach(i; ix..rix+1){
        cnt += (arr[i] == 0);
    }
    writeln(cnt);
}

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

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
void show(A...)(A a) { debug{ a.each!(w => write(w, "| ")); writeln; } }
alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
T max(T = long)(T a, T b){ return (a > b) ? a : b; }
T min(T = long)(T a, T b){ return (a < b) ? a : b; }

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		while (!a.front)
		{
			a.popFront ();
		}
		while (!a.back)
		{
			a.popBack ();
		}
		writeln (a.length - a.sum);
	}
}


module main;

import std.stdio, std.string;

void solve(int[] w, int[] h)
{
    int maxs = 0, cnt = 0, smaxs = 0;
    long sum = 0;
    foreach (i; 0 .. w.length)
    {
	if (h[i] > maxs)
	{
	    if (maxs != 0)
	    {
		smaxs = maxs;
	    }
	    maxs = h[i];
	    cnt = 1;
	}
	else if (h[i] == maxs)
	{
	    smaxs = h[i];
	    ++ cnt;
	}
	else if (h[i] > smaxs)
	{
	    smaxs = h[i];
	}
	sum += w[i];
    }
    foreach (i; 0 .. w.length)
    {
	if (h[i] == maxs)
	{
	    if (cnt == 1)
	    {
		writef("%d ", (sum - w[i]) * smaxs);
	    }
	    else
	    {
		writef("%d ", (sum - w[i]) * maxs);
	    }
	}
	else
	{
	    writef("%d ", (sum - w[i]) * maxs);
	}
    }
    writeln();
}

void main(string[] args)
{
    int n;
    while (scanf("%d", &n) == 1)
    {
	auto w = new int[n];
	auto h = new int[n];
	foreach (i; 0 .. n)
	{
	    scanf("%d%d", &w[i], &h[i]);
	}
	solve(w, h);
    }
}

import std.stdio;
import std.algorithm;

void main() {

	int n;
	ubyte w;
	ushort h;

	scanf("%d", &n);

	int[] W;
	ushort[] H;
	foreach (i; 0 .. n) {
		readf(" %s %s", &w, &h);
		W ~= w, H ~= h;
	}

	ushort[] tmpH = H.dup;
	sort(tmpH);
	ushort max1 = tmpH[$ - 1], max2 = tmpH[$ - 2];

	int sum = W.reduce!"a + b";

	foreach (i, elem; W)
		write((H[i] != max1) ? ((sum - elem) * max1) : ((sum - elem) * max2), ' ');

	writeln;
}

import std.stdio;

int n;
short[] a;

ulong sumW() {
	ulong sum;
	for (size_t i = 0; i < 2 * n; i += 2)
			sum += a[i];
	return sum;
}

size_t j, k, t;

short maxH() {
	short max;
	for (size_t i = 1; i < 2 * n; i += 2)
			if ((a[i] > max) && (i != j)) {
				max = a[i];
				k = i;
			}

	if (t < 1)
		j = k;

	++t;

	return max;
}

void main() {

	scanf("%d", &n);

	short w, h;
	foreach (i; 0 .. n) {
		scanf("%hd%hd", &w, &h);
		a ~= w,	a ~= h;
	}

	ulong sum = sumW();
	short max1 = maxH();
	short max2 = maxH();

	for (size_t i = 0; i < 2 * n; i += 2)
		if (i != j - 1)
			write((sum - a[i]) * max1, ' ');
		else
			write((sum - a[i]) * max2, ' ');

	putchar('\n');
}


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

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

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

    auto used = new bool[N];

    int s = 0;
    int[] X;
    for (int i = 0; i < 32; i++) {
        int m = -1;
        int x = 0;
        for (int j = 0; j < N; j++) {
            if (used[j]) continue;
            if (x < Y[j]) {
                x = Y[j];
                m = j;
            }
        }
        if (m < 0) continue;
        used[m] = true;
        X ~= A[m];
        s |= A[m];
        foreach (ref a; Y) {
            a = a & ~s;
        }
    }
    for (int i = 0; i < N; i++) {
        if (used[i]) continue;
        X ~= A[i];
    }
    writefln("%(%s %)", X);
}

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

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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    long n;
    readf!" %d "(n);
    auto a = readln.splitter.map!(to!int).array;
    int mask = 0;
    size_t i = 0;
    while (i < a.length) {
      a[i .. $].sort!((x, y) => (y & ~mask) < (x & ~mask));
      if ((a[i] & ~mask) == 0)
        break;
      mask |= a[i];
      i++;
    }
    writefln("%(%s %)", a);
  }
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
multitest_loop:
	foreach (test; 0..tests)
	{
		int n, k, lim;
		readf !(" %s %s %s") (n, k, lim);
		readln;
		auto d = readln.splitter.map !(to !(int)).array;
		d[] = lim - d[];
		if (d.any !(q{a < 0}))
		{
			writeln ("No");
			continue multitest_loop;
		}
		int cur = -1;
		foreach (i; 0..n)
		{
			cur += 1;
			if (d[i] >= k)
			{
				cur = -1;
			}
			else if (cur < k)
			{
				cur = max (cur, k - d[i]);
			}
			else if (d[i] < k && cur > k + d[i])
			{
				writeln ("No");
				continue multitest_loop;
			}
		}
		writeln ("Yes");
	}
}

import std.stdio;

class Input
{
static:
  import std.container: DList, make;
  DList!string words;
  T next(alias T)()
  {
    import std.conv: to;
    import std.string: split;
    while (words.empty)
      {
        string line = stdin.readln;
        foreach(word; line.split)
          words.insertFront(word);
      }
    string nextWord = words.back;
    words.removeBack;
    return to!T(nextWord);
  }
  void read(Args...)(ref Args args)
  {
    static foreach(i, arg; args)
      arg = next!(Args[i])();
  }
}

struct Interval(string type)
{
  long lowerBound, higherBound;
  bool empty()
  {
    static if (type == "[]")
      return !(lowerBound <= higherBound);
    else
      static assert(false);
  }
}

Interval!type intersect(string type)(Interval!type a, Interval!type b)
{
  import std.algorithm: min, max;
  return Interval!type(max(a.lowerBound, b.lowerBound),
                       min(a.higherBound, b.higherBound));
}

auto intersect(IntervalRange1, IntervalRange2)(IntervalRange1 a, IntervalRange2 b)
  if (isInputRange!IntervalRange1 && isInputRange!IntervalRange2)
{
  import std.algorithm.setops: cartesianProduct;
  import std.algorithm: map, filter;

  return cartesianProduct(a.filter!(i=>!i.empty), b.filter!(i=>!i.empty))
    .map!(t => intersect(t[0], t[1]))
    .filter!(i => !i.empty)();
}

import std.range.primitives: isInputRange;
auto simplifyIntervals(IntervalRange)(IntervalRange range)
  if (isInputRange!IntervalRange)
    {
      struct Event
      {
        long position;
        int type;
      }
      auto less = (Event e1, Event e2)
        {
         if (e1.position < e2.position)
           return true;
         if (e1.position > e2.position)
           return false;
         return e1.type > e2.type;
        };
      import std.algorithm: sort;
      import std.array: appender;

      long[long] events;
      foreach(interval; range)
        {
          events[interval.lowerBound]++;
          events[interval.higherBound + 1]--;
        }
      long start = int.min;
      long cnt = 0;
      auto result = appender!(Interval!"[]"[])();
      result.reserve(range.length);
      foreach(position; sort(events.keys()))
        {
          auto delta = events[position];
          import std.conv;
          assert(cnt >= 0, text("Failed with range ", range, " with events ", events));
          if (cnt == 0)
            {
              cnt += delta;
              start = position;
            }
          else
            {
              cnt += delta;
              if (cnt == 0)
                result.put(Interval!"[]"(start, position - 1));
            }
        }
      return result[];
    }
int main()
{
  long t;
  Input.read(t);
 testCase:while(t--)
    {
      import std.algorithm: min;
      long n, k, l;
      Input.read(n, k, l);
      long mod = 2 * k;
      auto d = new long[cast(size_t)n];
      foreach(ref di; d)
        Input.read(di);
      auto sealimit = new long[cast(size_t)n];
      foreach(i, di; d)
        {
          long maxsea = l - di;
          if (maxsea < 0)
            {
              writeln("No");
              continue testCase;
            }
          if (maxsea < k)
            sealimit[i] = maxsea;
          else
            sealimit[i] = -1;
        }

      Interval!"[]"[] activeIntervals = [Interval!"[]"(0, 2 * k - 1)];
      foreach(i, limit; sealimit)
        {
          import std.array: appender;
          auto newActive = appender!(Interval!"[]"[])();
          foreach(ref interval; activeIntervals) with(interval)
            {
              assert(!interval.empty);
              lowerBound++;
              lowerBound %= 2 * k;
              higherBound++;
              higherBound %= 2 * k;
              if (lowerBound > higherBound)
                {
                  newActive.put(Interval!"[]"(lowerBound, 2 * k - 1));
                  newActive.put(Interval!"[]"(0, higherBound));
                }
              else
                {
                  newActive.put(interval);
                }
            }
          activeIntervals = simplifyIntervals(newActive[]);
          if (limit == -1)
            {
              activeIntervals = [Interval!"[]"(0, 2 * k - 1)];
              continue;
            }
          import std.array: array;
          activeIntervals = intersect([Interval!"[]"(0, limit), Interval!"[]"(2 * k - limit, 2 * k - 1)], activeIntervals).array;
          if (activeIntervals.length == 0)
            {
              writeln("No");
              continue testCase;
            }
        }
      long totalLength = 0;
      import std.algorithm: max;
      foreach(interval; activeIntervals)
        totalLength += max(0, interval.higherBound - interval.lowerBound + 1);
      if (totalLength > 0)
        writeln("Yes");
      else
        writeln("No");
    }
  return 0;
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
multitest_loop:
	foreach (test; 0..tests)
	{
		auto x = readln.splitter.map !(to !(int)).array;
		foreach (i; x)
		{
			foreach (j; x)
			{
				foreach (k; x)
				{
					if (max (i, j) == x[0] &&
					    max (i, k) == x[1] &&
					    max (j, k) == x[2])
					{
						writeln ("YES");
						writeln (i, " ", j, " ", k);
						continue multitest_loop;
					}
				}
			}
		}
		writeln ("NO");
	}
}

import std.stdio;
import std.algorithm : max, min;

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

  foreach (i; 0..t) {
    long x, y, z;
    readf!"%d %d %d\n"(x, y, z);

    // trivial case
    if (x == y && y == z) {
      writefln("YES\n%d %d %d", x, x, x);
      continue;
    }

    // otherwise, 2 of 3 have to be max
    auto m = max(x, y, z);
    auto n = min(x, y, z);
    if ((x == m && y == m) || (x == m && z == m) || (y == m && z == m)) {
      writefln("YES\n%d %d %d", n, n, m);
      continue;
    }

    writeln("NO");
  }
}


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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [n + 1];
		auto b = new int [n + 1];
		auto s = new long [n + 1];
		int [] [int] x;
		s[0] = 0;
		foreach (i; 1..n + 1)
		{
			readf (" %s", &a[i]);
			b[i] = max (a[i], 0);
			s[i] = s[i - 1] + b[i];
			x[a[i]] ~= i;
		}

		long res = long.min;
		int bu, bv;
		foreach (i, c; x)
		{
			if (c.length >= 2)
			{
				int u = c[0];
				int v = c[$ - 1];
				long cur = i * 2 + s[v - 1] - s[u];
				if (res < cur)
				{
					res = cur;
					bu = u;
					bv = v;
				}
			}
		}

		int [] ans;
		foreach (i; 1..n + 1)
		{
			if (i < bu || bv < i ||
			    (i != bu && i != bv && a[i] < 0))
			{
				ans ~= i;
			}
		}
		writefln ("%s %s", res, ans.length);
		writefln ("%(%s %)", ans);
	}
}


/+ dub.sdl:
    name "D"
    dependency "dunkelheit" version="1.0.1"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dkh.foundation, dkh.scanner, dkh.numeric.prime;

int main() {
    Scanner sc = new Scanner(stdin);
    scope(exit) assert(!sc.hasNext);

    debug {
        foreach (n; 3..1001) {
            bool ok = false;
            foreach (m; n..(n + n / 4 * 2) + 1) {
                if (isPrime(m)) {
                    ok = true;
                    writefln("find %d : %d", n, m);
                    stdout.flush;
                    break;
                }
            }
            if (!ok) {
                writeln("ERROR ", n);
                return 0;
            }
        }
    }

    int n;
    sc.read(n);
    foreach (m; n..(n + n / 4 * 2) + 1) {
        if (isPrime(m)) {

            int[2][] edges;
            foreach (i; 0..n) {
                edges ~= [i, (i + 1) % n];
            }
            foreach (i; 0..n) {
                if (i % 4 >= 2) continue;
                if (edges.length.to!int >= m) break;
                edges ~= [i, (i + 2) % n];
            }

            writeln(m);
            foreach (d; edges) {
                writeln(d[0] + 1, " ", d[1] + 1);
            }
            return 0;
        }
    }

    return 0;
}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;

// import dkh.container.stackpayload;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    private File f;

    this(File f) {
        this.f = f;
    }
    private char[512] lineBuf;
    private char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    assert(succW());
                    x[i] = line.parse!E;
                }
            } else {
                StackPayload!E buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }

    int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }

    void read(Args...)(auto ref Args args) {
        import std.exception : enforce;
        static if (args.length != 0) {
            enforce(readSingle(args[0]));
            read(args[1..$]);
        }
    }

    bool hasNext() {
        return succ();
    }
}

/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/numeric/prime.d */
// module dkh.numeric.prime;

import std.traits;
// import dkh.int128;

ulong ulongPowMod(U)(ulong x, U n, ulong md)
if (isIntegral!U || is(U == BigInt)) {
    x %= md;
    ulong r = 1;
    while (n) {
        if (n & 1) {
            r = mul128(r, x).mod128(md);
        }
        x = mul128(x, x).mod128(md);
        n >>= 1;
    }
    return r % md;
}

T[] divisorList(T)(T x) {
    import std.algorithm : sort;
    T[] res;
    for (T i = 1; i*i <= x; i++) {
        if (x%i == 0) {
            res ~= i;
            if (i*i != x) res ~= x/i;
        }
    }
    sort(res);
    return res;
}

T[] factorList(T)(T x) {
    T[] res;
    for (T i = 2; i*i <= x; i++) {
        while (x % i == 0) {
            res ~= i;
            x /= i;
        }
    }
    if (x > 1) res ~= x;

    return res;
}

// import dkh.numeric.primitive;

bool isPrime(ulong n) {
//     import dkh.int128;
    if (n <= 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    ulong d = n-1;
    while (d % 2 == 0) d /= 2;
    ulong[] alist = [2,3,5,7,11,13,17,19,23,29,31,37];
    foreach (a; alist) {
        if (n <= a) break;
        ulong y = ulongPowMod(a, d, n);
        ulong t = d;
        while (t != n-1 && y != 1 && y != n-1) {
            y = mul128(y, y).mod128(n);
            t <<= 1;
        }
        if (y != n-1 && t % 2 == 0) {
            return false;
        }
    }
    return true;
}

/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/numeric/primitive.d */
// module dkh.numeric.primitive;

import std.traits, std.bigint;

T lcm(T)(in T a, in T b) {
    import std.numeric : gcd;
    return a / gcd(a,b) * b;
}

Unqual!T pow(T, U)(T x, U n)
if (!isFloatingPoint!T && (isIntegral!U || is(U == BigInt))) {
    return pow(x, n, T(1));
}

Unqual!T pow(T, U, V)(T x, U n, V e)
if ((isIntegral!U || is(U == BigInt)) && is(Unqual!T == Unqual!V)) {
    Unqual!T b = x, v = e;
    Unqual!U m = n;
    while (m) {
        if (m & 1) v *= b;
        b *= b;
        m /= 2;
    }
    return v;
}

T powMod(T, U, V)(T x, U n, V md)
if (isIntegral!U || is(U == BigInt)) {
    T r = T(1);
    Unqual!U m = n;
    while (m) {
        if (m & 1) r = (r*x)%md;
        x = (x*x)%md;
        m >>= 1;
    }
    return r % md;
}

T[3] extGcd(T)(in T a, in T b)
if (!isIntegral!T || isSigned!T)
{
    if (b==0) {
        return [T(1), T(0), a];
    } else {
        auto e = extGcd(b, a%b);
        return [e[1], e[0]-a/b*e[1], e[2]];
    }
}

T invMod(T)(T x, T md) {
    auto r = extGcd!T(x, md);
    assert(r[2] == 1);
    auto z = r[0];
    return (z % md + md) % md;
}

/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;

struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
    import core.exception : RangeError;

    private T* _data;
    private uint len, cap;

    @property bool empty() const { return len == 0; }
    @property size_t length() const { return len; }
    alias opDollar = length;

    inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }

    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        return _data[i];
    }
    ref inout(T) front() inout { return this[0]; }
    ref inout(T) back() inout { return this[$-1]; }

    void reserve(size_t newCap) {
        import core.memory : GC;
        import core.stdc.string : memcpy;
        import std.conv : to;
        if (newCap <= cap) return;
        void* newData = GC.malloc(newCap * T.sizeof);
        cap = newCap.to!uint;
        if (len) memcpy(newData, _data, len * T.sizeof);
        _data = cast(T*)(newData);
    }
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }

    void clear() {
        len = 0;
    }

    void insertBack(T item) {
        import std.algorithm : max;
        if (len == cap) reserve(max(cap * 2, MINCAP));
        _data[len++] = item;
    }
    alias opOpAssign(string op : "~") = insertBack;
    void removeBack() {
        assert(!empty, "StackPayload.removeBack: Stack is empty");
        len--;
    }
}

/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/foundation.d */

// module dkh.foundation;

static if (__VERSION__ <= 2070) {
    /*
    Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
    Copyright: Andrei Alexandrescu 2008-.
    License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
    */
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }

}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/ldc/inline.d */
// module dkh.ldc.inline;

version(LDC) {
    pragma(LDC_inline_ir) R inlineIR(string s, R, P...)(P);
}
/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/int128.d */

// module dkh.int128;

version(LDC) {
//     import dkh.ldc.inline;
}

version(LDC) version(X86_64) {
    version = LDC_IR;
}

ulong[2] mul128(ulong a, ulong b) {
    ulong[2] res;
    version(LDC_IR) {
        ulong upper, lower;
        inlineIR!(`
            %r0 = zext i64 %0 to i128
            %r1 = zext i64 %1 to i128
            %r2 = mul i128 %r1, %r0
            %r3 = trunc i128 %r2 to i64
            %r4 = lshr i128 %r2, 64
            %r5 = trunc i128 %r4 to i64
            store i64 %r3, i64* %2
            store i64 %r5, i64* %3`, void)(a, b, &lower, &upper);
        return [lower, upper];
    } else version(D_InlineAsm_X86_64) {
        ulong upper, lower;
        asm {
            mov RAX, a;
            mul b;
            mov lower, RAX;
            mov upper, RDX;
        }
        return [lower, upper];
    } else {
        ulong B = 2UL^^32;
        ulong[2] a2 = [a % B, a / B];
        ulong[2] b2 = [b % B, b / B];
        ulong[4] c;
        foreach (i; 0..2) {
            foreach (j; 0..2) {
                c[i+j] += a2[i] * b2[j] % B;
                c[i+j+1] += a2[i] * b2[j] / B;
            }
        }
        foreach (i; 0..3) {
            c[i+1] += c[i] / B;
            c[i] %= B;
        }
        return [c[0] + c[1] * B, c[2] + c[3] * B];
    }
}

ulong div128(ulong[2] a, ulong b) {
    version(LDC_IR) {
        return inlineIR!(`
            %r0 = zext i64 %0 to i128
            %r1 = zext i64 %1 to i128
            %r2 = shl i128 %r1, 64
            %r3 = add i128 %r0, %r2
            %r4 = zext i64 %2 to i128
            %r5 = udiv i128 %r3, %r4
            %r6 = trunc i128 %r5 to i64
            ret i64 %r6`,ulong)(a[0], a[1], b);
    } else version(D_InlineAsm_X86_64) {
        ulong upper = a[1], lower = a[0];
        ulong res;
        asm {
            mov RDX, upper;
            mov RAX, lower;
            div b;
            mov res, RAX;
        }
        return res;
    } else {
        if (b == 1) return a[0];
        while (!(b & (1UL << 63))) {
            a[1] <<= 1;
            if (a[0] & (1UL << 63)) a[1] |= 1;
            a[0] <<= 1;
            b <<= 1;
        }
        ulong ans = 0;
        foreach (i; 0..64) {
            bool up = (a[1] & (1UL << 63)) != 0;
            a[1] <<= 1;
            if (a[0] & (1UL << 63)) a[1] |= 1;
            a[0] <<= 1;

            ans <<= 1;
            if (up || b <= a[1]) {
                a[1] -= b;
                ans++;
            }
        }
        return ans;
    }
}

ulong mod128(ulong[2] a, ulong b) {
    version(D_InlineAsm_X86_64) {
        ulong upper = a[1], lower = a[0];
        ulong res;
        asm {
            mov RDX, upper;
            mov RAX, lower;
            div b;
            mov res, RDX;
        }
        return res;
    } else {
        return a[0] - div128(a, b) * b;
    }
}

/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/

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

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

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

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

enum LIM = 10^^5;
bool[] isnp;

void main() {
  isnp = new bool[LIM];
  foreach (p; 2 .. LIM) {
    if (!isnp[p]) {
      for (int n = 2 * p; n < LIM; n += p) {
        isnp[n] = true;
      }
    }
  }

  debug {
    for (int n = 3; n <= 1000; ++n) {
      bool found;
      foreach (p; n .. n + n / 2) {
        if (p >= 2 && !isnp[p]) {
          found = true;
        }
      }
      if (!found) {
        writeln("failed ", n);
      }
    }
  }

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

      int k;
      for (k = 0; k < N / 2; ++k) {
        if (N + k >= 2 && !isnp[N + k]) {
          break;
        }
      }
      debug {
        writeln("N = ", N, ": k = ", k);
      }

      int[] as, bs;
      foreach (i; 0 .. N) {
        as ~= i;
        bs ~= (i + 1) % N;
      }
      foreach (i; 0 .. k) {
        as ~= i;
        bs ~= (i + N / 2) % N;
      }

      writeln(N + k);
      foreach (i; 0 .. N + k) {
        writeln(as[i] + 1, " ", bs[i] + 1);
      }
    }
  } catch (EOFException e) {
  }
}


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;

int ask(int q) {
    writeln("? ", q);
    stdout.flush();
    return readln.chomp.to!int;
}

void answer(int x) {
    writeln("! ", x);
    stdout.flush();
}

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

    if (n % 2 == 1) {
        answer(-1);
        return;
    }

    n /= 2;
    auto stdiff = ask(1) - ask(n+1);

    if (stdiff % 2 == 1) {
        answer(-1);
        return;
    } else if (stdiff == 0) {
        answer(1);
        return;
    }

    auto lo = 2, hi = n;
    while (lo < hi) {
        auto med = (lo + hi) / 2;
        auto d = ask(med) - ask(n+med);
        if (d == 0) {
            answer(med);
            return;
        }

        if (sgn(d) == sgn(stdiff)) lo = med + 1;
        else hi = med - 1;
    }

    if (ask(lo) - ask(lo + n) == 0) {
        answer(lo);
    } else {
        answer(-1);
    }
}

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

void main ()
{
	int n;

	int ask (int pos)
	{
		int x, y;

		writeln ("? ", pos);
		stdout.flush ();
		readf (" %s", &x);

		writeln ("? ", pos + n / 2);
		stdout.flush ();
		readf (" %s", &y);

		return x - y;
	}

	void go (int lo, int hi, int valLo, int valHi)
	{
		int me = (lo + hi) / 2;
		auto d = ask (me);
		if (d == 0)
		{
			writeln ("! ", me);
			stdout.flush ();
		}
		else if (d * 1L * valLo < 0)
		{
			go (lo, me, valLo, d);
		}
		else if (d * 1L * valHi < 0)
		{
			go (me, hi, d, valHi);
		}
		else
		{
			assert (false);
		}
	}

	while (readf (" %s", &n) > 0)
	{
		if (n % 4 == 0)
		{
			auto d = ask (1);
			if (d == 0)
			{
				writeln ("! ", 1);
				stdout.flush ();
			}
			else
			{
				go (1, n / 2 + 1, +d, -d);
			}
		}
		else
		{
			writeln ("! ", -1);
			stdout.flush ();
		}
	}
}

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

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

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

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

int N;
long[] A;

long Ask(int i) {
  debug {
    return A[i];
  } else {
    writefln("? %s", i + 1);
    stdout.flush;
    const res = readLong();
    return res;
  }
}
void Answer(int i) {
  writefln("! %s", i + 1);
  stdout.flush;
  import core.stdc.stdlib;
  exit(0);
}

void main() {
  N = readInt();
  debug {
    A = new long[N];
    foreach (i; 0 .. N) {
      A[i] = readInt();
    }
  }

  if (N % 4 != 0) {
    Answer(-2);
  }

  const a = Ask(0);
  const b = Ask(N / 2);
  if (a == b) {
    Answer(0);
  }
  int lo = 0, hi = N / 2;
  for (; lo + 1 < hi; ) {
    const mid = (lo + hi) / 2;
    const c = Ask(mid);
    const d = Ask(mid + N / 2);
    if (c == d) {
      Answer(mid);
    }
    (((a < b) == (c < d)) ? lo : hi) = mid;
  }
  Answer(hi);
}

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;

int ask(int q) {
    writeln("? ", q);
    stdout.flush();
    return readln.chomp.to!int;
}

void answer(int x) {
    writeln("! ", x);
    stdout.flush();
}

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

    if (n % 2 == 1) {
        answer(-1);
        return;
    }

    n /= 2;
    auto stdiff = ask(1) - ask(n+1);

    if (stdiff % 2 == 1) {
        answer(-1);
        return;
    } else if (stdiff == 0) {
        answer(1);
        return;
    }

    auto lo = 2, hi = n;
    while (lo < hi) {
        auto med = (lo + hi) / 2;
        auto d = ask(med) - ask(n+med);
        if (d == 0) {
            answer(med);
            return;
        }

        if (sgn(d) == sgn(stdiff)) lo = med + 1;
        else hi = med - 1;
    }

    answer(lo);
}

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;

int ask(int q) {
    writeln("? ", q);
    stdout.flush();
    return readln.chomp.to!int;
}

void answer(int x) {
    writeln("! ", x);
    stdout.flush();
}

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

    if (n % 2 == 1) {
        answer(-1);
        return;
    }

    n /= 2;
    auto stdiff = ask(1) - ask(n+1);

    if (stdiff % 2 == 1) {
        answer(-1);
        return;
    } else if (stdiff == 0) {
        answer(1);
        return;
    }

    auto lo = 2, hi = n;
    while (lo < hi) {
        auto med = (lo + hi) / 2;
        auto d = ask(med) - ask(n+med);
        if (d == 0) {
            answer(med);
            return;
        }

        if (sgn(d) == sgn(stdiff)) lo = med + 1;
        else hi = med - 1;
    }
}

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

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

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

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

int N;
long[] A;

long Ask(int i) {
  debug {
    return A[i];
  } else {
    writefln("? %s", i + 1);
    stdout.flush;
    const res = readLong();
    return res;
  }
}
void Answer(int i) {
  writefln("! %s", i + 1);
  stdout.flush;
  import core.stdc.stdlib;
  exit(0);
}

void main() {
  N = readInt();
  debug {
    A = new long[N];
    foreach (i; 0 .. N) {
      A[i] = readInt();
    }
  }

  if (N % 4 != 0) {
    Answer(-2);
  }

  const a = Ask(0);
  const b = Ask(N / 2);
  if (a == b) {
    Answer(0);
  }
  int lo = 0, hi = N / 2;
  for (; lo + 1 < hi; ) {
    const mid = (lo + hi) / 2;
    const c = Ask(mid);
    const d = Ask(mid + N / 2);
    (((a < b) == (c < d)) ? lo : hi) = mid;
  }
  Answer(hi);
}


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.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 = arr.uniq.array;

    debug { arr.writeln; }

    auto dp = new int[][] (arr.length, arr.length);

    int go(int le, int r) {
        if (dp[le][r]) { return dp[le][r]; }

        if (le == r) { return 0; }

        dp[le][r] = 1 + (arr[le] == arr[r] ?
            go(le+1, r-1) : min(go(le+1, r), go(le, r-1)));

        return dp[le][r];
    }

    int ans = go(0, arr.length.to!int - 1);

    ans.writeln;
}

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

alias type = single;
struct TestCase
{
  mixin prettyPrinting;

  int n;
  @Dim("n") int[] c;

  void solve(long tc = -1)
  {
    auto comps = new int[](1);
    comps[0] = c[0];
    foreach(ci; c[1 .. $])
      if (comps[$ - 1] != ci)
        comps ~= ci;
    auto dp = new int[][](comps.length + 1, comps.length + 1);
    foreach(prefix; 0 .. cast(int) comps.length)
      {
        foreach(suffix; 0 .. cast(int) comps.length)
          {
            if (prefix == 0)
              dp[prefix][suffix] = suffix;
            else if (suffix == 0)
              dp[prefix][suffix] = prefix;
            else if (comps[prefix - 1] == comps[$ - suffix])
              dp[prefix][suffix] = 1 + dp[prefix - 1][suffix - 1];
            else
              dp[prefix][suffix] = 1 + min(dp[prefix - 1][suffix], dp[prefix][suffix - 1]);
          }
      }
    iota(0, cast(int)comps.length).map!(i => dp[i][cast(int)comps.length - i - 1]).fold!min.writeln;
  }
}

struct Interval
{
  long l, h;

  bool empty()
  {
    return l > h;
  }
}

Interval intersect(Interval a, Interval b)
{
  return Interval(max(a.l, b.l), min(a.h, b.h));
}

struct If
{
  string condition;
}
enum ignore = If("false");
struct Dim
{
  string dimensions;
  int levels;
  this(string dimensions)
  {
    this.dimensions = dimensions;
    levels = cast(int)dimensions.count(",") + 1;
  }
}

template getArrayLevel(W)
{
  static if (isDynamicArray!W && !is(W == string))
    enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));
  else
    enum getArrayLevel = 0;
}

static foreach(fieldName; 'a' .. cast(char)('z' + 1))
  {
    static if (fieldName != 'o')
      mixin("enum d", fieldName, " = Dim(\"", fieldName, "\");");
  }

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

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

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

DList!string _words;

template removeArray(W, int times)
{
  static if (times == 0)
    alias removeArray = W;
  else static if (times == 1)
    alias removeArray = typeof(function(){W w; return w[0];}());
  else
    {
      static assert(isDynamicArray!W);
      alias removeArray = removeArray!(removeArray!(W, 1), times - 1);
    }
}

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

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

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, If))
              enum condition = getUDAs!(fieldSymbol, If)[0].condition;
            else
              enum condition = "true";

            if (mixin(condition))
              {
                static if (hasUDA!(fieldSymbol, Dim))
                  {
                    static assert(isDynamicArray!(typeOfField)
                                  , text(W.stringof, ".", fieldName, " has Dim UDA but isn't a Dynamic Array."));
                    enum uda = getUDAs!(fieldSymbol, Dim)[0];
                    static assert(getArrayLevel!(typeOfField) == uda.levels,
                                  text(W.stringof, ".", fieldName, " has a Dim UDA with different number of dimensions than it's type."));
                    mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});
                  }
                else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
                  {
                    pragma(msg, "Warning: You probably want to add dimension to input ", W.stringof, ".", fieldName);
                  }
                read(mixin(fieldName));
              }
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

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

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

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

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

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

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

    }
}

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

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

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

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

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

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

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

void main()
{
  type;
}


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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		int res = 0;
		foreach (i; 0..n)
		{
			if (a[i] != a[0])
			{
				res = max (res, abs (i - 0));
			}
		}
		foreach (i; 0..n)
		{
			if (a[i] != a[n - 1])
			{
				res = max (res, abs (i - (n - 1)));
			}
		}
		writeln (res);
	}
}

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

  int n;
  rd(n);
  auto a = readln.split.to!(int[]);

  if (a[0] != a[$ - 1]) {
    writeln(n - 1);
    return;
  }
  int mx = 1;
  foreach (i; 1 .. n) {
    if (a[0] != a[i]) {
      mx = max(mx, i, n - i - 1);
    }
  }
  writeln(mx);

}

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

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

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

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

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

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

int N;
int[] C;

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

      int l, r;
      for (l = 0; l < N && C[0] == C[l]; ++l) {}
      for (r = N - 1; r >= 0 && C[N - 1] == C[r]; --r) {}
      assert(l < N);
      assert(r >= 0);

      int ans;
      foreach (i; 0 .. N) {
        chmax(ans, abs(i - ((C[0] == C[i]) ? l : 0)));
        chmax(ans, abs(i - ((C[N - 1] == C[i]) ? r : (N - 1))));
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


import std.algorithm;
import std.container;
import std.conv;
import std.exception;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

class UnionFind {
    import std.range;
    import std.algorithm;

    private size_t[] par, rank;

    ///
    this(size_t n)
    {
        rank.length = n;
        rank[] = 1;
        par = iota(0,n).array;
    }

    ///
    size_t find(size_t a) nothrow pure @nogc @safe
    {
        if (par[a] == a) return a;
        else return par[a] = find(par[a]);
    }

    ///
    void unite(size_t a, size_t b) nothrow pure @nogc @safe
    {
        a = find(a), b = find(b);

        if (a == b) return;

        if (rank[a] < rank[b]) {
            par[a] = b;
        } else {
            par[b] = a;
            if (rank[a] == rank[b]) {
                rank[a]++;
            }
        }
    }

    ///
    bool same(size_t a, size_t b) nothrow pure @nogc @safe
    {
        return find(a) == find(b);
    }
}

alias Edge = Tuple!(long,int,int);

void main()
{
    int n = readln.strip.to!int;

    long[] x,y;
    x.length = y.length = n+1;

    foreach (i; 1 .. n+1) {
        auto xy = readln.strip.split.map!(to!long);
        x[i] = xy[0], y[i] = xy[1];
    }

    long[] c = [0L] ~ readln.strip.split.map!(to!long).array;
    long[] k = [0L] ~ readln.strip.split.map!(to!long).array;

    Edge[] edges;

    foreach (i; 1 .. n+1) {
        edges ~= tuple(c[i], 0, i);
    }

    foreach (i; 1 .. n+1) {
        foreach (j; i+1 .. n+1) {
            edges ~= tuple((k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j])), i, j);
        }
    }

    edges.sort();

    auto uf = new UnionFind(n+1);

    long total = 0;
    int[] es;
    Tuple!(int,int)[] cs;

    foreach (e; edges) {
        if (uf.same(e[1], e[2])) continue;

        total += e[0];
        uf.unite(e[1], e[2]);

        if (e[1] == 0)
            es ~= e[2];
        else
            cs ~= tuple(e[1], e[2]);
    }

    writeln(total);

    writeln(es.length);
    foreach (e; es) {
        writef!"%s "(e);
    }
    writeln();

    writeln(cs.length);
    foreach (v; cs) {
        writefln!"%s %s"(v[0],v[1]);
    }
}

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

class UnionFind {
    import std.range;
    import std.algorithm;

    private size_t[] par, rank;

    ///
    this(size_t n)
    {
        rank.length = n;
        rank[] = 1;
        par = iota(0,n).array;
    }

    ///
    size_t find(size_t a) nothrow pure @nogc @safe
    {
        if (par[a] == a) return a;
        else return par[a] = find(par[a]);
    }

    ///
    void unite(size_t a, size_t b) nothrow pure @nogc @safe
    {
        a = find(a), b = find(b);

        if (a == b) return;

        if (rank[a] < rank[b]) {
            par[a] = b;
        } else {
            par[b] = a;
            if (rank[a] == rank[b]) {
                rank[a]++;
            }
        }
    }

    ///
    bool same(size_t a, size_t b) nothrow pure @nogc @safe
    {
        return find(a) == find(b);
    }
}

alias Edge = Tuple!(long,int,int);

void main()
{
    int n = readln.strip.to!int;

    long[] x,y,c,k;
    x.length = y.length = c.length = k.length = n+1;

    foreach (i; 1 .. n+1) {
        readf!" %s %s "(x[i],y[i]);
    }

    foreach (i; 1 .. n+1) {
        readf!" %s "(c[i]);
    }

    foreach (i; 1 .. n+1) {
        readf!" %s "(k[i]);
    }

    Edge[] edges;

    foreach (i; 1 .. n+1) {
        edges ~= tuple(c[i], 0, i);
    }

    foreach (i; 1 .. n+1) {
        foreach (j; i+1 .. n+1) {
            edges ~= tuple((k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j])), i, j);
        }
    }

    edges.sort();

    auto uf = new UnionFind(n+1);

    long total = 0;
    int[] es;
    Tuple!(int,int)[] cs;

    foreach (e; edges) {
        if (uf.same(e[1], e[2])) continue;

        total += e[0];
        uf.unite(e[1], e[2]);

        if (e[1] == 0)
            es ~= e[2];
        else
            cs ~= tuple(e[1], e[2]);
    }

    writeln(total);

    writeln(es.length);
    foreach (e; es) {
        writef!"%s "(e);
    }
    writeln();

    writeln(cs.length);
    foreach (v; cs) {
        writefln!"%s %s"(v[0],v[1]);
    }
}

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

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

  template next(T) if (isSigned!T) {
    final T next ()  {
      T res;
      ubyte b = skipByte (45);
      if (b == 45) {
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    final T next () {
      T res = skipByte (48) - 48;
      while (true) {
        ubyte b = nextByte ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  final T[] nextA(T) (int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

class Heap(T) {
  private:
    T [] a;
    int [] h;
    int [] g;
    int n;
    int size;
  final void heapify_front (int k) {
    immutable he = h[k];
    int i = k;
    int j = i << 1;
    while (j <= size) {
      if (j < size && a[h[j+1]] < a[h[j]]) {
        j++;
      }
      if (a[h[j]] >= a[he]) {
        break;
      }
      h[i] = h[j];
      g[h[i]] = i;
      i = j;
      j = i << 1;
    }
    if (i != k) {
      h[i] = he;
      g[he] = i;
    }
  }
  final void heapify_back (int k) {
    immutable he = h[k];
    int i = k;
    while (i > 1) {
      int j = i >> 1;
      if (a[he] >= a[h[j]]) {
        break;
      }
      h[i] = h[j];
      g[h[i]] = i;
      i = j;
    }
    if (i != k) {
      h[i] = he;
      g[he] = i;
    }
  }
  final void insert (int i) {
    h[++size] = i;
    g[i] = size;
    heapify_back (size);
  }
  public:
  final void update (int k, T value) in {
    assert (k >= 0 && k < n);
  } body {
    immutable pos = g[k];
    if (pos < 0) {
      a[k] = value;
      insert (k);
    } else if (value < a[k]) {
      a[k] = value;
      heapify_back (pos);
    } else if (value > a[k]) {
      a[k] = value;
      heapify_front (pos);
    }
  }
  final int extract_min () {
    assert (size > 0);
    immutable he = h[1];
    g[he] = -1;
    h[1] = h[size--];
    g[h[1]] = 1;
    if (size) {
      heapify_front (1);
    }
    return he;
  }

  inout(T) opIndex (size_t index) inout {
    return a[index];
  }

  @property
  bool empty () const { return size == 0; }

  this (int n_, T default_value) {
    n = n_;
    size = 0;
    a = new T[n];
    a[] = default_value;
    h = new int[n+1];
    g = new int[n];
    g[] = -1;
  }
}

void main() {
  auto r = new InputReader;
  immutable m = r.next!uint;
  immutable n = m + 1;
  auto x = new int[n];
  auto y = new int[n];
  foreach (i; 1 .. n) {
    x[i] = r.next!uint;
    y[i] = r.next!uint;
  }
  auto c = new int[n];
  foreach (i; 1 .. n) {
    c[i] = r.next!uint;
  }
  auto kt = new int[n];
  foreach (i; 1 .. n) {
    kt[i] = r.next!uint;
  }
  auto h = new Heap!long (n, long.max);
  h.update (0, 0);
  auto p = new int[n];
  auto b = new bool[n];
  p[] = -1;
  while (!h.empty) {
    immutable i = h.extract_min ();
    b[i] = true;
    debug stderr.writefln ("i: %d, h[i]: %d", i+1, h[i]);
    if (i == 0) {
      foreach (j; 1 .. n) {
        assert (!b[j]);
        immutable w = c[j];
        if (w < h[j]) {
          h.update (j, w);
          p[j] = i;
        }
      }
    } else {
      immutable xi = x[i], yi = y[i], ki = kt[i];
      foreach (j; 1 .. n) {
        if (b[j]) {
          continue;
        }
        long w = abs (xi - x[j]) + abs (yi - y[j]);
        w *= ki + kt[j];
        if (w < h[j]) {
          h.update (j, w);
          p[j] = i;
        }
      }
    }
  }
  iota (0, n).map! (i => h[i]).sum.writeln;
  int[] u;
  Tuple!(int, int)[] d;
  foreach (i; 1 .. n) {
    if (p[i] == 0) {
      u ~= i;
    } else {
      d ~= tuple (i.to!int, p[i]);
    }
  }
  writeln (u.length);
  writefln ("%(%s %)", u);
  writeln (d.length);
  foreach (q; d) {
    if (q[0] > q[1]) swap (q[0], q[1]);
    writeln (q[0], ' ', q[1]);
  }

}

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

class UnionFind {
    import std.range;
    import std.algorithm;

    private size_t[] par, rank;

    ///
    this(size_t n)
    {
        rank.length = n;
        rank[] = 1;
        par = iota(0,n).array;
    }

    ///
    size_t find(size_t a) nothrow pure @nogc @safe
    {
        if (par[a] == a) return a;
        else return par[a] = find(par[a]);
    }

    ///
    void unite(size_t a, size_t b) nothrow pure @nogc @safe
    {
        a = find(a), b = find(b);

        if (a == b) return;

        if (rank[a] < rank[b]) {
            par[a] = b;
        } else {
            par[b] = a;
            if (rank[a] == rank[b]) {
                rank[a]++;
            }
        }
    }

    ///
    bool same(size_t a, size_t b) nothrow pure @nogc @safe
    {
        return find(a) == find(b);
    }
}

alias Edge = Tuple!(long,int,int);

void main()
{
    int n = readln.strip.to!int;

    long[] x,y,c,k;
    x.length = y.length = c.length = k.length = n+1;

    foreach (i; 1 .. n+1) {
        readf!" %s %s "(x[i],y[i]);
    }

    foreach (i; 1 .. n+1) {
        readf!" %s "(c[i]);
    }

    foreach (i; 1 .. n+1) {
        readf!" %s "(k[i]);
    }

    Edge[] edges;
    edges.reserve(n*n+n);

    foreach (i; 1 .. n+1) {
        edges ~= tuple(c[i], 0, i);
    }

    foreach (i; 1 .. n+1) {
        foreach (j; i+1 .. n+1) {
            edges ~= tuple((k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j])), i, j);
        }
    }

    edges.sort();

    auto uf = new UnionFind(n+1);

    long total = 0;
    int[] es;
    Tuple!(int,int)[] cs;
    es.reserve(n);
    cs.reserve(n);

    foreach (e; edges) {
        if (uf.same(e[1], e[2])) continue;

        total += e[0];
        uf.unite(e[1], e[2]);

        if (e[1] == 0)
            es ~= e[2];
        else
            cs ~= tuple(e[1], e[2]);
    }

    writeln(total);

    writeln(es.length);
    foreach (e; es) {
        writef!"%s "(e);
    }
    writeln();

    writeln(cs.length);
    foreach (v; cs) {
        writefln!"%s %s"(v[0],v[1]);
    }
}

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

class UnionFind {
    import std.range;
    import std.algorithm;

    private size_t[] par, rank;

    ///
    this(size_t n)
    {
        rank.length = n;
        rank[] = 1;
        par = iota(0,n).array;
    }

    ///
    size_t find(size_t a) nothrow pure @nogc @safe
    {
        if (par[a] == a) return a;
        else return par[a] = find(par[a]);
    }

    ///
    void unite(size_t a, size_t b) nothrow pure @nogc @safe
    {
        a = find(a), b = find(b);

        if (a == b) return;

        if (rank[a] < rank[b]) {
            par[a] = b;
        } else {
            par[b] = a;
            if (rank[a] == rank[b]) {
                rank[a]++;
            }
        }
    }

    ///
    bool same(size_t a, size_t b) nothrow pure @nogc @safe
    {
        return find(a) == find(b);
    }
}

alias Edge = Tuple!(long,int,int);

void main()
{
    int n = readln.strip.to!int;

    long[] x,y,c,k;
    x.length = y.length = c.length = k.length = n+1;

    foreach (i; 1 .. n+1) {
        readf!" %s %s "(x[i],y[i]);
    }

    foreach (i; 1 .. n+1) {
        readf!" %s "(c[i]);
    }

    foreach (i; 1 .. n+1) {
        readf!" %s "(k[i]);
    }

    Array!Edge edges;

    foreach (i; 1 .. n+1) {
        edges ~= tuple(c[i], 0, i);
    }

    foreach (i; 1 .. n+1) {
        foreach (j; i+1 .. n+1) {
            edges ~= tuple((k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j])), i, j);
        }
    }

    edges[].sort();

    auto uf = new UnionFind(n+1);

    long total = 0;
    Array!int es;
    Array!(Tuple!(int,int)) cs;

    foreach (e; edges) {
        if (uf.same(e[1], e[2])) continue;

        total += e[0];
        uf.unite(e[1], e[2]);

        if (e[1] == 0)
            es ~= e[2];
        else
            cs ~= tuple(e[1], e[2]);
    }

    writeln(total);

    writeln(es.length);
    foreach (e; es) {
        writef!"%s "(e);
    }
    writeln();

    writeln(cs.length);
    foreach (v; cs) {
        writefln!"%s %s"(v[0],v[1]);
    }
}

import std.algorithm;
import std.container;
import std.conv;
import std.exception;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
    int n = readln.strip.to!int;

    long[] x,y;
    x.length = y.length = n+1;

    foreach (i; 0 .. n) {
        readf!" %s %s "(x[i],y[i]);
    }

    long[] c = readln.strip.split.map!(to!long).array;
    long[] k = readln.strip.split.map!(to!long).array;

    int[] b = new int[n];
    b[] = -1;

    long total;
    int[] es;
    Tuple!(int,int)[] cs;

    foreach (_; 0 .. n) {
        auto i = minIndex(c).to!int;
        total += c[i];

        if (b[i] >= 0) {
            cs ~= tuple(i+1,b[i]+1);
        } else {
            es ~= i+1;
        }

        foreach (j; 0 .. n) {
            if (c[j] != long.max) {
                long v = (k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j]));
                if (v < c[j]) {
                    c[j] = v;
                    b[j] = i;
                }
            }
        }
        c[i] = long.max;
    }

    writeln(total);

    writeln(es.length);
    writefln!"%(%s %)"(es);

    writeln(cs.length);
    foreach (p; cs)
        writefln!"%s %s"(p[0],p[1]);
}

import std.algorithm;
import std.container;
import std.conv;
import std.exception;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

alias Edge = Tuple!(long,int,int);

void main()
{
    int n = readln.strip.to!int;

    long[] x,y;
    x.length = y.length = n+1;

    foreach (i; 1 .. n+1) {
        auto xy = readln.strip.split.map!(to!long);
        x[i] = xy[0], y[i] = xy[1];
    }

    long[] c = [0L] ~ readln.strip.split.map!(to!long).array;
    long[] k = [0L] ~ readln.strip.split.map!(to!long).array;

    Edge[] edges;

    alias pair = Tuple!(long,int);

    long total = 0;
    int[] es;
    Tuple!(int,int)[] cs;

    bool[] use = new bool[n+1];
    auto q = BinaryHeap!(pair[],"b < a")([]);
    foreach (i, v; c) {
        q.insert(tuple(v,to!int(i)));
    }

    use[0] = true;
    int[] b = new int[n+1];
    b[] = -1;

    int v = 0;
    while (!q.empty && v < n) {
        auto p = q.front; q.removeFront();

        int i = p[1];
        if (c[i] < p[0] || use[i]) continue;

        use[i] = true;

        if (b[i] >= 0)
            cs ~= tuple(i,b[i]);
        else
            es ~= i;

        v++;

        total += p[0];

        foreach (j; 1 .. n+1) {
            long newCost = (k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j]));
            if (c[j] > newCost) {
                c[j] = newCost;
                q.insert(tuple(newCost, j));
                b[j] = i;
            }
        }
    }

    writeln(total);

    writeln(es.length);
    writefln!"%(%s %)"(es);

    writeln(cs.length);
    foreach (p; cs) {
        writefln!"%s %s"(p[0],p[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 n, a, b, da, db;
		readf !(" %s %s %s %s %s") (n, a, b, da, db);
		a -= 1;
		b -= 1;
		auto adj = new int [] [n];
		foreach (i; 0..n - 1)
		{
			int u, v;
			readf !(" %s %s") (u, v);
			u -= 1;
			v -= 1;
			adj[u] ~= v;
			adj[v] ~= u;
		}

		auto d = new int [n];

		void recur (int v, int p, int dist)
		{
			d[v] = dist;
			foreach (u; adj[v])
			{
				if (u != p)
				{
					recur (u, v, dist + 1);
				}
			}
		}

		recur (b, -1, 0);
		if (d[a] <= da)
		{
			writeln ("Alice");
			continue;
		}

		auto c = to !(int) (d.length - d.maxPos.length);

		recur (c, -1, 0);
		auto diameter = d.maxElement;
		auto canCatch = (da * 2 >= db);
		auto canCenter = (da * 2 >= diameter);
		writeln ((canCatch || canCenter) ? "Alice" : "Bob");
	}
}

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

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

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

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

int N, A, B, C, D;
int[] U, V;

int[][] G;
int[] dep;

void dfs(int u, int p) {
  dep[u] = (p == -1) ? 0 : (dep[p] + 1);
  foreach (i; G[u]) {
    const v = U[i] ^ V[i] ^ u;
    if (v != p) {
      dfs(v, u);
    }
  }
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        N = readInt();
        A = readInt() - 1;
        B = readInt() - 1;
        C = readInt();
        D = readInt();
        U = new int[N - 1];
        V = new int[N - 1];
        foreach (i; 0 .. N - 1) {
          U[i] = readInt() - 1;
          V[i] = readInt() - 1;
        }

        G = new int[][N];
        foreach (i; 0 .. N - 1) {
          G[U[i]] ~= i;
          G[V[i]] ~= i;
        }

        int ans;

        dep = new int[N];
        dfs(A, -1);
        if (dep[B] <= C) {
          ans = 1;
        } else {
          const r = cast(int)(dep.maxIndex);
          dfs(r, -1);
          const diam = dep.maxElement;
          if (2 * C >= min(D, diam)) {
            ans = 1;
          } else {
            ans = 0;
          }
        }

        writeln(ans ? "Alice" : "Bob");
      }
    }
  } catch (EOFException e) {
  }
}

// Vicfred
// https://codeforces.com/contest/1405/problem/D
// dfs, graph, bfs, tree
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

int n, a, b, da, db;
int[][] tree;

int[] depth;
int diameter;

int dfs(int x, int p) {
    int len = 0;

    foreach(child; tree[x]) {
        if(child != p) {
            depth[child] = depth[x] + 1;
            int cur = 1 + dfs(child, x);
            diameter = max(diameter, cur + len);
            len = max(len, cur);
        }
    }

    return len;
}

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

    while(t--) {
        readf("%s %s %s %s %s", &n, &a, &b, &da, &db);
        readln;

        tree = new int[][](n+1);
        depth = new int[n+1];
        diameter = 0;

        foreach(_; 1..n) {
            int u, v;
            readf("%s %s", &u, &v);
            readln;
            tree[u] ~= v;
            tree[v] ~= u;
        }

        depth[a] = 0;
        dfs(a, -1);

        if(2 * da >= min(diameter, db) || depth[b] <= da)
            "Alice".writeln;
        else
            "Bob".writeln;
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RD!int-1;
		auto b = RD!int-1;
		auto da = RD!int;
		auto db = RD!int;
		auto edges = new int[][](n);
		foreach (i; 0..n-1)
		{
			auto u = RD!int-1;
			auto v = RD!int-1;
			edges[u] ~= v;
			edges[v] ~= u;
		}

		if (db <= da*2)
		{
			ans[ti] = true;
			continue;
		}

		bool dfs1(int pos, int last, int depth)
		{
			if (pos == b) return true;
			if (depth == da) return false;

			foreach (v; edges[pos])
			{
				if (v == last) continue;
				auto res = dfs1(v, pos, depth+1);
				if (res) return true;
			}
			return false;
		}
		auto otk = dfs1(a, -1, 0);
		if (otk)
		{
			ans[ti] = true;
			continue;
		}

		int[] dfs2(int pos, int last, int depth)
		{
			int[] res = [depth, pos];
			foreach (v; edges[pos])
			{
				if (v == last) continue;
				auto r = dfs2(v, pos, depth+1);
				if (r[0] > res[0])
				{
					res = r;
				}
			}
			return res;
		}
		auto r = dfs2(0, -1, 0);
		auto r2 = dfs2(r[1], -1, 0);
		ans[ti] = r2[0] <= da*2;
	}

	foreach (e; ans)
		writeln(e ? "Alice" : "Bob");
	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 a = RDA(-1);

		auto cnt = new long[](n);
		foreach (i; 0..n)
		{
			++cnt[a[i]];
		}

		long x = -1;
		foreach (i; 0..n)
		{
			if (cnt[i] == 1)
			{
				x = i;
				break;
			}
		}

		ans[ti] = -1;
		foreach (i; 0..n)
		{
			if (a[i] == x)
			{
				ans[ti] = i+1;
				break;
			}
		}
	}

	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)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		int [] [int] b;
		foreach (i, c; a)
		{
			b[c] ~= i + 1;
		}
		auto f = b.byKey.filter !(c => b[c].length == 1);
		writeln (f.empty ? -1 : b[f.minElement].front);
	}
}


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

void main ()
{
	int n, m, k;
	while (readf (" %s %s %s", &n, &m, &k) > 0)
	{
		auto a = new int [] [] (n, m);
		foreach (i; 0..n)
		{
			foreach (j; 0..m)
			{
				readf (" %s", &a[i][j]);
			}
		}
		if (n > m)
		{
			auto b = new int [] [] (m, n);
			foreach (i; 0..n)
			{
				foreach (j; 0..m)
				{
					b[j][i] = a[i][j];
				}
			}
			swap (n, m);
			a = b;
		}
		assert (n <= m);

		int [2] [] s = new int [2] [m];
		int res = k + 1;
		int cur = k + 1;

		void recur (int i)
		{
			debug {writeln (i, ' ', cur);}
			if (i >= n)
			{
				res = min (res, cur);
				return;
			}

			// put 0
			cur = 0;
			foreach (j; 0..m)
			{
				s[j][0] += (a[i][j] != 0);
				s[j][1] += (a[i][j] != 1);
				cur += min (s[j][0], s[j][1]);
			}
			if (cur <= k)
			{
				recur (i + 1);
			}
			foreach (j; 0..m)
			{
				s[j][0] -= (a[i][j] != 0);
				s[j][1] -= (a[i][j] != 1);
			}

			// put 1
			cur = 0;
			foreach (j; 0..m)
			{
				s[j][0] += (a[i][j] != 1);
				s[j][1] += (a[i][j] != 0);
				cur += min (s[j][0], s[j][1]);
			}
			if (cur <= k)
			{
				recur (i + 1);
			}
			foreach (j; 0..m)
			{
				s[j][0] -= (a[i][j] != 1);
				s[j][1] -= (a[i][j] != 0);
			}
		}

		recur (0);
		if (res > k)
		{
			res = -1;
		}
		writeln (res);
	}
}

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

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

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

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

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

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

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

		int ans = int.max;

		if (M > K) {
			foreach (sx; 0 .. M) {
				int sum;
				foreach (x; 0 .. M) {
					int cnt;
					foreach (y; 0 .. N) {
						if (A[sx][y] != A[x][y]) {
							++cnt;
						}
					}
					sum += min(cnt, N - cnt);
				}
				chmin(ans, sum);
			}
		}

		if (N > K) {
			foreach (sy; 0 .. N) {
				int sum;
				foreach (y; 0 .. N) {
					int cnt;
					foreach (x; 0 .. M) {
						if (A[x][sy] != A[x][y]) {
							++cnt;
						}
					}
					sum += min(cnt, M - cnt);
				}
				chmin(ans, sum);
			}
		}

		if (M <= K && N <= K) {
			foreach (p; 0 .. 1 << M) foreach (q; 0 .. 1 << N) {
				int cnt;
				foreach (x; 0 .. M) foreach (y; 0 .. N) {
					if (A[x][y] != (((p >> x) & 1) ^ ((q >> y) & 1))) {
						++cnt;
					}
				}
				chmin(ans, cnt);
			}
		}

// writeln("ans = ",ans);
		if (ans > K) {
			writeln(-1);
		} else {
			writeln(ans);
		}

	}
	} catch (EOFException) {}
}

import std.algorithm, std.stdio;

void main ()
{
	int n, m, k;
	while (readf (" %s %s %s", &n, &m, &k) > 0)
	{
		auto a = new int [] [] (min (n, m), max (n, m));
		foreach (i; 0..n)
			foreach (j; 0..m)
				readf (" %s", n > m ? &a[j][i] : &a[i][j]);
		if (n > m)
			swap (n, m);

		auto s = new int [2] [m];
		int res = k + 1;
		int cur;

		void recur (int i)
		{
			if (i >= n)
			{
				res = min (res, cur);
				return;
			}
			foreach (v; 0..2)
			{
				cur = 0;
				foreach (j; 0..m)
				{
					s[j][0] += a[i][j] ^ v;
					s[j][1] += a[i][j] ^ !v;
					cur += min (s[j][0], s[j][1]);
				}
				if (cur <= k)
					recur (i + 1);
				foreach (j; 0..m)
				{
					s[j][0] -= a[i][j] ^ v;
					s[j][1] -= a[i][j] ^ !v;
				}
			}
		}

		recur (0);
		writeln (res > k ? -1 : res);
	}
}


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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto n = RD!int;
	auto k = RD!int;
	auto id = RDA;
	long[] ans;
	bool[long] flag;
	foreach (i; 0..n)
	{
		if (flag.get(id[i], false)) continue;
		ans ~= id[i];
		flag[id[i]] = true;
		if (ans.length > k)
		{
			flag[ans.front] = false;
			ans.popFront;
		}
	}
	ans.reverse;
	writeln(ans.length);
	ans.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.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto n = RD!int;
	auto k = RD!int;
	auto id = RDA;
	long[] ans;
	bool[long] flag;
	foreach (i; 0..n)
	{
		if (flag.get(id[i], false)) continue;
		ans ~= id[i];
		flag[id[i]] = true;
		if (ans.length > k)
		{
			flag[ans.front] = false;
			ans.popFront;
		}
	}
	ans.reverse;
	ans.map!(to!string).join(" ").writeln;
	stdout.flush();
	debug readln();
}