import std.algorithm;
import std.functional;
import std.stdio;

immutable int MAX_N = 31;
immutable int MAX_K = 51;
immutable int INF = int.max / 4;
immutable int NA = -1;

int [] [] [] f;

int mfun (int n, int m, int k)
{
	if (f[n][m][k] == NA)
	{
		f[n][m][k] = fun (n, m, k);
	}
	return f[n][m][k];
}

int fun (int n, int m, int k)
{
	if (k == 0)
	{
		return 0;
	}
	if (n * m == k)
	{
		return 0;
	}
	if (n * m < k)
	{
		return INF;
	}
	int res = INF;
	foreach (p; 0..k + 1)
	{
		foreach (i; 1..n)
		{
			int cost = m * m;
			res = min (res, cost + mfun (i, m, p) +
			    mfun (n - i, m, k - p));
		}
		foreach (j; 1..m)
		{
			int cost = n * n;
			res = min (res, cost + mfun (n, j, p) +
			    mfun (n, m - j, k - p));
		}
	}
	return res;
}

void main ()
{
	f = new int [] [] [] (MAX_N, MAX_N, MAX_K);
	foreach (ref g; f)
	{
		foreach (ref h; g)
		{
			h[] = NA;
		}
	}

	int tests;
	readf (" %s", &tests);
	foreach (test; 0..tests)
	{
		int n, m, k;
		readf (" %s %s %s", &n, &m, &k);
		writeln (mfun (n, m, k));
	}
}

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

int dp[31][31][51];
immutable auto inf = 1 << 29;

int saiki(int n, int m, int k)
{
    int res = dp[n][m][k];
    if (res != -1) return res;
    if (k == 0)
    {
        dp[n][m][k] = 0;
        return 0;
    }
    if (n * m < k)
    {
        dp[n][m][k] = inf;
        return dp[n][m][k];
    }
    if (n * m == k) return 0;
    res = inf;
    foreach (i; 1 .. (n >> 1) + 1)
    {
        foreach (j; 0 .. to!int(fmin(i * m, k)) + 1)
        {
            auto ret = saiki(i, m, j) + saiki(n - i, m, k - j) + m * m;
            res = to!int(fmin(res, ret));
        }
    }
    foreach (i; 1 .. (m >> 1) + 1)
    {
        foreach (j; 0 .. to!int(fmin(i * n, k)) + 1)
        {
            auto ret = saiki(n, i, j) + saiki(n, m - i, k - j) + n * n;
            res = to!int(fmin(res, ret));
        }
    }
    dp[n][m][k] = res;
    return res;
}

void main(string[] args)
{
    int t;
    foreach (i; 0 .. 31)
    {
        foreach (j; 0 .. 31)
        {
            foreach (k; 0 .. 51)
            {
                dp[i][j][k] = -1;
            }
        }
    }
    scanf("%d", &t);
    foreach (i; 0 .. t)
    {
        int n, m, k;
        scanf("%d%d%d", &n, &m, &k);
        auto ans = saiki(n, m, k);
        writeln(ans);
    }
}

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

int dp[31][31][51];
immutable auto inf = 1 << 29;

int saiki(int n, int m, int k)
{
    int res = dp[n][m][k];
    if (res != -1) return res;
    if (k == 0 || n * m == k) return 0;
    if (n * m < k) return inf;
    res = inf;
    foreach (i; 1 .. (n >> 1) + 1)
    {
        foreach (j; 0 .. to!int(fmin(i * m, k)) + 1)
        {
            auto ret = saiki(i, m, j) + saiki(n - i, m, k - j) + m * m;
            res = to!int(fmin(res, ret));
        }
    }
    foreach (i; 1 .. (m >> 1) + 1)
    {
        foreach (j; 0 .. to!int(fmin(i * n, k)) + 1)
        {
            auto ret = saiki(n, i, j) + saiki(n, m - i, k - j) + n * n;
            res = to!int(fmin(res, ret));
        }
    }
    dp[n][m][k] = res;
    return res;
}

void main(string[] args)
{
    int t;
    foreach (i; 0 .. 31)
    {
        foreach (j; 0 .. 31)
        {
            foreach (k; 0 .. 51)
            {
                dp[i][j][k] = -1;
            }
        }
    }
    scanf("%d", &t);
    foreach (i; 0 .. t)
    {
        int n, m, k;
        scanf("%d%d%d", &n, &m, &k);
        auto ans = saiki(n, m, k);
        writeln(ans);
    }
}


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

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

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

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

enum LIM = 4 * 10L^^18;

alias Line = Tuple!(char, "op", long, "a", long, "b");

void main() {
  debug {
    for (long n = 1; n < 10^^6; n += 2) {
      assert(gcd(n, n ^ (n << bsr(n))) == 1);
    }
  }

  try {
    for (; ; ) {
      const N = readLong();
      if (N == 1) {
        writeln(0);
        continue;
      }

      const K = bsr(N);
      const B = N ^ (N << K);

      Line[] ans;
      for (int i = 1; ; ++i) {
        if (N << i > LIM) {
          break;
        }
        ans ~= Line('+', N << (i - 1), N << (i - 1));
      }
      ans ~= Line('^', N, N << K);
      for (int i = 1; ; ++i) {
        if (B << i > LIM) {
          break;
        }
        ans ~= Line('+', B << (i - 1), B << (i - 1));
      }

      int L;
      for (L = 1; 1L << L < N * B; ++L) {}
      foreach (t; [1L << L, 1L << L | 1]) {
        foreach (y; 0 .. N) {
          if ((t - B * y) % N == 0) {
            const x = (t - B * y) / N;
            long sum;
            foreach (e; 0 .. bsr(x) + 1) {
              if ((x >> e) & 1) {
                if (sum > 0) {
                  ans ~= Line('+', sum, N << e);
                }
                sum += N << e;
              }
            }
            foreach (e; 0 .. bsr(y) + 1) {
              if ((y >> e) & 1) {
                if (sum > 0) {
                  ans ~= Line('+', sum, B << e);
                }
                sum += B << e;
              }
            }
            assert(sum == t);
            break;
          }
        }
      }
      ans ~= Line('^', 1L << L, 1L << L | 1);

      writeln(ans.length);
      foreach (ref line; ans) {
        writefln("%s %s %s", line.a, line.op, line.b);
      }
    }
  } catch (EOFException e) {
  }
}

import core.bitop;
import std.algorithm;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;

auto gcdExt (long a, long b, ref long x, ref long y)
out (res)
{
	assert (a * x + b * y == res);
}
body
{
	if (a == 0)
	{
		x = 0;
		y = 1;
		return b;
	}
	auto res = gcdExt (b % a, a, y, x);
	x -= (b / a) * y;
	return res;
}

void main ()
{
	long n;
	while (readf !(" %s") (n) > 0)
	{
		string [] answer;
		answer ~= format !("%s ^ %s") (n, n); // zero

		void getMult (long v, long m)
		{
			if (m > 1)
			{
				answer ~= format !("%s + %s") (v, v);
				getMult (v * 2, m / 2);
				if (m & 1)
				{
					answer ~= format !("%s + %s")
					    ((v * 2) * (m / 2), v);
				}
			}
		}

		while (true)
		{
			auto a = uniform (1L, 11L);
//			auto b = uniform (1L, 1100L);
			auto b = n;
			auto na = n * a;
			auto nb = n * b;
			auto nc = na ^ nb;
			long x, y;
			if (gcdExt (na, nc, x, y) != 1L)
			{
				continue;
			}
			x = abs (x);
			y = abs (y);
			if ((na * x) / x != na || (nc * y) / y != nc)
			{
				continue;
			}
			if (((na * x) ^ (nc * y)) != 1L)
			{
				continue;
			}
			getMult (n, a);
			getMult (n, b);
			answer ~= format !("%s ^ %s") (na, nb);
			getMult (na, x);
			getMult (nc, y);
			answer ~= format !("%s ^ %s") (na * x, nc * y);
			break;
		}

		writeln (answer.length);
		foreach (ref line; answer)
		{
			writeln (line);
		}
	}
}

import core.bitop;
import std.algorithm;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;

auto gcdExt (long a, long b, ref long x, ref long y)
out (res)
{
	assert (a * x + b * y == res);
}
body
{
	if (a == 0)
	{
		x = 0;
		y = 1;
		return b;
	}
	auto res = gcdExt (b % a, a, y, x);
	x -= (b / a) * y;
	return res;
}

void main ()
{
	long n;
	while (readf !(" %s") (n) > 0)
	{
		string [] answer;
		answer ~= format !("%s ^ %s") (n, n); // zero

		void getMult (long v, long m)
		{
			if (m > 1)
			{
				answer ~= format !("%s + %s") (v, v);
				getMult (v * 2, m / 2);
				if (m & 1)
				{
					answer ~= format !("%s + %s")
					    ((v * 2) * (m / 2), v);
				}
			}
		}

		while (true)
		{
			auto a = uniform (1L, 1100L);
//			auto b = uniform (1L, 1100L);
			auto b = n;
			auto na = n * a;
			auto nb = n * b;
			auto nc = na ^ nb;
			long x, y;
			if (gcdExt (na, nc, x, y) != 1L)
			{
				continue;
			}
			x = abs (x);
			y = abs (y);
			if ((na * x) / x != na || (nc * y) / y != nc)
			{
				continue;
			}
			if (((na * x) ^ (nc * y)) != 1L)
			{
				continue;
			}
			getMult (n, a);
			getMult (n, b);
			answer ~= format !("%s ^ %s") (na, nb);
			getMult (na, x);
			getMult (nc, y);
			answer ~= format !("%s ^ %s") (na * x, nc * y);
			break;
		}

		writeln (answer.length);
		foreach (ref line; answer)
		{
			writeln (line);
		}
	}
}


import std.stdio;

void main ()
{
	readln;
	int n;
	while (readf !(" %s") (n) > 0)
	{
		if (n % 4 == 0)
		{
			writeln ("YES");
			int [] a;
			int [] b;
			int cur = 0;
			for (int i = 0; i < n / 2; i += 2)
			{
				a ~= cur + 1;
				a ~= cur + 5;
				b ~= cur + 2;
				b ~= cur + 4;
				cur += 6;
			}
			writefln !("%(%s %)") (b ~ a);
		}
		else
		{
			writeln ("NO");
		}
	}
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto N = readln.chomp.to!int;
        if ((N/2)%2 == 1) {
            writeln("NO");
            continue;
        }
        int[] as, bs;
        int x;
        foreach (_i; 0..N/2) {
            ++x;
            if (x%2 == 1) {
                bs ~= x++;
                as ~= x++;
            } else {
                as ~= x++;
                bs ~= x++;
            }
        }
        writeln("YES");
        writeln((as ~= bs).to!(string[]).join(" "));
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new long[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		if ((n / 2) % 2) continue;

		foreach (i; 0..n/2)
		{
			ans[ti] ~= (i+1)*2;
		}
		foreach (i; 0..n/2)
		{
			if (i < n/4)
				ans[ti] ~= ans[ti][i]-1;
			else
				ans[ti] ~= ans[ti][i]+1;
		}
	}

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

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto N = readln.chomp.to!int;
        if ((N/2)%2 == 1) {
            writeln("NO");
            continue;
        }
        int[] as, bs;
        int x;
        foreach (_i; 0..N/2) {
            ++x;
            if (x%2 == 1) {
                bs ~= x++;
                as ~= x++;
            } else {
                as ~= x++;
                bs ~= x++;
            }
        }
        writeln((as ~= bs).to!(string[]).join(" "));
    }
}


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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long n;
    readf!" %d "(n);
    auto a = readln.strip.split.map!(to!long).array;
    long sum = a.sum;
    if (sum % n != 0) {
      writeln(-1);
    } else {
      long avg = sum / n;
      writeln(a.count!(x => x > avg));
    }
  }
}

// Vicfred
// https://codeforces.com/contest/1538/problem/B
// basic math, greedy
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

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

    long total = a.sum();

    if(total % n != 0) {
        "-1".writeln;
        continue;
    }

    long candies = total / n;
    long ans = 0L;
    for(int i = 0; i < n; ++i) {
        if(a[i] > candies)
            ans += 1;
    }
    ans.writeln;
}
}

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

void main() {
    foreach(t; 0 .. to!int(readln.strip)) {
        int n = to!int(readln.strip);
        auto ar = readln.strip.split.map!(to!int);
        int sm = sum(ar);
        writeln((sm % n != 0) ? -1 : to!int(ar.count!(a => a > sm/n)));
    }
}


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

void main ()
{
	int n;
	int k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		readln;
		auto x = readln.splitter.map !(to !(int)).array;
		int [int] first;
		int [int] last;
		foreach (i, ref cur; x)
		{
			if (cur !in first)
			{
				first[cur] = i;
			}
			last[cur] = i;
		}

		bool canBe (int a, int b)
		{
			if (a !in first)
			{
				return true;
			}
			int step = first[a];
			if (b !in last)
			{
				return true;
			}
			return step > last[b];
		}

		int res = 0;
		foreach (a; 1..n + 1)
		{
			foreach (b; max (a - 1, 1)..min (a + 1, n) + 1)
			{
				if (canBe (a, b))
				{
					res += 1;
				}
			}
		}
		writeln (res);
	}
}

//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.random;
import std.datetime.systime : Clock;

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

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

void main() {
  auto r = new InputReader;
  immutable n = r.next!int;
  immutable k = r.next!int;
  immutable a = r.nextA!int(k).idup;
  auto c = new int[n + 1];
  auto first = new int[n+1];
  first[] = int.max;
  auto last = new int[n+1];
  last[] = int.min;
  foreach_reverse (i, j; a) {
    first[j] = i.to!int;
    ++c[j];
  }
  foreach (i, j; a) {
    last[j] = i.to!int;
  }
  int res;
  foreach (i; 1 .. n + 1) {
    foreach (delta; -1 .. 2) {
      int j = i + delta;
      if (j >= 1 && j <= n) {
        if (first[i] > last[j]) ++res;
      }
    }
  }
  writeln (res);
}


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

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

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

  auto g = new int[](256); g[] = -1;

  auto calcGroup(int pi)
  {
    if (g[pi] >= 0) return g[pi];
    foreach_reverse (pj; max(0, pi-k+1)..pi) {
      if (g[pj] >= 0) {
        if (pi-g[pj]+1 <= k) {
          g[pj+1..pi+1][] = g[pj];
          return g[pj];
        } else {
          g[pj+1..pi+1][] = pj+1;
          return pj+1;
        }
      }
    }
    auto j = max(0, pi-k+1);
    g[j..pi+1] = j;
    return j;
  }

  foreach (i, pi; p)
    write(calcGroup(pi), " ");
}

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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto A = readln.split.map!(to!int).array;
    int[int] B;
    auto ans = new int[](N);

    foreach (i; 0..N) {
        if (A[i] in B) {
            ans[i] = B[A[i]];
            continue;
        }

        int k = max(0, A[i] - K + 1);
        while (k in B && A[i] - B[k] >= K) ++k;

        if (k in B) {
            ans[i] = B[k];
            foreach (j; k..A[i]+1) B[j] = B[k];
        } else {
            ans[i] = k;
            foreach (j; k..A[i]+1) B[j] = k;
        }
    }

    ans.map!(to!string).join(" ").writeln;
}

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

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

  const int m=256;
  auto root=new int[](m);
  fill(root, -1);
  int[] val;
  foreach(i; 0..n){
    if(root[a[i]]<0){
    //   auto left=max(0, a[i]-k+1);
    //   while(root[left]>=0) left++;
    //   for(int j=left; j<min(m, left+k); j++) root[j]=left;
      auto left=a[i];
      for(int j=left; j>=0; j--){
        if(root[j]>=0){
          left=j; break;
        }
      }
      if(left<a[i]){
        if(a[i]-root[left]+1<=k){
          for(int j=left+1; j<=a[i]; j++){
            root[j]=root[left];
          }
        }else{
          for(int j=max(left+1, a[i]-k+1); j<=a[i]; j++){
            root[j]=max(left+1, a[i]-k+1);
          }
        }
      }else{
        for(int j=max(0, a[i]-k+1); j<=a[i]; j++){
          root[j]=max(0, a[i]-k+1);
        }
      }
    }
    val~=root[a[i]];
  }
  writefln("%(%s %)", val);
}

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

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;

void main()
{
	int n, k;
	readln.chomp.split.tie(n, k);
	int[] p = readln.chomp.split.map!(to!int).array;
	int ite = 0;
	int[] ans;
	RedBlackTree!int tree = new RedBlackTree!int();
	RedBlackTree!int done = new RedBlackTree!int();
	tree.insert(ite);
	done.insert(ite);
	foreach (q; p) {
		int t = tree.lowerBound(q + 1).back;
		debug verbose(q, t, tree);
		if (q - t > k - 1) {
			auto arr = done.lowerBound(t + k);
			if (!arr.empty) {
				t = max(t, arr.back);
			}
			t = max(t + 1, q - k + 1);
			debug verbose("NEW", t);
			tree.insert(t);
		}
		ans ~= t;
		done.insert(q);
	}
	foreach (i, d; ans) {
		if (i) write = " ";
		d.write;
	}
	writeln;
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;

void main()
{
	int n, k;
	readln.chomp.split.tie(n, k);
	int[] p = readln.chomp.split.map!(to!int).array;
	int ite = 0;
	int[] ans;
	RedBlackTree!int tree = new RedBlackTree!int();
	RedBlackTree!int done = new RedBlackTree!int();
	tree.insert(ite);
	done.insert(ite);
	foreach (q; p) {
		int t = tree.lowerBound(q + 1).back;
		debug verbose(q, t, tree);
		if (q - t > k - 1) {
			auto arr = done.upperBound(t);
			if (!arr.empty) {
				t = max(t, arr.front);
			}
			t = max(t + 1, q - k + 1);
			t = min(t, 255);
			debug verbose("NEW", t);
			tree.insert(t);
		}
		ans ~= t;
		done.insert(q);
	}
	foreach (i, d; ans) {
		if (i) write = " ";
		d.write;
	}
	writeln;
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;

void main()
{
	int n, k;
	readln.chomp.split.tie(n, k);
	int[] p = readln.chomp.split.map!(to!int).array;
	int ite = 0;
	int[] ans;
	RedBlackTree!int tree = new RedBlackTree!int();
	RedBlackTree!int done = new RedBlackTree!int();
	tree.insert(ite);
	done.insert(ite);
	foreach (q; p) {
		int t = tree.lowerBound(q + 1).back;
		debug verbose(q, t, tree);
		if (q - t > k - 1) {
			auto arr = done.upperBound(t);
			if (!arr.empty) {
				t = max(t, min(t + k - 1, arr.front));
			}
			t = max(t + 1, q - k + 1);
			debug verbose("NEW", t);
			tree.insert(t);
		}
		ans ~= t;
		done.insert(q);
	}
	foreach (i, d; ans) {
		if (i) write = " ";
		d.write;
	}
	writeln;
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;

void main()
{
	int n, k;
	readln.chomp.split.tie(n, k);
	int[] p = readln.chomp.split.map!(to!int).array;
	int ite = 0;
	int[] ans;
	RedBlackTree!int tree = new RedBlackTree!int();
	RedBlackTree!int done = new RedBlackTree!int();
	tree.insert(ite);
	done.insert(ite);
	foreach (q; p) {
		int t = tree.lowerBound(q + 1).back;
		debug verbose(q, t, tree);
		if (q - t > k - 1) {
			t = max(t + 1, q - k + 1);
			t = max(t, min(done.upperBound(t).front + 1, t + k - 1));
			debug verbose("NEW", t);
			tree.insert(t);
		}
		ans ~= t;
		done.insert(q);
	}
	foreach (i, d; ans) {
		if (i) write = " ";
		d.write;
	}
	writeln;
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;

void main()
{
	int n, k;
	readln.chomp.split.tie(n, k);
	int[] p = readln.chomp.split.map!(to!int).array;
	int ite = 0;
	int[] ans;
	RedBlackTree!int tree = new RedBlackTree!int();
	RedBlackTree!int done = new RedBlackTree!int();
	tree.insert(ite);
	done.insert(ite);
	foreach (q; p) {
		int t = tree.lowerBound(q + 1).back;
		debug verbose(q, t, tree);
		if (q - t > k - 1) {
			auto arr = done.upperBound(t);
			if (!arr.empty) {
				t = max(t, arr.front);
			}
			t = max(t + 1, q - k + 1);
			debug verbose("NEW", t);
			tree.insert(t);
		}
		ans ~= t;
		done.insert(q);
	}
	foreach (i, d; ans) {
		if (i) write = " ";
		d.write;
	}
	writeln;
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;
import std.numeric;

void main()
{
	int n, k;
	readln.chomp.split.tie(n, k);
	int[] p = readln.chomp.split.map!(to!int).array;
	int ite = 0;
	int[] ans;
	RedBlackTree!int tree = new RedBlackTree!int();
	RedBlackTree!int done = new RedBlackTree!int();
	tree.insert(ite);
	done.insert(ite);
	foreach (q; p) {
		int t = tree.lowerBound(q + 1).back;
		debug verbose(q, t, tree);
		if (q - t > k - 1) {
			t = max(t + 1, q - k + 1);
			t = max(t, min(done.upperBound(t).front + 1, t + k));
			debug verbose("NEW", t);
			tree.insert(t);
		}
		ans ~= t;
		done.insert(q);
	}
	foreach (i, d; ans) {
		if (i) write = " ";
		d.write;
	}
	writeln;
}

void tie(R, Args...)(R arr, ref Args args)
		if (isRandomAccessRange!R || isArray!R)
in
{
	assert (arr.length == args.length);
}
body
{
	foreach (i, ref v; args) {
		alias T = typeof(v);
		v = arr[i].to!T;
	}
}

void verbose(Args...)(in Args args)
{
	stderr.write("[");
	foreach (i, ref v; args) {
		if (i) stderr.write(", ");
		stderr.write(v);
	}
	stderr.writeln("]");
}


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

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

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

    auto rbt = make!(RedBlackTree!(int, "a < b", true));
    int s = 0;
    int minans = 0;
    int[] res;
    foreach (e; arr) {
        int curans = minans;
        int curs = s;
        foreach_reverse (big; rbt) {
            if (curs + e <= m) { break; }

            curs -= big;
            curans += 1;
        }

        rbt.insert(e);
        s += e;

        while (s > m) {
            s -= rbt.back;
            rbt.removeBack();
            minans += 1;
        }

        res ~= curans;
    }

    res.map!(to!string).join(" ").writeln;
}

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

immutable int limit = 101;

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		readln;
		auto t = readln.splitter.map !(to !(int)).array;
		auto c = new int [limit];

		int [] ans;
		foreach (int num, ref value; t)
		{
			auto r = m - value;
			int cur = 0;
			foreach (i; 1..limit)
			{
				auto add = min (r / i, c[i]);
				cur += add;
				r -= add * i;
			}
			ans ~= num - cur;
			c[value] += 1;
		}
		writefln ("%(%s %)", ans);
	}
}

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

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

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

    auto rbt = make!(RedBlackTree!int);
    int s = 0;
    foreach (e; arr) {
        int ans = 0;
        int curs = s;
        foreach_reverse (big; rbt) {
            if (curs + e <= m) { break; }

            curs -= big;
            ans += 1;
        }

        rbt.insert(e);
        s += e;

        ans.writeln;
    }
}

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

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

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

    auto rbt = make!(RedBlackTree!int);
    int s = 0;
    int[] res;
    foreach (e; arr) {
        int ans = 0;
        int curs = s;
        foreach_reverse (big; rbt) {
            if (curs + e <= m) { break; }

            curs -= big;
            ans += 1;
        }

        rbt.insert(e);
        s += e;

        res ~= ans;
    }

    res.map!(to!string).join(" ").writeln;
}

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

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

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

    auto rbt = make!(RedBlackTree!(int, "a < b", true));
    int s = 0;
    int[] res;
    foreach (e; arr) {
        int ans = 0;
        int curs = s;
        foreach_reverse (big; rbt) {
            if (curs + e <= m) { break; }

            curs -= big;
            ans += 1;
        }

        rbt.insert(e);
        s += e;

        while (rbt.length > 100) {
            rbt.removeFront();
        }

        res ~= ans;
    }

    res.map!(to!string).join(" ").writeln;
}


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);
		n *= 2;
		auto a = readln.strip.map !(q{[-1, +1][a == '(']}).array;

		bool isOk ()
		{
			int bal = 0;
			foreach (i; 0..n)
			{
				bal += a[i];
				if (bal < 0)
				{
					return false;
				}
			}
			return true;
		}

		bool solve (int [] [] actions)
		{
			foreach (ref line; actions)
			{
				reverse (a[line[0]..line[1]]);
			}
			if (isOk ())
			{
				writeln (actions.length);
				foreach (ref line; actions)
				{
					writeln (line[0] + 1, " ", line[1]);
				}
				return true;
			}
			foreach_reverse (ref line; actions)
			{
				reverse (a[line[0]..line[1]]);
			}
			return false;
		}

		if (solve ([])) continue;

		{
			int lo = 0;
			int bestLo = 0;
			int cur = 0;
			foreach (i; 0..n)
			{
				cur += a[i];
				if (bestLo < cur)
				{
					bestLo = cur;
					lo = i + 1;
				}
				if (cur < 0)
				{
					break;
				}
			}

			int hi = n;
			int bestHi = 0;
			cur = 0;
			foreach_reverse (i; 0..n)
			{
				cur -= a[i];
				if (bestHi < cur)
				{
					bestHi = cur;
					hi = i;
				}
				if (cur < 0)
				{
					break;
				}
			}

			if (solve ([[lo, hi]])) continue;
		}

		{
			int p = 0;
			int up = 0;
			int cur = 0;
			foreach (i; 0..n)
			{
				cur += a[i];
				if (up < cur)
				{
					up = cur;
					p = i + 1;
				}
			}
			if (solve ([[0, p], [p, n]])) continue;
		}

		assert (false);
	}
}

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

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

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

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

enum FAIL = [-1];

int N;
string S;

int[] hs;
int im;

int[] solve0() {
  foreach (i; 0 .. 2 * N + 1) {
    if (hs[i] < 0) {
      return FAIL;
    }
  }
  return [];
}

int[] solve1() {
  int a = -1, b = -1;
  foreach         (i; 0 .. 2 * N + 1) if (hs[i] < 0) { a = i - 1; break; }
  foreach_reverse (i; 0 .. 2 * N + 1) if (hs[i] < 0) { b = i + 1; break; }
  assert(hs[a] == 0);
  assert(hs[b] == 0);
  debug {
    writeln("  a = ", a, ", b = ", b);
  }

  if (im <= a) return [im, 2 * N];
  if (b <= im) return [0, im];

  int am, bm;
  foreach (i; 0 .. a + 1)     if (hs[am] < hs[i]) am = i;
  foreach (i; b .. 2 * N + 1) if (hs[bm] < hs[i]) bm = i;
  debug {
    writeln("  am = ", am, ", bm = ", bm);
  }
  if (hs[am] + hs[bm] - hs[im] >= 0) {
    return [am, bm];
  }

  return FAIL;
}

int[] solve2() {
  return [0, im, im, 2 * N];
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        N = readInt;
        S = readToken;

        hs = new int[2 * N + 1];
        foreach (i; 0 .. 2 * N) {
          hs[i + 1] = hs[i] + ((S[i] == '(') ? +1 : -1);
        }
        im = 0;
        foreach (i; 0 .. 2 * N + 1) {
          if (hs[im] < hs[i]) {
            im = i;
          }
        }
        debug {
          writeln("  hs = ", hs);
          writeln("  im = ", im);
        }

        int[] ans;

        ans = solve0;
        if (ans != FAIL) {
          debug {
            writeln("  ", S);
          }
          writeln(0);
          continue;
        }
        ans = solve1;
        if (ans != FAIL) {
          debug {
            auto cs = S.dup;
            cs[ans[0] .. ans[1]].reverse;
            writeln("  ", cs);
          }
          writeln(1);
          writeln(ans[0] + 1, " ", ans[1]);
          continue;
        }
        ans = solve2;
        if (ans != FAIL) {
          debug {
            auto cs = S.dup;
            cs[ans[0] .. ans[1]].reverse;
            cs[ans[2] .. ans[3]].reverse;
            writeln("  ", cs);
          }
          writeln(2);
          writeln(ans[0] + 1, " ", ans[1]);
          writeln(ans[2] + 1, " ", ans[3]);
          continue;
        }

        assert(false);
      }
    }
  } 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)); }

enum FAIL = [-1];

int N;
string S;

int[] hs;
int im;

int[] solve0() {
  foreach (i; 0 .. 2 * N + 1) {
    if (hs[i] < 0) {
      return FAIL;
    }
  }
  return [];
}

int[] solve1() {
  int a = -1, b = -1;
  foreach         (i; 0 .. 2 * N + 1) if (hs[i] < 0) { a = i - 1; break; }
  foreach_reverse (i; 0 .. 2 * N + 1) if (hs[i] < 0) { b = i + 1; break; }
  assert(hs[a] == 0);
  assert(hs[b] == 0);
  debug {
    writeln("  a = ", a, ", b = ", b);
  }

  if (im <= a) return [im, 2 * N];
  if (b <= im) return [0, im];

  int am, bm;
  foreach (i; 0 .. a + 1)     if (hs[am] < hs[i]) am = i;
  foreach (i; b .. 2 * N + 1) if (hs[bm] < hs[i]) bm = i;
  debug {
    writeln("  am = ", am, ", bm = ", bm);
  }
  if (hs[am] + hs[bm] - hs[im] >= 0) {
    return [am, bm];
  }

  return FAIL;
}

int[] solve2() {
  return [0, im, im, 2 * N];
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        N = readInt;
        S = readToken;

        hs = new int[2 * N + 1];
        foreach (i; 0 .. 2 * N) {
          hs[i + 1] = hs[i] + ((S[i] == '(') ? +1 : -1);
        }
        foreach (i; 0 .. 2 * N + 1) {
          if (hs[im] < hs[i]) {
            im = i;
          }
        }
        debug {
          writeln("  hs = ", hs);
          writeln("  im = ", im);
        }

        int[] ans;

        ans = solve0;
        if (ans != FAIL) {
          writeln(0);
          continue;
        }
        ans = solve1;
        if (ans != FAIL) {
          writeln(1);
          writeln(ans[0] + 1, " ", ans[1]);
          continue;
        }
        ans = solve2;
        if (ans != FAIL) {
          writeln(2);
          writeln(ans[0] + 1, " ", ans[1]);
          writeln(ans[2] + 1, " ", ans[3]);
          continue;
        }

        assert(false);
      }
    }
  } catch (EOFException e) {
  }
}


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

void main() {
    auto T = readln.chomp.to!int;
    while (T--) {
        auto s = readln.split.map!(to!long);
        auto l = s[0];
        auto r = s[1];
        writeln(l, " ", l * 2);
    }
}

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

  int t;
  rd(t);
  while (t--) {
    int l, r;
    rd(l, r);
    writeln(l, " ", l * 2);
  }

}

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.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm : sort, each, maxElement, minElement;
import std.conv : to;
import std.range : iota, tee, enumerate;
import std.algorithm.comparison : equal, max, min;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;
import std.math;

alias Tree = RBT!int;
alias ll = long;

void main() {
  GC.disable();

  int T;
  readf(" %s", T);
  foreach(i; 0 .. T) {
    long l, r;
    readf(" %s %s", l, r);
    writef("%s %s\n", l, l*2);
  }

}

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

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

    foreach (i; 0 .. t) {
        int l,r;
        readf!" %s %s"(l,r);

        writeln(l," ",2*l);
    }
}


import std.stdio;
import std.typecons;

void main()
{
	uint n, k;

	readf(" %s %s", &n, &k);

	uint pairs = n * (n - 1) / 2;

	if(pairs < k * n)
	{
		writeln("-1");
		return;
	}

	uint[] wins = new uint[n + 1];
	uint[] losses = new uint[n + 1];

	uint maxLosses = n - 1 - k;

	Tuple!(uint, uint)[] lines;

	for(uint i = 1; i <= n; i++)
	{
		for(uint j = i + 1; j <= n; j++)
		{
			if(wins[i] < k && losses[j] < maxLosses)
			{
				wins[i]++;
				losses[j]++;
				lines ~= Tuple!(uint, uint)(i, j);
			}
			else if(wins[j] < k && losses[i] < maxLosses)
			{
				wins[j]++;
				losses[i]++;
				lines ~= Tuple!(uint, uint)(j, i);
			}
		}
	}

	writeln(lines.length);
	foreach(line; lines)
	{
		writeln(line[0], " ", line[1]);
	}
}

import std.stdio, std.string;

int r[1010][1010];
int a[1000010][2];

void solve(int n, int k)
{
    if (k > n * (n - 1) / 2)
    {
        printf("-1\n");
        return;
    }
    foreach (int i; 0 .. n)
    {
        foreach (int j; 0 .. n)
        {
            r[i][j] = 0;
        }
    }
    int idx = 0;
    foreach (int i; 0 .. n)
    {
        int cnt = 0;
        for (int j = 0; cnt < k && j < n; ++ j)
        {
            if (j == i || r[i][j] == 1)
            {
                continue;
            }
            a[idx][0] = i + 1;
            a[idx][1] = j + 1;
            ++ idx;
            r[i][j] = r[j][i] = 1;
            ++ cnt;
        }
        if (cnt < k)
        {
            printf("-1\n");
            return;
        }
    }
    printf("%d\n", n * k);
    foreach (int i; 0 .. n * k)
    {
        printf("%d %d\n", a[i][0], a[i][1]);
    }
}

void main(string[] args)
{
    int n, k;
    while (scanf("%d%d", &n, &k) == 2)
    {
        solve(n, k);
    }
}

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, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		if (k + k < n)
		{
			writeln (n * k);
			foreach (i; 0..n)
			{
				foreach (j; 1..k + 1)
				{
					writeln (i + 1, ' ', (i + j) % n + 1);
				}
			}
		}
		else
		{
			writeln (-1);
		}
	}
}

module football;
import std.stdio, std.array, std.range, std.string, std.typecons;
import std.algorithm, std.container, std.math, std.numeric, std.random;
void scan(T...)(ref T args) { foreach (ref arg; args) readf(" %s", &arg); }
void minify(T)(ref T a, in T b) { if (a > b) a = b; }
void maxify(T)(ref T a, in T b) { if (a < b) a = b; }
void ewriteln(T...)(T args) { stderr.writeln("\033[35m", args, "\033[0m"); }

int n, k;
void readInput() {
	scan(n, k);
}

void tc() {
	readInput();
	if (2*k > n-1) { writeln("-1"); return; }
	writeln(n * k);
	foreach (i; 0..n) {
		foreach (j; 0..k) {
			writeln(i + 1, " ", (i+j+1)%n+1);
		}
	}
}

void main() { tc(); }

import std.stdio;
import std.typecons;

void main()
{
	uint n, k;

	readf(" %s %s", &n, &k);

	uint pairs = n * (n - 1);

	if(pairs < k * n)
	{
		writeln("-1");
		return;
	}

	uint[] wins = new uint[n + 1];

	Tuple!(uint, uint)[] lines;

	for(uint i = 1; i <= n; i++)
	{
		for(uint j = i + 1; j <= n; j++)
		{
			if(wins[i] < k)
			{
				wins[i]++;
				lines ~= Tuple!(uint, uint)(i, j);
			}
			else if(wins[j] < k)
			{
				wins[j]++;
				lines ~= Tuple!(uint, uint)(j, i);
			}
		}
	}

	writeln(lines.length);
	foreach(line; lines)
	{
		writeln(line[0], " ", line[1]);
	}
}

import std.stdio;
import std.typecons;

void main()
{
	uint n, k;

	readf(" %s %s", &n, &k);

	uint pairs = n * (n - 1);

	if(pairs < k * n)
	{
		writeln("-1");
		return;
	}

	uint[] wins = new uint[n + 1];
	uint[] losses = new uint[n + 1];

	uint maxLosses = n - 1 - k;

	Tuple!(uint, uint)[] lines;

	for(uint i = 1; i <= n; i++)
	{
		for(uint j = i + 1; j <= n; j++)
		{
			if(wins[i] < k && losses[j] < maxLosses)
			{
				wins[i]++;
				losses[j]++;
				lines ~= Tuple!(uint, uint)(i, j);
			}
			else if(wins[j] < k && losses[i] < maxLosses)
			{
				wins[j]++;
				losses[i]++;
				lines ~= Tuple!(uint, uint)(j, i);
			}
		}
	}

	writeln(lines.length);
	foreach(line; lines)
	{
		writeln(line[0], " ", line[1]);
	}
}


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

void main ()
{
	int n, m, k;
	while (readf (" %s %s %s", &n, &m, &k) > 0)
	{
		readln;
		auto b = readln.splitter.map !(to !(int)).array;
		auto c = iota (n - 1).map !(i => b[i + 1] - b[i] - 1).array;
		sort (c);
		long res = n;
		res += sum (c[0..n - k], 0L);
		writeln (res);
	}
}

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

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

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

    auto B = (N-1).iota.map!(i => A[i+1] - A[i] - 1).array;
    B.sort!"a > b";

    long ans = A.back - A.front + 1;
    long cnt = 1;
    int p = 0;

    while (cnt < K && p < B.length) {
        ans -= B[p];
        p += 1;
        cnt += 1;
    }

    ans.writeln;
}


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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		alias Edge = Tuple !(int, q{v}, int, q{w});
		immutable int steps = 18;
		immutable int inf = int.max / 2;
		auto p = new Edge [] [steps];
		p[0] = new Edge [n];
		p[0][0] = Edge (-1, inf);
		auto adj = new int [] [n];
		foreach (i; 1..n)
		{
			int v;
			int w;
			readf (" %s %s", &v, &w);
			v--;
			p[0][i] = Edge (v, w);
			adj[v] ~= i;
		}
		foreach (step; 1..steps)
		{
			p[step] = p[step - 1].dup;
			foreach (i; 0..n)
			{
				int cv = p[step][i].v;
				int cw = p[step][i].w;
				if (cw < inf)
				{
					p[step][i] = Edge (p[step - 1][cv].v,
					    min (inf, p[step - 1][cv].w + cw));
				}
			}
		}

		auto ans = new int [n];
		foreach (i; 0..n)
		{
			int v = i;
			ans[v] += 1;
			foreach_reverse (step; 0..steps)
			{
				if (a[i] >= p[step][v].w)
				{
					a[i] -= p[step][v].w;
					v = p[step][v].v;
				}
			}
			v = p[0][v].v;
			if (v != -1)
			{
				ans[v] -= 1;
			}
		}

		int recur (int v)
		{
			int res = ans[v];
			foreach (u; adj[v])
			{
				res += recur (u);
			}
			ans[v] = res;
			return res;
		}

		recur (0);
		ans[] -= 1;
		writefln ("%(%s %)", ans);
	}
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(long)).array;
		alias Edge = Tuple !(int, q{v}, long, q{w});
		immutable int steps = 18;
		immutable long inf = long.max / 2;
		auto p = new Edge [] [steps];
		p[0] = new Edge [n];
		p[0][0] = Edge (-1, inf);
		auto adj = new int [] [n];
		foreach (i; 1..n)
		{
			int v;
			long w;
			readf (" %s %s", &v, &w);
			v--;
			p[0][i] = Edge (v, w);
			adj[v] ~= i;
		}
		debug {writeln (p[0]);}
		foreach (step; 1..steps)
		{
			p[step] = new Edge [n];
			foreach (i; 0..n)
			{
				p[step][i] = p[step - 1][i];
				int cv = p[step][i].v;
				long cw = p[step][i].w;
				if (cw < inf)
				{
					p[step][i] = Edge (p[step - 1][cv].v,
					    p[step - 1][cv].w + cw);
				}
			}
			debug {writeln (p[step]);}
		}

		auto ans = new int [n];
		foreach (i; 0..n)
		{
			int v = i;
			ans[v] += 1;
			foreach_reverse (step; 0..steps)
			{
				if (a[i] >= p[step][v].w)
				{
					a[i] -= p[step][v].w;
					v = p[step][v].v;
				}
			}
			v = p[0][v].v;
			debug {writeln (i, " ", v);}
			if (v != -1)
			{
				ans[v] -= 1;
			}
		}

		int recur (int v)
		{
			debug {writeln (v);}
			int res = ans[v];
			foreach (u; adj[v])
			{
				res += recur (u);
			}
			ans[v] = res;
			return res;
		}

		recur (0);
		ans[] -= 1;
		writefln ("%(%s %)", ans);
	}
}

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

__gshared:

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

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

struct SegTree {
    long[ ][800_000] _t;
    long[ ][ ] t;

    static int lc(int i) { return i << 1 | 0x1; }
    static int rc(int i) { return (i << 1) + 2; }

    void init(int i, const(long)[ ] a) {
        assert(!a.empty);
        if (a.length == 1)
            t[i] = [a[0]];
        else {
            auto mid = a.length >> 1;
            init(lc(i), a[0 .. mid]);
            init(rc(i), a[mid .. $]);
            t[i] = merge(t[lc(i)], t[rc(i)]).array();
        }
    }

    int countLessEqual(int left, int right, long value) const {
        value++;

        int get(int i, int lb, int rb, int left, int right) {
            if (left >= right)
                return 0;
            if (lb == left && rb == right)
                return cast(int)assumeSorted(t[i][ ]).lowerBound(value).length;
            int mid = (lb + rb) >> 1;
            int a = get(lc(i), lb, mid, left, min(mid, right));
            int b = get(rc(i), mid, rb, max(left, mid), right);
            return a + b;
        }

        return get(0, 0, n, left, right);
    }
}

int gid;
long[200_000] _magic;
long[ ] magic;

struct Node {
    int value;
    long distToRoot;
    int left, right;
    int parentLen;
    Node*[ ] children;

    void calcDist(long d) {
        distToRoot = d + parentLen;
        magic[gid++] = distToRoot - value;
        left = gid;
        foreach (node; children)
            node.calcDist(distToRoot);
        right = gid;
    }
}

int n;
Node[200_000] _nodes;
Node[ ] nodes;
SegTree sgt;

void main() {
    _nodes[0].parentLen = 0;
    while (read(&n)) {
        nodes = _nodes[0 .. n];
        magic = _magic[0 .. n];
        version (LocalProject)
            foreach (ref node; nodes)
                node.children = null;
        foreach (ref node; nodes)
            read(&node.value);
        foreach (ref node; nodes[1 .. $]) {
            int p, w;
            read(&p, &w);
            p--;
            node.parentLen = w;
            nodes[p].children ~= &node;
        }
        gid = 0;
        nodes[0].calcDist(0);
        debug writeln(magic);
        //debug foreach (ref node; nodes)
        //    writeln(node);
        sgt.t = sgt._t[0 .. n << 2];
        version (LocalProject)
            foreach (ref ls; sgt.t)
                ls = null;
        sgt.init(0, magic);
        foreach (ref node; nodes) {
            debug write(node.left, "..", node.right, ':', node.distToRoot, '@');
            write(sgt.countLessEqual(node.left, node.right, node.distToRoot), ' ');
        }
        writeln();
        debug writeln();
    }
}

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

__gshared:

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

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

/+
int myUpperBound(R, T)(R range, T value) if (isRandomAccessRange!R) {
    int left = 0, right = cast(int)range.length;
    while (left != right) {
        int mid = (left + right) >> 1;
        if (value >= range[mid])
            left = mid + 1;
        else
            right = mid;
    }
    return left;
}
+/

struct SegTree {
    //Array!(Array!long) t;
    long[ ][800_000] _t;
    long[ ][ ] t;

    static int lc(int i) { return i << 1 | 0x1; }
    static int rc(int i) { return (i << 1) + 2; }

    void init(int i, const(long)[ ] a) {
        assert(!a.empty);
        if (a.length == 1)
            t[i] = [a[0]];
        else {
            auto mid = a.length >> 1;
            init(lc(i), a[0 .. mid]);
            init(rc(i), a[mid .. $]);
            //t[i] = Array!long(merge(t[lc(i)][ ], t[rc(i)][ ]));
            t[i] = merge(t[lc(i)], t[rc(i)]).array();
        }
    }

    int countLessEqual(int left, int right, long value) const {
        value++;

        int get(int i, int lb, int rb, int left, int right) {
            if (left >= right)
                return 0;
            if (lb == left && rb == right)
                return cast(int)assumeSorted(t[i][ ]).lowerBound(value).length;
                /+return myUpperBound(t[i], value);+/
            int mid = (lb + rb) >> 1;
            int a = get(lc(i), lb, mid, left, min(mid, right));
            int b = get(rc(i), mid, rb, max(left, mid), right);
            return a + b;
        }

        return get(0, 0, n, left, right);
    }
}

int gid;
long[200_000] _magic;
long[ ] magic;

struct Node {
    int value;
    long distToRoot;
    int left, right;
    int parentLen;
    //Array!(Node*) children;
    Node*[ ] children;

    void calcDist(long d) {
        distToRoot = d + parentLen;
        magic[gid++] = distToRoot - value;
        left = gid;
        foreach (node; children)
            node.calcDist(distToRoot);
        right = gid;
    }
}

int n;
Node[200_000] _nodes;
Node[ ] nodes;
SegTree sgt;

void main() {
    _nodes[0].parentLen = 0;
    while (scanf("%d", &n) == 1) {
        nodes = _nodes[0 .. n];
        magic = _magic[0 .. n];
        version (LocalProject)
            foreach (ref node; nodes)
                /+node.children.clear();+/
                node.children = null;
        foreach (ref node; nodes)
            scanf("%d", &node.value);
        foreach (ref node; nodes[1 .. $]) {
            int p, w;
            scanf("%d%d", &p, &w);
            p--;
            node.parentLen = w;
            nodes[p].children ~= &node;
        }
        gid = 0;
        nodes[0].calcDist(0);
        debug writeln(magic);
        //debug foreach (ref node; nodes)
        //    writeln(node);
        //sgt.t.clear();
        //sgt.t.length = n << 2;
        sgt.t = sgt._t[0 .. n << 2];
        version (LocalProject)
            foreach (ref ls; sgt.t)
                ls = null;
        sgt.init(0, magic);
        foreach (ref node; nodes) {
            debug write(node.left, "..", node.right, ':', node.distToRoot, '@');
            printf("%d ", sgt.countLessEqual(node.left, node.right, node.distToRoot));
        }
        putchar('\n');
        debug writeln();
    }
}

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

__gshared:

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

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

struct SegTree {
    long[ ][800_000] _t;
    long[ ][ ] t;

    static int lc(int i) { return i << 1 | 0x1; }
    static int rc(int i) { return (i << 1) + 2; }

    void init(int i, const(long)[ ] a) {
        assert(!a.empty);
        if (a.length == 1)
            t[i] = [a[0]];
        else {
            auto mid = a.length >> 1;
            init(lc(i), a[0 .. mid]);
            init(rc(i), a[mid .. $]);
            t[i] = merge(t[lc(i)], t[rc(i)]).array();
        }
    }

    int countLessEqual(int left, int right, long value) const {
        value++;

        int get(int i, int lb, int rb, int left, int right) {
            if (left >= right)
                return 0;
            if (lb == left && rb == right)
                return cast(int)assumeSorted(t[i][ ]).lowerBound(value).length;
            int mid = (lb + rb) >> 1;
            int a = get(lc(i), lb, mid, left, min(mid, right));
            int b = get(rc(i), mid, rb, max(left, mid), right);
            return a + b;
        }

        return get(0, 0, n, left, right);
    }
}

int gid;
long[200_000] _magic;
long[ ] magic;

struct Node {
    int value;
    long distToRoot;
    int left, right;
    int parentLen;
    Node*[ ] children;

    void calcDist(long d) {
        distToRoot = d + parentLen;
        magic[gid++] = distToRoot - value;
        left = gid;
        foreach (node; children)
            node.calcDist(distToRoot);
        right = gid;
    }
}

int n;
Node[200_000] _nodes;
Node[ ] nodes;
int[199_999] _parents;
int[ ] parents;
Node*[199_999] _children;
Node*[ ] children;
SegTree sgt;

void main() {
    _nodes[0].parentLen = 0;
    while (scanf("%d", &n) == 1) {
        nodes = _nodes[0 .. n];
        magic = _magic[0 .. n];
        children = _children[0 .. n - 1];
        parents = _parents[0 .. n - 1];
        version (LocalProject)
            foreach (ref node; nodes)
                node.children = null;
        foreach (ref node; nodes)
            scanf("%d", &node.value);
        foreach (ref node, ref child, ref parent; lockstep(nodes[1 .. $], children, parents)) {
            child = &node;
            scanf("%d%d", &parent, &node.parentLen);
            parent--;
        }
        auto z = zip(parents, children);
        z.sort!`a[0] < b[0]`;
        int last = 0;
        foreach (pc, count; z.group!`a[0] == b[0]`) {
            nodes[pc[0]].children = children[last .. last + count];
            last += count;
        }
        gid = 0;
        nodes[0].calcDist(0);
        debug writeln(magic);
        //debug foreach (ref node; nodes)
        //    writeln(node);
        sgt.t = sgt._t[0 .. n << 2];
        version (LocalProject)
            foreach (ref ls; sgt.t)
                ls = null;
        sgt.init(0, magic);
        foreach (ref node; nodes) {
            debug write(node.left, "..", node.right, ':', node.distToRoot, '@');
            printf("%d ", sgt.countLessEqual(node.left, node.right, node.distToRoot));
        }
        putchar('\n');
        debug writeln();
    }
}

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

__gshared:

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

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

int myUpperBound(R, T)(R range, T value) if (isRandomAccessRange!R) {
    int left = 0, right = cast(int)range.length;
    while (left != right) {
        int mid = (left + right) >> 1;
        if (value >= range[mid])
            left = mid + 1;
        else
            right = mid;
    }
    return left;
}

struct SegTree {
    //Array!(Array!long) t;
    long[ ][800_000] _t;
    long[ ][ ] t;

    static int lc(int i) { return i << 1 | 0x1; }
    static int rc(int i) { return (i << 1) + 2; }

    void init(int i, const(long)[ ] a) {
        assert(!a.empty);
        if (a.length == 1)
            t[i] ~= a[0];
        else {
            auto mid = a.length >> 1;
            init(lc(i), a[0 .. mid]);
            init(rc(i), a[mid .. $]);
            //t[i] = Array!long(merge(t[lc(i)][ ], t[rc(i)][ ]));
            t[i] = merge(t[lc(i)], t[rc(i)]).array();
        }
    }

    int countLessEqual(int left, int right, long value) const {
        //value++;

        int get(int i, int lb, int rb, int left, int right) {
            if (left >= right)
                return 0;
            if (lb == left && rb == right)
                /+return cast(int)assumeSorted(t[i][ ]).lowerBound(value).length;+/
                return myUpperBound(t[i], value);
            int mid = (lb + rb) >> 1;
            int a = get(lc(i), lb, mid, left, min(mid, right));
            int b = get(rc(i), mid, rb, max(left, mid), right);
            return a + b;
        }

        return get(0, 0, n, left, right);
    }
}

int gid;
long[200_000] _magic;
long[ ] magic;

struct Node {
    int value;
    long distToRoot;
    int left, right;
    int parentLen;
    //Array!(Node*) children;
    Node*[ ] children;

    void calcDist(long d) {
        distToRoot = d + parentLen;
        magic[gid++] = distToRoot - value;
        left = gid;
        foreach (node; children)
            node.calcDist(distToRoot);
        right = gid;
    }
}

int n;
Node[200_000] _nodes;
Node[ ] nodes;
SegTree sgt;

void main() {
    _nodes[0].parentLen = 0;
    while (scanf("%d", &n) == 1) {
        nodes = _nodes[0 .. n];
        magic = _magic[0 .. n];
        version (LocalProject)
            foreach (ref node; nodes)
                /+node.children.clear();+/
                node.children = null;
        foreach (ref node; nodes)
            scanf("%d", &node.value);
        foreach (ref node; nodes[1 .. $]) {
            int p, w;
            scanf("%d%d", &p, &w);
            p--;
            node.parentLen = w;
            nodes[p].children ~= &node;
        }
        gid = 0;
        nodes[0].calcDist(0);
        debug writeln(magic);
        //debug foreach (ref node; nodes)
        //    writeln(node);
        //sgt.t.clear();
        //sgt.t.length = n << 2;
        sgt.t = sgt._t[0 .. n << 2];
        version (LocalProject)
            foreach (ref ls; sgt.t)
                ls = null;
        sgt.init(0, magic);
        foreach (ref node; nodes) {
            debug write(node.left, "..", node.right, ':', node.distToRoot, '@');
            printf("%d ", sgt.countLessEqual(node.left, node.right, node.distToRoot));
        }
        putchar('\n');
        debug writeln();
    }
}

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

__gshared:

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

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

int myUpperBound(R, T)(R range, T value) if (isRandomAccessRange!R) {
    int left = 0, right = cast(int)range.length;
    while (left != right) {
        int mid = (left + right) >> 1;
        if (value >= range[mid])
            left = mid + 1;
        else
            right = mid;
    }
    return left;
}

struct SegTree {
    Array!(Array!long) t;

    static int lc(int i) { return i << 1 | 0x1; }
    static int rc(int i) { return (i << 1) + 2; }

    void init(int i, const(long)[ ] a) {
        assert(!a.empty);
        if (a.length == 1)
            t[i] ~= a[0];
        else {
            auto mid = a.length >> 1;
            init(lc(i), a[0 .. mid]);
            init(rc(i), a[mid .. $]);
            t[i] = Array!long(merge(t[lc(i)][ ], t[rc(i)][ ]));
        }
    }

    int countLessEqual(int left, int right, long value) const {
        //value++;

        int get(int i, int lb, int rb, int left, int right) {
            if (left >= right)
                return 0;
            if (lb == left && rb == right)
                /+return cast(int)assumeSorted(t[i][ ]).lowerBound(value).length;+/
                return myUpperBound(t[i][ ], value);
            int mid = (lb + rb) >> 1;
            int a = get(lc(i), lb, mid, left, min(mid, right));
            int b = get(rc(i), mid, rb, max(left, mid), right);
            return a + b;
        }

        return get(0, 0, n, left, right);
    }
}

int gid;
long[200_000] _magic;
long[ ] magic;

struct Node {
    int value;
    long distToRoot;
    int left, right;
    int parentLen;
    Array!(Node*) children;

    void calcDist(long d) {
        distToRoot = d + parentLen;
        magic[gid++] = distToRoot - value;
        left = gid;
        foreach (node; children)
            node.calcDist(distToRoot);
        right = gid;
    }
}

int n;
Node[200_000] _nodes;
Node[ ] nodes;
SegTree sgt;

void main() {
    _nodes[0].parentLen = 0;
    while (scanf("%d", &n) == 1) {
        nodes = _nodes[0 .. n];
        magic = _magic[0 .. n];
        version (LocalProject)
            foreach (ref node; nodes)
                node.children.clear();
        foreach (ref node; nodes)
            scanf("%d", &node.value);
        foreach (ref node; nodes[1 .. $]) {
            int p, w;
            scanf("%d%d", &p, &w);
            p--;
            node.parentLen = w;
            nodes[p].children ~= &node;
        }
        gid = 0;
        nodes[0].calcDist(0);
        debug writeln(magic);
        //debug foreach (ref node; nodes)
        //    writeln(node);
        sgt.t.clear();
        sgt.t.length = n << 2;
        sgt.init(0, magic);
        foreach (ref node; nodes) {
            debug write(node.left, "..", node.right, ':', node.distToRoot, '@');
            printf("%d ", sgt.countLessEqual(node.left, node.right, node.distToRoot));
        }
        putchar('\n');
        debug writeln();
    }
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		alias Edge = Tuple !(int, q{v}, int, q{w});
		immutable int steps = 18;
		immutable int inf = int.max / 2;
		auto p = new Edge [] [steps];
		p[0] = new Edge [n];
		p[0][0] = Edge (-1, inf);
		auto adj = new int [] [n];
		foreach (i; 1..n)
		{
			int v;
			int w;
			readf (" %s %s", &v, &w);
			v--;
			p[0][i] = Edge (v, w);
			adj[v] ~= i;
		}
		debug {writeln (p[0]);}
		foreach (step; 1..steps)
		{
			p[step] = new Edge [n];
			foreach (i; 0..n)
			{
				p[step][i] = p[step - 1][i];
				int cv = p[step][i].v;
				int cw = p[step][i].w;
				if (cw < inf)
				{
					p[step][i] = Edge (p[step - 1][cv].v,
					    p[step - 1][cv].w + cw);
				}
			}
			debug {writeln (p[step]);}
		}

		auto ans = new int [n];
		foreach (i; 0..n)
		{
			int v = i;
			ans[v] += 1;
			foreach_reverse (step; 0..steps)
			{
				if (a[i] >= p[step][v].w)
				{
					a[i] -= p[step][v].w;
					v = p[step][v].v;
				}
			}
			v = p[0][v].v;
			debug {writeln (i, " ", v);}
			if (v != -1)
			{
				ans[v] -= 1;
			}
		}

		int recur (int v)
		{
			debug {writeln (v);}
			int res = ans[v];
			foreach (u; adj[v])
			{
				res += recur (u);
			}
			ans[v] = res;
			return res;
		}

		recur (0);
		ans[] -= 1;
		writefln ("%(%s %)", ans);
	}
}


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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		if (n < 3)
		{
			writeln (0);
			continue;
		}
		auto d = a[1] - a[0];
		int res = n + 1;
		foreach (long delta; d - 2..d + 3)
		{
			foreach (start; a[0] - 1..a[0] + 2)
			{
				auto v = sequence !((r, k) =>
				    start + k * delta);
				int cur = 0;
				foreach (x, y; zip (a, v))
				{
					if (abs (x - y) > 1)
					{
						cur = n + 1;
					}
					else
					{
						cur += abs (x - y);
					}
				}
				res = min (res, cur);
			}
		}
		if (res > n)
		{
			res = -1;
		}
		writeln (res);
	}
}

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

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

  if(n<=2){
    writeln(0);
    return;
  }

  long[] cand;
  for(long dx=-1; dx<=1; dx++){
    for(long dy=-1; dy<=1; dy++){
      cand~=((as[1]+dx)-(as[0]+dy));
    }
  }
  cand=cand.sort.uniq.array;
  int mn=1_000_000_000;
  foreach(diff; cand)for(long init_diff=-1; init_diff<=1; init_diff++){
    auto pre=as[0]+init_diff;
    int cnt=init_diff.abs.to!(int);
    foreach(i; 1..n){
      bool found=false;
      for(long d=-1; d<=1; d++){
        if((as[i]+d)-(pre)==diff){
          pre=as[i]+d;
          cnt+=d.abs;
          found=true;
          break;
        }
      }
      if(found==false) goto hell;
    }
    mn=min(mn, cnt);
    hell:;
  }

  if(mn<=n) writeln(mn);
  else writeln(-1);
}

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


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

string FMT_F = "%.10f";

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

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

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

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

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

		auto x = a.maxElement;
		auto used = new bool[](n);
		foreach (i; 0..n)
		{
			long best;
			int pos;
			foreach (j; 0..n)
			{
				if (used[j]) continue;
				auto tmp = gcd(x, a[j]);
				debug writeln("tmp:", tmp);
				if (tmp > best)
				{
					best = tmp;
					pos = j;
				}
			}
			debug writeln("a[pos]:", a[pos], " best:", best);
			ans[ti] ~= a[pos];
			used[pos] = true;
			x = best;
		}
	}

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

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

alias ll = long;
alias to!int isz;
alias rbt = redBlackTree;
static string[] token;
T rd(T = long)() { while(!token.length) token = readln.chomp.split; string res = token[0]; token.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
/*******************************It's a Me, Mario!**********************************************/

void play(){
    int n;
    n = rd!int;
    ll[] arr = rdarr;
    ll[] ray;
    arr.sort();
    arr.reverse();
    ll maxel = arr[0];
    bool[long] vis;
    int maxi = 0;
    foreach(i; 0..arr.length){
        if(arr[i] >= maxel){
            maxel = arr[i];
            maxi = to!int(i);
        }
        vis[i] = 0;
    }
    ray ~= maxel;
    vis[maxi] = 1;
    ll cnt = 1;
    ll gcdall = maxel;
    while(cnt < n){
        ll maxgcd = 1;
        foreach(j; 0..n){
            if(!vis[j] && gcd(gcdall, arr[j]) >= maxgcd){
                maxgcd = gcd(gcdall, arr[j]);
                maxi = j;
            }
        }
        ray ~= arr[maxi];
        vis[maxi] = 1;
        gcdall = maxgcd;
        ++cnt;
    }
    foreach(el; ray){
        write(el, " ");
    }
    writeln;
}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto x = a.maxElement;
		auto c = new long[](n);
		foreach (i; 0..n)
		{
			c[i] = gcd(x, a[i]);
		}

		auto index = c.MAKE_IDX!"a > b";
		ans[ti].length = n;
		foreach (ii, i; index)
			ans[ti][ii] = a[i];
	}

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


import std.algorithm, std.container, std.conv, std.range, std.stdio, std.string;
void main () {
	foreach (test; 0..readln.strip.to !(int)) {
		readln;
		int [long] z;
		auto t = redBlackTree !(long);
		long m = 1, d, r;
		alias u = x => (x - d) * m;
		alias v = x => x * m + d;
		foreach (c; readln.splitter.map !(to !(long))) {
			m *= -1;
			d = c - d;
			while (!t.empty && v (t.front) < 0) z.remove (t.front), t.removeFront ();
			while (!t.empty && v (t.back) < 0) z.remove (t.back), t.removeBack ();
			t.insert (u (c));
			z[u (c)] += 1;
			r += z.get (u (0), 0);
		}
		writeln (r);
	}
}

import std;
void main() {
	foreach (_; 0..readln.strip.to!int) {
		readln;
		int [long] z;
		auto t = redBlackTree!long;
		long m = 1, d, r;
		alias u = x => (x - d) * m, v = x => x * m + d;
		foreach (c; readln.splitter.map!(to!long)) {
			m *= -1, d = c - d;
			while (!t.empty && v(t.front) < 0) z.remove(t.front), t.removeFront;
			while (!t.empty && v(t.back) < 0) z.remove(t.back), t.removeBack;
			t.insert(u(c)), z[u(c)] += 1, r += z.get(u(0), 0);
		}
		r.writeln;
	}
}

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

struct Storage
{
	int [long] num;
	RedBlackTree !(long) t = redBlackTree !(long);
	int mult = +1;
	long delta = 0L;

	long encode (long value)
	{
		return (value - delta) * mult;
	}

	long decode (long value)
	{
		return value * mult + delta;
	}

	void insert (long value)
	{
		value = encode (value);
		t.insert (value);
		num[value] += 1;
	}

	void cleanup ()
	{
		while (!t.empty && decode (t.front) < 0L)
		{
			num.remove (t.front);
			t.removeFront ();
		}

		while (!t.empty && decode (t.back) < 0L)
		{
			num.remove (t.back);
			t.removeBack ();
		}
	}

	int curAnswer ()
	{
		return num.get (encode (0L), 0);
	}

	void invertAll ()
	{
		mult *= -1;
		delta *= -1;
	}

	void addToAll (long value)
	{
		delta += value;
	}
}

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;

		Storage s;
		long res = 0L;
		foreach (i, ref cur; a)
		{
			s.invertAll ();
			s.addToAll (cur);
			s.cleanup ();
			s.insert (cur);
			res += s.curAnswer ();
		}
		writeln (res);
	}
}

immutable multi = true;

void solve(int tc)
{
	auto n = readInt!int;
	auto a = new int[](n+1);
	foreach(i; 1 .. n + 1) a[i] = readInt!int;
	auto cSum = new long[](n+1);
	cSum[0] = 0;
	foreach(i; 1 .. n+1)
	{
		if (i&1) cSum[i] = cSum[i-1] - a[i];
		else cSum[i] = cSum[i-1] + a[i];
	}
	auto only1Max = new long[](n+1); only1Max[] = long.min;
	auto only0Max = new long[](n+1); only0Max[] = long.min;
	auto only1Min = new long[](n+1); only1Min[] = long.max;
	auto only0Min = new long[](n+1); only0Min[] = long.max;
	foreach(i; 0 .. n+1)
	{
		if (i&1)
		{
			only1Max[i] = cSum[i];
			only1Min[i] = cSum[i];
		}
		else
		{
			only0Max[i] = cSum[i];
			only0Min[i] = cSum[i];
		}
	}
	auto queryOnly1Max = Sparse!(long, max, "max")(only1Max);
	auto queryOnly0Max = Sparse!(long, max, "max")(only0Max);
	auto queryOnly1Min = Sparse!(long, min, "min")(only1Min);
	auto queryOnly0Min = Sparse!(long, min, "min")(only0Min);
	debug writeln(cSum);
	debug writeln(only1Max);
	debug writeln(only0Min);
	int getLeft(int r)
	{
		int left = -1;
		int hi = r;
		int lo = 0;
		while (lo <= hi)
		{
			int mi = (hi + lo) / 2;
			// this - same >= 0 this >= max(same)
			// this - other <= 0 this <= min(other)
			if (cSum[r] >= queryOnly1Max[mi .. r+1].max &&
			    cSum[r] <= queryOnly0Min[mi .. r+1].min)
			{
				left = mi;
				hi = mi - 1;
			}
			else
			{
				lo = mi + 1;
			}
		}
		return left;
	}
	debug foreach(i; 1 .. n + 1)
	{
		writeln("left of ", i, " ", getLeft(i));
	}
	int[long] lastWithValue;
	lastWithValue[0] = 0;
	long[] ways = new long[](n+1);
	foreach(i; 1 .. n+1)
	{
		if (auto last = cSum[i] in lastWithValue)
		{
			int left = getLeft(i);
			if (*last >= left)
			{
				ways[i] = 1 + ways[*last];
			}
		}
		lastWithValue[cSum[i]] = i;
	}
	ways.sum.writeln;
}
// sparse table V, f, fName {{{
struct Sparse(V, alias f, string fName = "value")
{
	import std.math : log2;
	V[][] _table;
	int[] maxPow;
	this(V[] values)
	{
		auto n = values.length;
		maxPow = new int[](n + 1);
		maxPow[0] = int.min;
		maxPow[1] = 0;
		foreach(i; 2 .. n + 1)
		{
			int prev = maxPow[i - 1];
			maxPow[i] = prev;
			prev = (1 << prev);
			if (prev * 2 <= i) maxPow[i]++;
		}
		_table = new V[][](maxPow[n] + 1, n);
		_table[0][] = values[];

		foreach(p; 1 .. maxPow[n] + 1)
		foreach(i; 0 .. n - (1<<p) + 1)
			_table[p][i] = f(_table[p-1][i], _table[p-1][i+(1<<(p-1))]);
	}
	int[2] opSlice(size_t i)(size_t start, size_t end) if (i == 0)
	{
		return [cast(int)start, cast(int)end];
	}
	auto opIndex(int[2] slice)
	{
		int sliceLen = slice[1] - slice[0];
		auto x = maxPow[sliceLen];
		auto twoX = (1 << x);
		auto p1 = _table[x][slice[0]];
		auto p2 = _table[x][slice[1] - twoX];
		struct Ans
		{
			mixin(q{V }, fName, q{;});
		}
		return Ans(f(p1, p2));
	}
}

unittest
{
	import std.algorithm;
	import std.stdio;
	alias MinQ = Sparse!(int, min, "min");
	writeln("testing");
	int[] array = [1, 2, 3, 4, -2, -2, -3, 0, 10];
	auto minQ = MinQ(array);
	foreach(i; 0 .. array.length)
	{
		foreach(j; i + 1 .. array.length + 1)
		{
			assert(minQ[i .. j].min == array[i .. j].fold!min);
		}
	}
}
// }}}

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

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

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

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

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


// Author: Ivan Kazmenko (gassa@mail.ru)
module solution;
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

int [2] solve (long n)
{
	int [2] res = [1, 1];
	for (int d = 2; d * 1L * d * d <= n; d++)
	{
		if (n % d == 0)
		{
			int [2] cur = [0, d];
			while (n % d == 0)
			{
				n /= d;
				cur[0] += 1;
			}
			res = max (res, cur);
		}
	}
	auto v = cast (int) (sqrt (n * 1.0));
	if (v * 1L * v == n && res[0] < 2)
	{
		res = [2, v];
	}
	return res;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(long);
		auto res = solve (n);
		long [] answer;
		foreach (i; 0..res[0] - 1)
		{
			answer ~= res[1];
			n /= res[1];
		}
		answer ~= n;
		writeln (answer.length);
		writefln !("%(%s %)") (answer);
	}
}

// Author: Ivan Kazmenko (gassa@mail.ru)
module solution;
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

int [2] solve (long n)
{
	int [2] res = [1, 1];
	for (int d = 2; d * 1L * d <= n && d <= 90000; d++)
	{
		if (n % d == 0)
		{
			int [2] cur = [0, d];
			while (n % d == 0)
			{
				n /= d;
				cur[0] += 1;
			}
			res = max (res, cur);
		}
	}
	auto v = cast (int) (sqrt (n * 1.0));
	if (v * 1L * v == n && res[0] < 2)
	{
		res = [2, v];
	}
	return res;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(long);
		auto res = solve (n);
		long [] answer;
		foreach (i; 0..res[0] - 1)
		{
			answer ~= res[1];
			n /= res[1];
		}
		answer ~= n;
		writeln (answer.length);
		writefln !("%(%s %)") (answer);
	}
}

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

long[2][] primeFact(long x)
{
	long[2][] ans;
	for (long i = 2; i*i <= x; ++i)
	{
		if (x % i != 0) continue;

		long r;
		while (x % i == 0)
		{
			++r;
			x /= i;
		}
		ans ~= [i, r];
	}
	if (x != 1)
		ans ~= [x, 1];
	return ans;
}

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

		auto r = primeFact(n);
		while (true)
		{
			long x = 1;
			foreach (ref e; r)
			{
				if (e[1] == 0) continue;
				x *= e[0];
				--e[1];
			}
			if (x == 1) break;
			ans[ti] = x ~ ans[ti];
		}
	}

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


// Vicfred
// https://codeforces.com/contest/1504/problem/A
// greedy
import std.stdio;

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

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

    bool found = false;
    int n = cast(int)s.length;
    for(uint i = 0; i < n; ++i) {
        if(s[i] == 'a')
            continue;
        found = true;
        "YES".writeln;
        (s[0..n-i]~'a'~s[n-i..$]).writeln;
        break;
    }
    if(!found)
        "NO".writeln;
}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		foreach (i; 0..s.length)
		{
			if (s[$-i-1] != 'a')
			{
				ans[ti] = s[0..i] ~ 'a' ~ s[i..$];
				break;
			}
		}
	}

	foreach (e; ans)
	{
		if (e.empty)
			writeln("NO");
		else
		{
			writeln("YES");
			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;
		auto p = n.iota.array;
		p.schwartzSort !(i => a[i]);
		int [] ans;
		long prev = 0;
		foreach (i; p)
		{
			if (prev < a[i])
			{
				ans.length = 0;
			}
			ans ~= i + 1;
			prev += a[i];
		}
		sort (ans);
		writeln (ans.length);
		writefln !("%(%s %)") (ans);
	}
}

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

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

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

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

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

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

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

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

alias P = Tuple!(int, "i", long, "t");

void main()
{
    int T; get(T); while (T--) {
        int N; get(N);
        long[] AA; get(AA);
        P[] ps;
        foreach (i, a; AA) ps ~= P(i.to!int + 1, a);
        sort!"a.t < b.t"(ps);
        int[] rs;
        long s;
        foreach (i; 0..N-1) {
            auto p = ps[i];
            s += p.t;
            if (ps[i + 1].t <= s) {
                rs ~= p.i;
            } else {
                rs = [];
            }
        }
        rs ~= ps[$-1].i;
        sort(rs);
        writeln(rs.length);
        writefln!"%(%d %)"(rs);
    }
}

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

long compress(in long[] arr, out long[long] zip, out long[] unzip)
{
	auto index = MAKE_IDX(arr);
	long last = arr[index[0]], x;
	zip[last] = x;
	unzip ~= last;
	foreach (i; index[1..$])
	{
		if (arr[i] == last) continue;
		last = arr[i];
		++x;
		zip[last] = x;
		unzip ~= last;
	}
	return x+1;
}

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

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

		long[long] zip;
		long[] unzip;
		auto len = cast(int)compress(a, zip, unzip);

		auto cnt = new int[](len);
		foreach (i; 0..n)
		{
			++cnt[cast(int)zip[a[i]]];
		}
		auto b = new long[](len+1);
		foreach (i; 0..len)
		{
			b[i+1] = b[i] + cnt[i] * unzip[i];
		}
		debug writeln(b);

		auto win = new bool[](len);
		foreach (i; 0..len)
		{
			auto x = b[i+1];
			debug writeln("i:", i, " x:", x);
			while (x < unzip[len-1])
			{
				bool f(int p)
				{
					return x >= unzip[p];
				}
				auto r = binarySearch!(f)(0, len);
				debug writeln("r:", r);
				if (b[r+1] <= x) break;
				x = b[r+1];
			}
			win[i] = x >= unzip[len-1];
		}

		foreach (i; 0..n)
		{
			auto p = cast(int)zip[a[i]];
			if (win[p])
				ans[ti] ~= i+1;
		}
	}

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