import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;
import std.range;
import std.numeric;
import std.traits;

void main(string[] args)
{
  auto n = next!int;
  auto m = next!int;
  auto nom = n / m;
  auto a = next!int(n);
  auto cnt = new int[](m);
  auto byclass = new int[][](m);
  foreach(i, ai; a)
    {
      auto aim = ai % m;
      cnt[aim]++;
      byclass[aim] ~= cast(int) i;
    }
  auto toFill = redBlackTree!int();
  foreach(i; 0 .. m)
    if (cnt[i] < nom)
      toFill.insert(cast(int)i);
  long moves = 0;
  foreach(mclass; 0 .. m)
    {
      if (cnt[mclass] < nom) continue;
      auto tomove = cnt[mclass] - nom;
      foreach(i; 0 .. tomove)
	{
	  auto index = byclass[mclass][i];
	  auto upper = toFill.upperBound(mclass);
	  int fill = upper.empty? toFill.upperBound(-1).front : upper.front;
	  int delta = fill - mclass + int(fill < mclass) * m;
	  moves += delta;
	  a[index] = a[index] + delta;
	  assert(a[index] % m == fill);
	  assert(cnt[fill] < nom);
	  cnt[fill]++;
	  if (cnt[fill] == nom)
	    toFill.removeKey(fill);
	}
    }
  writeln(moves);
  foreach(ai; a)
    write(ai, " ");
  writeln;
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  string toString()
  {
    return to!string(_rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (isArray!(typeof(ti)))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}

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

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

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

    auto rm = new int[][] (m);

    foreach (i, e; arr) { rm[e % m] ~= i.to!int; }

    debug { rm.each!writeln; }

    long ans = 0;
    int[] totake;
    foreach (i; 0 .. 2 * m) {
        int cr = i % m;
        while (rm[cr].length < n / m && !totake.empty()) {
            int idx = totake.back;
            totake.popBack();

            int newval = (arr[idx] / m) * m + cr;
            if (newval <= arr[idx]) { newval += m; }
            ans += newval - arr[idx];
            arr[idx] = newval;
            rm[cr] ~= idx;
        }

        while (rm[cr].length > n / m) {
            totake ~= rm[cr].back;
            rm[cr].popBack();
        }
    }

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

import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;
import std.range;
import std.numeric;
import std.traits;

void main(string[] args)
{
  auto n = next!int;
  auto m = next!int;
  auto a = next!int(n);
  auto cnt = new int[](m);
  auto byclass = new int[][](m);
  foreach(i, ai; a)
    {
      auto aim = ai % m;
      cnt[aim]++;
      byclass[aim] ~= cast(int) i;
    }
  auto toFill = redBlackTree!int();
  foreach(i; 0 .. m)
    if (cnt[i] < n / m)
      toFill.insert(cast(int)i);
  long moves = 0;
  foreach(mclass; 0 .. m)
    {
      debug writeln("working with class ", mclass, " with indices ", byclass[mclass]);
      if (cnt[mclass] < n / m) continue;
      auto tomove = cnt[mclass] - n / m;
      debug writeln("will move ", tomove);
      foreach(i; 0 .. tomove)
	{
	  auto index = byclass[mclass][i];
	  int fill;
	  auto upper = toFill.upperBound(mclass);
	  if (upper.empty)
	    {
	      fill = toFill.upperBound(-1).front;
	    }
	  else
	    {
	      fill = upper.front;
	    }
	  int delta;
	  if (fill > mclass)
	    {
	      delta = fill - mclass;
	    }
	  else
	    {
	      delta = m - mclass + fill;
	    }
	  moves += delta;
	  a[index] = a[index] + delta;
	  assert(a[index] % m == fill);
	  assert(cnt[fill] < n / m);
	  cnt[fill]++;
	  if (cnt[fill] >= n / m)
	    toFill.removeKey(fill);
	}
    }
  writeln(moves);
  foreach(ai; a)
    write(ai, " ");
  writeln;
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  string toString()
  {
    return to!string(_rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (isArray!(typeof(ti)))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}

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

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

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

    auto rm = new int[][] (m);

    foreach (i, e; arr) { rm[e % m] ~= i.to!int; }

    debug { rm.each!writeln; }

    int ans = 0;
    int[] totake;
    foreach (i; 0 .. 3 * m) {
        int cr = i % m;
        while (rm[cr].length < n / m && !totake.empty()) {
            int idx = totake.back;
            totake.popBack();

            int newval = (arr[idx] / m) * m + cr;
            if (newval <= arr[idx]) { newval += m; }
            ans += newval - arr[idx];
            arr[idx] = newval;
            rm[cr] ~= idx;
        }

        while (rm[cr].length > n / m) {
            totake ~= rm[cr].back;
            rm[cr].popBack();
        }
    }

    ans.writeln;
    arr.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.typecons;

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

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

    auto rm = new int[][] (m);

    foreach (i, e; arr) { rm[e % m] ~= i.to!int; }

    debug { rm.each!writeln; }

    int ans = 0;
    int[] totake;
    foreach (i; 0 .. 2 * m) {
        int cr = i % m;
        while (rm[cr].length < n / m && !totake.empty()) {
            int idx = totake.back;
            totake.popBack();

            int newval = (arr[idx] / m) * m + cr;
            ans += newval - arr[idx];
            arr[idx] = newval;
            rm[cr] ~= idx;
        }

        while (rm[cr].length > n / m) {
            totake ~= rm[cr].back;
            rm[cr].popBack();
        }
    }

    ans.writeln;
    arr.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.typecons;

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

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

    auto rm = new int[][] (m);

    foreach (i, e; arr) { rm[e % m] ~= i.to!int; }

    debug { rm.each!writeln; }

    int ans = 0;
    int[] totake;
    foreach (i; 0 .. 3 * m) {
        int cr = i % m;
        while (rm[cr].length < n / m && !totake.empty()) {
            int idx = totake.back;
            totake.popBack();

            int newval = (arr[idx] / m) * m + cr;
            ans += newval - arr[idx];
            arr[idx] = newval;
            rm[cr] ~= idx;
        }

        while (rm[cr].length > n / m) {
            totake ~= rm[cr].back;
            rm[cr].popBack();
        }
    }

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


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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto q = RD!int;
	auto ans = new long[][](q);
	foreach (i; 0..q)
	{
		auto n = RD!int;
		auto k = RD!int;
		auto a = RDA;
		long[] tmp;
		long cnt;
		foreach (j; 0..n)
		{
			cnt += a[j];
			if (tmp.length == k-1) continue;
			if (cnt % 2 == 1)
			{
				tmp ~= j + 1;
				cnt = 0;
			}
		}
		if (cnt != 0)
		{
			if (cnt % 2 == 1)
				tmp ~= n;
			else
				tmp.length = 0;
		}
		if (tmp.length != k)
		{
			tmp.length = 0;
		}
		ans[i] = tmp;
	}

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

import std.stdio;
void main()
{
    int q;
    readf(" %s", &q);

    for(int i = 0; i < q; i++){
    	int k = 0;
    	int n = 0;
    	readf(" %s %s", &n, &k);
    	long[] array = new long[] (n);
    	int totalParity = 0;
    	int numOdd = 0;

    	for(int j = 0; j < n; j++){
    		readf(" %s", &array[j]);
    		totalParity += array[j];
    		totalParity %= 2;
    		if(array[j] % 2 == 1)
    			numOdd++;
    	}

    	if(totalParity == (k % 2) && numOdd >= k){
    		write("YES\n");
    		int currentParity = 0;
    		int numSegments = 1;

    		for(int j = 0; j < n && numSegments < k; j++){
    			currentParity += array[j];
    			currentParity %= 2;
    			if(currentParity % 2 == 1){
    				write(j + 1);
    				write(" ");
    				currentParity = 0;
    				numSegments++;
    			}
    		}
    		write((n));
    		write("\n");
    	}else{
    		write("NO\n");
    	}
    }
}

import std.stdio;
import std.algorithm;

void solve() {
    int n, k;
    readf(" %s %s", n, k);

    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
        readf(" %s", a[i]);
    }

    auto numOfOdds = fold!((s, x) => s + x % 2)(a, 0);
    if ((numOfOdds - k) % 2 == 0 && numOfOdds >= k) {
        writeln("YES");
        for (int i = 0, j = 1; i < n; i++) {
            if (a[i] % 2 == 1) {
                if (j == k) {
                    write(n);
                    break;
                } else {
                    write(i+1, " ");
                    j += 1;
                }
            }
        }
        writeln();
    } else {
        writeln("NO");
    }
}

void main(){
    int numOfTests;
    readf(" %s", numOfTests);
    for (int i = 0; i < numOfTests; i++) {
        solve();
    }
}

module main;

import std.stdio;
import std.container.array;

void main(string[] args){
    long n, a, b, sum, input;
    scanf("%lld", &n);
    while (n--) {
        auto arr = Array!int();
        scanf("%lld %lld", &a, &b);
        sum = 0;
        for (int i = 0; i < a; i++) {
            scanf("%lld", &input);
            sum += input;
            if (sum & 1) {
                arr.insertBack(i + 1);
                sum = 0;
            } else if (i == a - 1) {
                if (!arr.empty()) {
                    arr.back() = i + 1;
                }
            }
        }
        int len = arr.length;
        int start = 0;
        while (len > b) {
            len -= 2;
            start += 2;
        }
        if (len == b) {
            printf("YES\n");
            for (int i = start; i < arr.length; i++ ) {
                printf("%d ", arr[i]);
            }
            printf("\n");
        } else {
            printf("NO\n");
        }
    }
}

module main;

import std.stdio;
import std.container.array;

void main(string[] args){
    long n, a, b, sum, input;
    scanf("%lld", &n);
    while (n--) {
        auto arr = Array!int();
        scanf("%lld %lld", &a, &b);
        sum = 0;
        for (int i = 0; i < a; i++) {
            scanf("%lld", &input);
            sum += input;
            if (sum & 1) {
                arr.insertBack(i + 1);
                sum = 0;
            }
        }
        int len = arr.length;
        while (len > b) {
            len -= 2;
        }
        if (len == b) {
            printf("YES\n");
            for (int i =0; i < b; i++ ) {
                printf("%d ", arr[i]);
            }
            printf("\n");
        } else {
            printf("NO\n");
        }
    }
}

import std.stdio;
void main()
{
    int q;
    readf(" %s", &q);

    for(int i = 0; i < q; i++){
    	int k = 0;
    	int n = 0;
    	readf(" %s %s", &n, &k);
    	int[] array = new int[] (n);
    	int totalParity = 0;

    	for(int j = 0; j < n; j++){
    		readf(" %s", &array[j]);
    		totalParity += array[j];
    		totalParity %= 2;
    	}

    	if(totalParity == (k % 2)){
    		write("YES\n");
    		int currentParity = 0;
    		int numSegments = 1;

    		for(int j = 0; j < n && numSegments < k; j++){
    			currentParity += array[j];
    			currentParity %= 2;
    			if(currentParity % 2 == 1){
    				write(j);
    				write(" ");
    			}
    		}
    		write((n - 1));
    		write("\n");
    	}else{
    		write("NO\n");
    	}
    }
}

import std.stdio;
void main()
{
    int q;
    readf(" %s", &q);

    for(int i = 0; i < q; i++){
    	int k = 0;
    	int n = 0;
    	readf(" %s %s", &n, &k);
    	int[] array = new int[] (n);
    	int totalParity = 0;

    	for(int j = 0; j < n; j++){
    		readf(" %s", &array[j]);
    		totalParity += array[j];
    		totalParity %= 2;
    	}

    	if(totalParity == (k % 2)){
    		write("YES\n");
    		int currentParity = 0;
    		int numSegments = 1;

    		for(int j = 0; j < n && numSegments < k; j++){
    			currentParity += array[j];
    			currentParity %= 2;
    			if(currentParity % 2 == 1){
    				write(j + 1);
    				write(" ");
    				currentParity = 0;
    				numSegments++;
    			}
    		}
    		write((n));
    		write("\n");
    	}else{
    		write("NO\n");
    	}
    }
}

import std.stdio;
void main()
{
    int q;
    readf(" %s", &q);

    for(int i = 0; i < q; i++){
    	int k = 0;
    	int n = 0;
    	readf(" %s %s", &n, &k);
    	long[] array = new long[] (n);
    	int totalParity = 0;

    	for(int j = 0; j < n; j++){
    		readf(" %s", &array[j]);
    		totalParity += array[j];
    		totalParity %= 2;
    	}

    	if(totalParity == (k % 2)){
    		write("YES\n");
    		int currentParity = 0;
    		int numSegments = 1;

    		for(int j = 0; j < n && numSegments < k; j++){
    			currentParity += array[j];
    			currentParity %= 2;
    			if(currentParity % 2 == 1){
    				write(j + 1);
    				write(" ");
    				currentParity = 0;
    				numSegments++;
    			}
    		}
    		write((n));
    		write("\n");
    	}else{
    		write("NO\n");
    	}
    }
}

import std.stdio;
void main()
{
    int q;
    readf(" %s", &q);

    for(int i = 0; i < q; i++){
    	int k = 0;
    	int n = 0;
    	readf(" %s %s", &n, &k);
    	int[] array = new int[] (n);
    	int totalParity = 0;

    	for(int j = 0; j < n; j++){
    		readf(" %s", &array[j]);
    		totalParity += array[j];
    		totalParity %= 2;
    	}

    	if(totalParity == (k % 2)){
    		writeln("YES\n");
    		int currentParity = 0;
    		int numSegments = 1;

    		for(int j = 0; j < n && numSegments < k; j++){
    			currentParity += array[j];
    			currentParity %= 2;
    			if(currentParity % 2 == 1){
    				write(j);
    				write(" ");
    			}
    		}
    		write((n - 1));
    		write("\n");
    	}else{
    		write("NO\n");
    	}
    }
}


module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string read_string() {
                while (tokens.empty) {
                tokens = readln.split;
        }
        auto token = tokens.front;
                tokens.popFront;
                return token;
        }

        int read_int() {
                return read_string.to!int;
        }

        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // int t = cin.read_int;
        while (t--) {
                int n = cin.read_int;
                int d = cin.read_int;

                char[][] att = new char[][d];

                int beat_streak = 0;
                int count = 0;
                for (int i = 0; i < d; i++) {
                        att[i] = new char[n];
                        att[i] = cin.read_string.dup;
                        if (canFind(att[i][0..n], '0')) count++;
                        else count = 0;
                        beat_streak = max(beat_streak, count);
                }
                writeln(beat_streak);
        }
}

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

void main() {

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

    int max_ans1, max_ans2;
    foreach (idx; 0 .. nd[1]) {
        bool d_idx = readln.strip.map!(to!char).array.any!(d => d == '0');
        if (d_idx) {
            ++max_ans1;
            if (max_ans1 > max_ans2) {
                max_ans2 = max_ans1;
            }
        } else {
            max_ans1 = 0;
        }
    }

    writeln(max_ans2);
}

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

void main()
{
    auto n = split(strip(readln()));
    auto d = to!int(n[1]);
    int maxi;
    int count;
    foreach (i; 0 .. d)
    {
        auto x = strip(readln());
        if (indexOf(x, '0') >= 0)
            count++;
        else
        {
            maxi = max(maxi, count);
            count = 0;
        }
    }
    maxi = max(maxi, count);
    writeln(maxi);
}

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

void main()
{
    auto n = split(strip(readln()));
    auto d = to!int(n[1]);
    int maxi;
    int count;
    foreach (i; 0 .. d)
    {
        auto x = strip(readln());
        if (indexOf(x, '0') >= 0)
            count++;
        else
        {
            maxi = max(maxi, count);
            count = 0;
        }
    }
    writeln(maxi);
}


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 a = RD;
		auto b = RD;

		ans[ti] = (b - (a % b)) % b;
	}

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

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


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		auto board = new char [] [] (n, m);
		foreach (i, ref line; board)
		{
			foreach (j, ref square; line)
			{
				square = "BW"[i + 1 == n && j + 1 == m];
			}
		}
		writefln !("%-(%s\n%)") (board);
	}
}

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

final class InputReader {
  private:
  ubyte[] p, buffer;
  bool eof;
  bool rawRead () {
    if (eof) {
      return false;
    }
    p = stdin.rawRead (buffer);
    if (p.empty) {
      eof = true;
      return false;
    }
    return true;
  }
  ubyte nextByte(bool check) () {
    static if (check) {
      if (p.empty) {
        if (!rawRead ()) {
          return 0;
        }
      }
    }
    auto r = p.front;
    p.popFront ();
    return r;
  }
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
  }
  bool seekByte (in ubyte lo) {
    while (true) {
      p = p.find! (c => c >= lo);
      if (!p.empty) {
        return false;
      }
      if (!rawRead ()) {
        return true;
      }
    }
  }
  template next(T) if (isSigned!T) {
    T next ()  {
      if (seekByte (45)) {
        return 0;
      }
      T res;
      ubyte b = nextByte!false ();
      if (b == 45) {
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    T next () {
      if (seekByte (48)) {
        return 0;
      }
      T res = nextByte!false () - 48;
      while (true) {
        ubyte b = nextByte!true ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  T[] nextA(T) (in int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  foreach (tid; 0 .. nt) {
    const uint h = r.next!uint ();
    const uint w = r.next!uint ();
    auto a = new char[][](h, w);
    foreach (j; 0 .. h) {
      foreach (i; 0 .. w) {
        if (i || j) write ('B'); else write('W');
      }
      writeln;
    }
  }
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    foreach(_; 0 .. scan!int){
        int n = scan!int, m = scan!int;
        foreach(i; 0 .. n){
            if(i == 0) "W".write;
            else "B".write;
            foreach(j; 0 .. m - 1) "B".write;
            "".writeln;
        }
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new string[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		ans[ti].length = n;
		foreach (y; 0..n-1)
		{
			foreach (x; 0..m-1)
			{
				ans[ti][y] ~= 'W';
			}
			ans[ti][y] ~= 'B';
		}
		foreach (i; 0..m)
		{
			ans[ti][$-1] ~= 'B';
		}
	}

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


import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    foreach(_; 0 .. scan!int){
        long d = scan!long, m = scan!long;
        long u = 1;
        long ans = 0;
        long tmp = 1;
        int i = 0;
        d += 1;
        while(u <= d){
            tmp *= u / 2 + 1, tmp %= m;
            ans += tmp * u, ans %= m;
            i += 1;
            u *= 2;
        }
        ans += m - tmp * (u - d) % m, ans %= m;
        tmp *= u / 2 + 1, tmp %= m;
        ans.print;
    }

}

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

struct ModInt {
  static int M;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op)() const if (op == "-") { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const { return mixin("ModInt(this) " ~ op ~ "= a"); }
  ModInt opBinaryRight(string op)(long a) const { return mixin("ModInt(a) " ~ op ~ "= this"); }
  string toString() const { return x.to!string; }
}

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const D = readLong();
        ModInt.M = readInt();

        ModInt ans = 1;
        for (int e = 0; ; ++e) {
          long lb = 1 << e, ub = 1 << (e + 1);
          chmin(ub, D + 1);
          debug {
            writeln(e, ": ", lb, " ", ub);
          }
          if (lb < ub) {
            ans *= (1 + (ub - lb));
          } else {
            break;
          }
        }
        ans -= 1;
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

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

void main ()
{
	int tests;
	readf !(" %s") (tests);
	foreach (test; 0..tests)
	{
		int d, m;
		readf !(" %s %s") (d, m);

		long res = 1;
		for (long p = 1; p <= d; p <<= 1)
		{
			long hi = min ((p << 1) - 1, d);
			long total = hi - p + 2;
			res = (res * total) % m;
		}
		res = (res + m - 1) % m;
		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;

final class InputReader {
  private:
  ubyte[] p, buffer;
  bool eof;
  bool rawRead () {
    if (eof) {
      return false;
    }
    p = stdin.rawRead (buffer);
    if (p.empty) {
      eof = true;
      return false;
    }
    return true;
  }
  ubyte nextByte(bool check) () {
    static if (check) {
      if (p.empty) {
        if (!rawRead ()) {
          return 0;
        }
      }
    }
    auto r = p.front;
    p.popFront ();
    return r;
  }
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
  }
  bool seekByte (in ubyte lo) {
    while (true) {
      p = p.find! (c => c >= lo);
      if (!p.empty) {
        return false;
      }
      if (!rawRead ()) {
        return true;
      }
    }
  }
  template next(T) if (isSigned!T) {
    T next ()  {
      if (seekByte (45)) {
        return 0;
      }
      T res;
      ubyte b = nextByte!false ();
      if (b == 45) {
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    T next () {
      if (seekByte (48)) {
        return 0;
      }
      T res = nextByte!false () - 48;
      while (true) {
        ubyte b = nextByte!true ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  T[] nextA(T) (in int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  foreach (tid; 0 .. nt) {
    const d = r.next!uint;
    const m = r.next!uint;
    uint add (uint x, uint y) {
      x += y;
      if (x >= m) x -= m;
      return x;
    }
    uint sub (uint x, uint y) {
      if (x < y) x += m;
      x -= y;
      return x;
    }
    uint mul (uint x, uint y) {
      ulong z = x.to!ulong * y;
      return (z % m).to!uint;
    }
    auto deg = new uint[32];
    int last = 1;
    foreach (i; 1 .. 32) {
      uint l = min (d + 1, 1U << i);
      debug stderr.writeln ("l = ", l);
      if (l == last) break;
      uint dt = l - last;
      debug stderr.writeln ("dt = ", dt);
      deg[i] = dt % m;
      last = l;
    }
    debug stderr.writeln (deg);
    auto u = new uint[32];
    u[0] = 1;
    uint res;
    while (u.any!("a != 0")) {
      auto e = new uint[32];
      foreach (i; 0 .. 32) {
        foreach (j; i + 1 .. 32) {
          e[j] = add (e[j], mul (u[i], deg[j]));
        }
      }
      debug stderr.writeln ("e = ", e);
      u = e;
      foreach (i; u) {
        res = add (res, i);
      }
    }
    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;

final class InputReader {
  private:
  ubyte[] p, buffer;
  bool eof;
  bool rawRead () {
    if (eof) {
      return false;
    }
    p = stdin.rawRead (buffer);
    if (p.empty) {
      eof = true;
      return false;
    }
    return true;
  }
  ubyte nextByte(bool check) () {
    static if (check) {
      if (p.empty) {
        if (!rawRead ()) {
          return 0;
        }
      }
    }
    auto r = p.front;
    p.popFront ();
    return r;
  }
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
  }
  bool seekByte (in ubyte lo) {
    while (true) {
      p = p.find! (c => c >= lo);
      if (!p.empty) {
        return false;
      }
      if (!rawRead ()) {
        return true;
      }
    }
  }
  template next(T) if (isSigned!T) {
    T next ()  {
      if (seekByte (45)) {
        return 0;
      }
      T res;
      ubyte b = nextByte!false ();
      if (b == 45) {
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte!true ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    T next () {
      if (seekByte (48)) {
        return 0;
      }
      T res = nextByte!false () - 48;
      while (true) {
        ubyte b = nextByte!true ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  T[] nextA(T) (in int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  foreach (tid; 0 .. nt) {
    const d = r.next!uint;
    const m = r.next!uint;
    uint add (uint x, uint y) {
      x += y;
      if (x >= m) x -= m;
      return x;
    }
    uint sub (uint x, uint y) {
      if (x < y) x += m;
      x -= y;
      return x;
    }
    uint mul (uint x, uint y) {
      ulong z = x.to!ulong * y;
      return (z % m).to!uint;
    }
    auto deg = new uint[32];
    int last = 1;
    foreach (i; 1 .. 32) {
      int l = min (d + 1, 1 << i);
      debug stderr.writeln ("l = ", l);
      int dt = l - last;
      debug stderr.writeln ("dt = ", dt);
      if (dt == 0) break;
      deg[i] = dt % m;
      last = l;
    }
    debug stderr.writeln (deg);
    auto cum = new uint[32];
    cum[0] = 0;
    foreach (i; 1 .. 32) {
      cum[i] = cum[i-1] + deg[i];
    }
    debug stderr.writeln ("cum = ", cum);
    auto u = new uint[32];
    u[0] = 1;
    uint res;
    while (u.any!("a != 0")) {
      auto e = new uint[32];
      foreach (i; 0 .. 32) {
        foreach (j; i + 1 .. 32) {
          e[j] = add (e[j], mul (u[i], deg[j]));
        }
      }
      debug stderr.writeln ("e = ", e);
      u = e;
      foreach (i; u) {
        res = add (res, i);
      }
    }
    writeln (res);
  }
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    foreach(_; 0 .. scan!int){
        long d = scan!long, m = scan!long;
        long u = 1;
        long ans = 0;
        long tmp = 1;
        int i = 0;
        d += 1;
        while(u <= d){
            tmp *= primes[i], tmp %= m;
            ans += tmp * u, ans %= m;
            i += 1;
            u *= 2;
        }
        ans += m - tmp * (u - d) % m, ans %= m;
        tmp *= primes[i], tmp %= m;
        ans.print;
    }

}

long[] primes = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
    53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127,
    131, 137, 139, 149, 151, 157, 163, 167, 173];


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

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }
void chmin(T)(ref T a, in T b) { a = min(a, b); }
void chmax(T)(ref T a, in T b) { a = max(a, b); }

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

void solve() {
    long b, q, y; readf("%d %d %d\n", &b, &q, &y);
    long c, r, z; readf("%d %d %d\n", &c, &r, &z);

    bool check_invalid() {
        if ( (c - b) % q != 0 ) return true; // invalid
        if (r % q != 0) return true;
        if (c - b < 0) return true;
        if (c + r * (z - 1) - b > q * (y - 1)) return true;
        return false;
    }

    bool check_infinite() {
        if (c - r < b) return true;
        if (c + r * z > b + q * (y - 1)) return true;
        return false;
    }

    if (check_invalid()) {
        writeln(0);
    } else if (check_infinite()) {
        writeln(-1);
    } else {
        long ans = 0;
        auto ms = divisors(q);
        foreach (m; ms) {
            long p = r / q * m;
            if (lcm(p, q) != r) continue;
            long s = r / p;
            ans += s * s;
            ans %= mod;
            //writefln("(%s, %s) -> %s", p, q, s);
        }
        writeln(ans);
    }
}

long[] divisors(long x) {
    long[] ret;
    for (long k = 1; k * k <= x; k++) {
        if (x % k == 0) {
            ret ~= k;
            ret ~= x / k;
        }
    }
    return ret.sort.uniq.array;
}
long lcm(long a, long b) {
    return a / gcd(a, b) * b;
}

enum long mod = cast(long)(1e9+7);

// cheese-cracker [2022-05-03]

const long MOD = 1_000_000_007;

void solve(){
    long b = scan; long q = scan;
    long y = scan;

    long c = scan;
    long r = scan;
    long z = scan;

    long lo = c - b;
    long B = b + q*(y-1);
    long C = c + r*(z-1);
    long remb = ((b % q) + q) % q;
    long remc = ((c % q) + q) % q;

    /* show(B, C, B-C); */
    if(r % q != 0 || B < C || lo < 0 || remc != remb){
        writeln(0);
    }else if(lo < r || B < C + r){
        writeln(-1);
    }else{
        long res = 0;
        for(long div = 1; div * div <= q; ++div){
            if(q % div == 0){
                long p  = div * (r / q);
                if(p / gcd(p, q) == r / q){
                    res += (r / p) * (r / p) % MOD;
                    res %= MOD;
                }
                if(div * div != q){
                    p = r / div;
                    if(p / gcd(p, q) == r / q){
                        res += (r / p) * (r / p) % MOD;
                        res %= MOD;
                    }
                }
            }
        }
        writeln(res);
    }
}

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

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm;
import std.container, std.math, std.numeric, std.functional;
string[] tk; alias tup = Tuple!(long, long);
T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }

// cheese-cracker [2022-05-03]

const long MOD = 1_000_000_007;

void solve(){
    long b = scan; long q = scan;
    long y = scan;

    long c = scan;
    long r = scan;
    long z = scan;

    long lo = c - b;
    long B = b + q*y;
    long C = c + r*z;
    long remb = ((b % q) + q) % q;
    long remc = ((c % q) + q) % q;

    /* show(B, C, B-C); */
    if(r % q != 0 || B < C || lo < 0 || remc != remb){
        writeln(0);
    }else if(lo < r || B < C + r){
        writeln(-1);
    }else{
        long res = 0;
        for(long div = 1; div * div <= q; ++div){
            if(q % div == 0){
                long p  = div * (r / q);
                if(p * q == r * gcd(p, q)){
                    res += (r / p) * (r / p) % MOD;
                    res %= MOD;
                }
                if(div * div != q){
                    p = (q/div) * (r/q);
                    if(p * q == r * gcd(p, q)){
                        res += (r / p) * (r / p) % MOD;
                        res %= MOD;
                    }
                }
            }
        }
        writeln(res);
    }
}

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

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm;
import std.container, std.math, std.numeric, std.functional;
string[] tk; alias tup = Tuple!(long, long);
T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }

// cheese-cracker [2022-05-03]

const long MOD = 1_000_000_007;

ll modexp(ll base, ll exp){
    ll x = base % MOD;
    ll y = exp;
    ll res = 1;
    while(y > 0){
        if(y & 1){
            res *= x; res %= MOD;
        }
        x *= x; x %= MOD;
        y >>= 1;
    }
    return res;
}

// Modulo Inverse
ll modinv(ll num){ return modexp(num, MOD-2); }

long[] primes;
void prime_sieve(){
    size_t sz =100_000;
    auto isPrime = new bool[](sz + 1);
    isPrime[] = 1;
    foreach(p; 2..10_000){
        if(isPrime[p]){
            for(int divi = p*p; divi <= sz; divi += p){ isPrime[divi] = 0; }
        }
    }
    primes = isPrime[2..$].enumerate.filter!(a => a[1]).map!(a => (a[0] + 2).to!(long)).array;
}

void solve(){
    long b = scan;
    long q = scan;
    long y = scan;

    long c = scan;
    long r = scan;
    long z = scan;

    long lo = c - b;
    long B = b + q*y;
    long C = c + r*z;
    long remb = ((b % q) + q) % q;
    long remc = ((c % q) + q) % q;

    if(r % q != 0 || B < C || lo < 0 || remc != remb){
        writeln(0);
    }else if(lo < r || B < C + r){
        writeln(-1);
    }else{
        long num = q;
        long res = 1;
        foreach(p; primes){
            long cnt = 1;
            while(num % p == 0){
                num /= p;
                ++cnt;
            }
            res *= ((modexp(p*p, cnt) - 1) + MOD) % MOD;
            res %= MOD;
            res *= modinv(p*p - 1);
            res %=  MOD;
        }
        if(num != 1){
            long p = num;
            res *= (1 + p*p) % MOD;
            res %= MOD;
        }
        writeln(res);
    }
}

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

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; alias tup = Tuple!(long, long);
T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long;

// cheese-cracker [2022-05-03]

const long MOD = 1_000_000_007;

ll modexp(ll base, ll exp){
    ll x = base % MOD;
    ll y = exp;
    ll res = 1;
    while(y > 0){
        if(y & 1){
            res *= x; res %= MOD;
        }
        x *= x; x %= MOD;
        y >>= 1;
    }
    return res;
}

// Modulo Inverse
ll modinv(ll num){ return modexp(num, MOD-2); }

long[] primes;
void prime_sieve(){
    size_t sz =100_000;
    auto isPrime = new bool[](sz + 1);
    isPrime[] = 1;
    foreach(p; 2..10_000){
        if(isPrime[p]){
            for(int divi = p*p; divi <= sz; divi += p){ isPrime[divi] = 0; }
        }
    }
    primes = isPrime[2..$].enumerate.filter!(a => a[1]).map!(a => (a[0] + 2).to!(long)).array;
}

void solve(){
    long b = scan;
    long q = scan;
    long y = scan;

    long c = scan;
    long r = scan;
    long z = scan;

    long lo = c - b;
    long hi = (b + q*y) - (c + r*z);
    long remb = ((b % q) + q) % q;
    long remc = ((c % q) + q) % q;

    if(r % q != 0 || hi < 0 || lo < 0 || remc != remb){
        writeln(0);
    }else if(lo < r || hi < r){
        writeln(-1);
    }else{
        long num = q;
        long res = 1;
        foreach(p; primes){
            long cnt = 1;
            while(num % p == 0){
                num /= p;
                ++cnt;
            }
            res *= ((modexp(p*p, cnt) - 1) + MOD) % MOD;
            res %= MOD;
            res *= modinv(p*p - 1);
            res %=  MOD;
        }
        if(num != 1){
            long p = num;
            res *= (1 + p*p) % MOD;
            res %= MOD;
        }
        writeln(res);
    }
}

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

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; alias tup = Tuple!(long, long);
T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long;

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

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }
void chmin(T)(ref T a, in T b) { a = min(a, b); }
void chmax(T)(ref T a, in T b) { a = max(a, b); }

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

void solve() {
    long b, q, y; readf("%d %d %d\n", &b, &q, &y);
    long c, r, z; readf("%d %d %d\n", &c, &r, &z);

    bool check_invalid() {
        if ( (c - b) % q != 0 ) return true; // invalid
        if (r % q != 0) return true;
        if (c - b < 0) return true;
        if (c + r * (z - 1) - b > q * (y - 1)) return true;
        return false;
    }

    bool check_infinite() {
        if (c - r < b) return true;
        if (c + r * z > b + q * (y - 1)) return true;
        return false;
    }

    if (check_invalid()) {
        writeln(0);
    } else if (check_infinite()) {
        writeln(-1);
    } else {
        long ans = 0;
        auto ms = divisors(q);
        foreach (m; ms) {
            long p = r / q * m;
            long s = r / p;
            ans += s * s;
            ans %= mod;
        }
        writeln(ans);
    }
}

long[] divisors(long x) {
    long[] ret;
    for (long k = 1; k * k <= x; k++) {
        if (x % k == 0) {
            ret ~= k;
            ret ~= x / k;
        }
    }
    return ret.sort.uniq.array;
}

enum long mod = cast(long)(1e9+7);


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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!int;
    auto a = readln.strip.splitter("").map!(to!int).array;
    auto b = readln.strip.splitter("").map!(to!int).array;
    auto cnt1 = a.count(1);
    Tuple!(int, int)[] ans;
    foreach (i ; 0 .. n) {
      if (a[i] == 1) {
        ans ~= tuple(i + 1, i + 1);
      }
      b[i] ^= (cnt1 % 2) ^ a[i];
    }
    auto cnt1b = b.count(1);
    if (cnt1b == 0) {
      writeln("YES");
    } else if (cnt1b == b.length) {
      writeln("YES");
      ans ~= tuple(1, n);
      ans ~= tuple(1, 1);
      ans ~= tuple(2, n);
    } else {
      writeln("NO");
      continue;
    }
    writeln(ans.length);
    foreach (x ; ans) {
      writefln("%d %d", x[0], x[1]);
    }
  }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.strip.map !(q{a - '0'}).array;
		auto b = readln.strip.map !(q{a - '0'}).array;
		int [] [] answer;
		if (a != b)
		{
			answer ~= [0, n];
			a[] = 1 - a[];
		}
		if (a != b)
		{
			writeln ("NO");
			continue;
		}
		writeln ("YES");
		int k = 0;
		foreach (i; 0..n)
		{
			if (a[i])
			{
				answer ~= [i, i + 1];
				k += 1;
			}
		}
		if ((k - 1) % 2 == 0)
		{
			answer ~= [0, n];
			answer ~= [0, 1];
			answer ~= [1, n];
		}
		writeln (answer.length);
		foreach (ref line; answer)
		{
			writeln (line[0] + 1, " ", line[1]);
		}
	}
}


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

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

  foreach (i; 0..t) {
    int a, b;
    readf!"%d %d\n"(a, b);
    auto c = min(max(2*a, b), max(2*b, a));
    writeln(c*c);
  }
}

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

alias type = multi;
struct TestCase
{
  mixin prettyPrinting;

  long a, b;

  void solve(long tc = -1)
  {
    if (a > b)
      swap(a, b);
    writeln(max(2 * a, b) * max(2 * a, b));
  }
}

struct Interval
{
  long l, h;

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

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

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

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

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

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

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

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

DList!string _words;

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

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

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

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

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

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

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

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

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

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

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

    }
}

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

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

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

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

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

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

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

void main()
{
  type;
}

import std.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 a = RD;
		auto b = RD;
		ans[ti] = max(min(a, b)*2, max(a, b))^^2;
	}

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


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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto k = RD!int;
		auto x = new int[](k);
		auto y = new int[](k);
		auto used = new bool[](n*2);
		foreach (i; 0..k)
		{
			x[i] = RD!int-1;
			y[i] = RD!int-1;
			used[x[i]] = true;
			used[y[i]] = true;
		}

		int[] arr;
		foreach (i; 0..n*2)
		{
			if (used[i]) continue;
			arr ~= i;
		}
		foreach (i; 0..n-k)
		{
			x ~= arr[i];
			y ~= arr[n-k+i];
		}
		foreach (i; 0..n)
		{
			foreach (j; i+1..n)
			{
				int[][] tmp = [[x[i], 0], [y[i], 0], [x[j], 1], [y[j], 1]];
				tmp.sort!"a[0] < b[0]";
				if (tmp[0][1] != tmp[1][1] && tmp[1][1] != tmp[2][1])
					++ans[ti];
			}
		}
	}

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

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;
		auto m = n * 2;
		auto p = new int [2] [n];
		auto used = new bool [m];
		foreach (int i, ref c; p[0..k])
		{
			c = readln.splitter.map !(to !(int)).array;
			c[] -= 1;
			foreach (ref x; c)
			{
				used[x] = true;
			}
		}

		int cur = 0;
		foreach (z; 0..2)
		{
			foreach (i; k..n)
			{
				while (used[cur])
				{
					cur += 1;
				}
				used[cur] = true;
				p[i][z] = cur;
			}
		}

		foreach (i; 0..n)
		{
			sort (p[i][]);
		}
		sort (p);
		debug {writeln (p);}

		int res = 0;
		foreach (i; 0..n)
		{
			foreach (j; 0..i)
			{
				if (p[i][0] < p[j][1] && p[j][1] < p[i][1])
				{
					res += 1;
				}
			}
		}

		writeln (res);
	}
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const N = readInt();
        const K = readInt();
        auto X = new int[K];
        auto Y = new int[K];
        foreach (k; 0 .. K) {
          X[k] = readInt() - 1;
          Y[k] = readInt() - 1;
          if (X[k] > Y[k]) {
            swap(X[k], Y[k]);
          }
        }

        auto used = new bool[2 * N];
        foreach (k; 0 .. K) {
          used[X[k]] = true;
          used[Y[k]] = true;
        }
        auto xs = X.dup, ys = Y.dup;
        foreach (u; 0 .. 2 * N) {
          if (!used[u]) {
            ((xs.length < N) ? xs : ys) ~= u;
          }
        }

        int ans;
        foreach (i; 0 .. N) foreach (j; 0 .. N) {
          if (xs[i] < xs[j] && xs[j] < ys[i] && ys[i] < ys[j]) {
            ++ans;
          }
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}


// Vicfred
// https://codeforces.com/contest/1519/problem/C
// data structures, sorting
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.stdio;
import std.string;

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

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

    long[][] universities = new long[][](n);

    for(int i = 0; i < n; ++i) {
        u[i] -= 1;
    }

    for(int i = 0; i < n; ++i) {
        universities[cast(uint)u[i]] ~= s[i];
    }

    for(int i = 0; i < n; ++i) {
        universities[i].sort;
        universities[i].reverse;
    }

    long[][] cumulative = new long[][](n + 1,1);

    for(int i = 0; i < n; i++) {
        foreach(x; universities[i]) {
            cumulative[i] ~= (cumulative[i][$- 1] + x);
        }
    }

    long[] ans = new long[n];
    for(int i = 0; i < n; ++i) {
        for(int k = 1; k <= universities[i].length; k++) {
            ans[k - 1] += cumulative[i][universities[i].length/k*k];
        }
    }
    for(int i = 0; i < n; ++i)
        writef("%s ", ans[i]);
    "".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)); }
double[] rotate(double[] vec, double rad) { return [cos(rad) * vec[0] - sin(rad) * vec[1], sin(rad) * vec[0] + cos(rad) * vec[1]]; }

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

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

		auto list = new long[][](n);
		foreach (i; 0..n)
		{
			list[u[i]] ~= s[i];
		}
		foreach (i; 0..n)
		{
			list[i].sort!"a > b";
		}
		foreach (i; 0..n)
		{
			foreach (j; 1..list[i].length)
			{
				list[i][j] += list[i][j-1];
			}
		}
		debug writeln(list);

		ans[ti].length = n;
		foreach (i; 0..n)
		{
			foreach (j; 0..list[i].length)
			{
				auto rem = list[i].length % (j+1);
				ans[ti][j] += list[i][$-1-rem];
			}
		}
	}

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

// Vicfred
// https://codeforces.com/contest/1519/problem/C
// data structures, sorting
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.stdio;
import std.string;

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

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

    long[][] universities = new long[][](n);

    for(int i = 0; i < n; ++i) {
        u[i] -= 1;
    }

    for(int i = 0; i < n; ++i) {
        universities[cast(uint)u[i]] ~= s[i];
    }

    for(int i = 0; i < n; ++i) {
        universities[i].sort;
        universities[i].reverse;
    }

    long[][] cumulative = new long[][](n + 1,1);

    for(int i = 0; i < n; i++) {
        foreach(x; universities[i]) {
            cumulative[i] ~= (cumulative[i][$- 1] + x);
        }
    }

    int[] ans = new int[n];
    for(int i = 0; i < n; ++i) {
        for(int k = 1; k <= universities[i].length; k++) {
            ans[k - 1] += cumulative[i][universities[i].length/k*k];
        }
    }
    for(int i = 0; i < n; ++i)
        writef("%s ", ans[i]);
    "".writeln;
}
}

// Vicfred
// https://codeforces.com/contest/1519/problem/C
// data structures, sorting
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.stdio;
import std.string;

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

while(t--) {
    int n = readln.chomp.to!int;
    int[] u = readln.split.map!(to!int).array;
    int[] s = readln.split.map!(to!int).array;

    int[][] universities = new int[][](n);

    for(int i = 0; i < n; ++i) {
        u[i] -= 1;
    }

    for(int i = 0; i < n; ++i) {
        universities[u[i]] ~= s[i];
    }

    for(int i = 0; i < n; ++i) {
        universities[i].sort;
        universities[i].reverse;
    }

    long[][] cumulative = new long[][](n + 1,1);

    for(int i = 0; i < n; i++) {
        foreach(x; universities[i]) {
            cumulative[i] ~= (cumulative[i][$- 1] + x);
        }
    }

    int[] ans = new int[n];
    for(int i = 0; i < n; ++i) {
        for(int k = 1; k <= universities[i].length; k++) {
            ans[k - 1] += cumulative[i][universities[i].length/k*k];
        }
    }
    for(int i = 0; i < n; ++i)
        writef("%s ", ans[i]);
    "".writeln;
}
}

// Vicfred
// https://codeforces.com/contest/1519/problem/C
// data structures, sorting
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.stdio;
import std.string;

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

while(t--) {
    int n = readln.chomp.to!int;
    int[] u = readln.split.map!(to!int).array;
    int[] s = readln.split.map!(to!int).array;

    int[][] universities = new int[][](n);

    for(int i = 0; i < n; ++i) {
        u[i] -= 1;
    }

    for(int i = 0; i < n; ++i) {
        universities[u[i]] ~= s[i];
    }

    for(int i = 0; i < n; ++i) {
        universities[i].sort;
        universities[i].reverse;
    }

    int[][] cumulative = new int[][](n + 1,1);

    for(int i = 0; i < n; i++) {
        foreach(x; universities[i]) {
            cumulative[i] ~= (cumulative[i][$- 1] + x);
        }
    }

    int[] ans = new int[n];
    for(int i = 0; i < n; ++i) {
        for(int k = 1; k <= universities[i].length; k++) {
            ans[k - 1] += cumulative[i][universities[i].length/k*k];
        }
    }
    for(int i = 0; i < n; ++i)
        writef("%s ", ans[i]);
    "".writeln;
}
}


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

void main() {
    int n, m;
    readf("%d %d\n", &n, &m);
    string[] x = new string[n];
    foreach (i; 0 .. n) { x[i] = stdin.readln; }
    bool[] f = new bool[n];
    f.fill(false);
    foreach (j; 0 .. m) {
        int mx = 0;
        foreach (i; 0 .. n) {
            mx = max(x[i][j].to!int, mx);
        }
        foreach (i; 0 .. n) {
            if (x[i][j].to!int == mx) {
                f[i] = true;
            }
        }
    }
    writeln(f.count(true));
}

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

void main() {
    int n, m;
    readf("%d %d\n", &n, &m);
    string[] x = new string[n];
    foreach (i; 0 .. n) { x[i] = stdin.readln.chomp; }
    uint[][] y = x.map!(pipe!(map!("a-'0'"), array)).array;
    bool[] f = new bool[n]; f.fill(false);
    foreach (j; 0 .. m) {
        int mx = 0;
        foreach (i; 0 .. n) {
            mx = max(y[i][j], mx);
        }
        foreach (i; 0 .. n) {
            if (y[i][j] == mx) {
                f[i] = true;
            }
        }
    }
    writeln(f.count(true));
}

module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.readInt;
        while (t--) {
                int n = cin.readInt;
                int m = cin.readInt;

                int[][] g = new int[][](n, m);
                string[] mat = new string[n];
                for (int i = 0; i < n; i++) {
                        mat[i] = cin.readString;
                        for (int j = 0; j < m; j++)
                                g[i][j] = mat[i][j] - 48;
                }

                int[] subMax;
                for (int i = 0; i < m; i++) {
                        int maxx = -9999;
                        for (int j = 0; j < n; j++) {
                                maxx = max(maxx, g[j][i]);
                        }
                        subMax ~= maxx;
                }

                int ans = 0;
                int[] best = new int[n];
                for (int i = 0; i < m; i++) {
                        int maxCount = 0;
                        for (int j = 0; j < n; j++) {
                                if (g[j][i] == subMax[i])
                                        best[j] = 1;
                        }
                }
                writeln(best.count(1));
        }
}


import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,
       std.container, std.typecons, std.conv, std.random, std.bigint;

void read(S...)(ref S args) {
  auto input = readln.split;
  assert(input.length == args.length);
  foreach (i, ref arg; args) {
    arg = input[i].to!(S[i]);
  }
}

auto list(T)() { return readln.split.map!(e => e.to!T).array; }

void main() {
  int n;
  read(n);

  while (n--) {
    long q;
    read(q);

    auto t = q / 3;
    auto r = q - 2 * t;

    while (r - t > 1) {
      t++;
      r -= 2;
    }

    writeln(r, " ", t);
  }
}

// Vicfred
// https://codeforces.com/contest/1551/problem/A
// math, greedy
import std.stdio;

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

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

    long c1, c2;
    c1 = n / 3L;
    c2 = n / 3L;

    if(n % 3 == 1) {
        c1 += 1;
    } else if (n % 3 == 2) {
        c2 += 1;
    }

    writefln("%s %s", c1, c2);
}
}

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

void main()
{
	int t = readInt!int;
	while (t--)
	{
		int n = readInt!int;
		if (n % 3 == 0)
		{
			writeln(n/3, " ", n/3);
		}
		else if (n % 3 == 1)
		{
			writeln(n/3+1, " ", n/3);
		}
		else
		{
			writeln(n/3, " ", n/3+1);
		}
	}
}

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

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

void popChar()
{
	currChar = getchar();
}

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

string readString()
{
	string res = "";
	while (topChar.isWhite)
		popChar;
	while (!topChar.isWhite)
	{
		res ~= topChar;
		popChar;
	}
	return res;
}
/**MODULAR SYSTEM*/
struct Z(immutable long m)
{
	long rep;
	this(long num)
	{
		rep = num;
	}

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

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

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

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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long n;
    readf!" %d "(n);
    long c2 = (n + 1) / 3;
    long c1 = n - c2 * 2;
    writefln("%d %d", c1, c2);
  }
}