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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		sort (a);
		auto s = a.group.map !(c => c[1]).array;
		auto hi = s.maxElement;
		auto num = s.count (hi);
		writeln ((n - num) / (hi - 1) - 1);
	}
}

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

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

    while (t--) {
        int n;
        readf("%s", &n);
        readln;

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

        int[int] cnt;
        foreach (e; arr) { cnt[e] += 1; }

        auto rbt = make!(RedBlackTree!(
            Tuple!(int, int),
            "a[1] != b[1] ? a[1] > b[1] : a[0] > b[0]",
            false));
        foreach (k; cnt.keys) {
            //debug { writeln(k, ' ', cnt[k]); }
            rbt.insert(tuple(k, cnt[k]));
        }

        debug { rbt.writeln; }

        bool isOk(int d) {
            auto crbt = rbt.dup;
            int[int] rest;
            int[] arr;
            foreach (i; n.iota) {
                if (i-1 >= d && rest.get(arr[i-1-d], 0) > 0) { crbt.insert(tuple(arr[i-1-d], rest[arr[i-1-d]])); }

                if (crbt.empty()) { return false; }

                auto kv = crbt.front;

                arr ~= kv[0];

                crbt.removeFront();

                rest[kv[0]] = kv[1] - 1;
            }

            return true;
        }

        int le = 0, r = n;
        while (le < r) {
            int m = (le + r) / 2 + 1;
            if (isOk(m)) { le = m; }
            else { r = m - 1; }
        }

        le.writeln;
    }
}

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

alias type = multi;
struct TestCase
{
  mixin prettyPrinting;

  long n;
  @Dim("n") long[] a;

  void solve(long tc = -1)
  {
    long[long] cnt;
    long mx = long.min;
    foreach(ai; a)
      if (++cnt.require(ai, 0) > mx)
        {
          mx = cnt[ai];
        }
    long ts = 0;
    foreach(a, c; cnt)
      {
        if (c == mx)
          {
            ts++;
          }
      }
    writeln((n - ts * mx) / (mx - 1) + (ts - 1));
  }
}

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) { y.modpow(mod - 2); x.modm(y); }

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

		auto cnt = new int[](n);
		foreach (i; 0..n)
		{
			++cnt[a[i]];
		}
		cnt.sort!"a > b";
		int cntcnt = 1;
		foreach (i; 1..n)
		{
			if (cnt[0] != cnt[i]) break;
			++cntcnt;
		}
		ans[ti] = (n-cntcnt) / (cnt[0]-1) - 1;
	}

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


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

Tuple!(int, int) getCenter(int n, int mx, int rw) {
    int x = rw, y = 1 + mx - (n - x);
    return tuple(x, y);
}

bool solve(int n, int m, int mx, int rw, int[] cnt) {
    auto t = getCenter(n, mx, rw);
    int x = t[0], y = t[1];

    if (x < 1 || x > n || y < 1 || y > m) return false;

    auto curcnt = new int[] (n*m);
    curcnt[] = 0;
    foreach (int i; 1 .. n + 1) foreach (int j; 1 .. m + 1) ++curcnt[abs(i-x) + abs(j-y)];

    return curcnt == cnt[0 .. n*m];
}

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

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

    auto cnt = new int[10 ^^ 6 + 1];
    cnt[] = 0;
    arr.each!(x => ++cnt[x]);

    if (t == 1) {
        if (arr[0] == 0) {
            writeln("1 1");
            writeln("1 1");
            return;
        }

        writeln("-1");
        return;
    }

    if (!cnt.dropOne.canFind!(x => x % 4 != 0)) {
        writeln("-1");
        return;
    }

    auto rw = cast(int) cnt.enumerate.dropOne.find!(t => t[1] % 4 != 0).front.index;
    auto mx = arr.maxElement;

    foreach (n; t.iota.dropOne.until!(v => v > t / v)) {
        if (t % n != 0) continue;

        void writeAns(int n, int m) {
            writeln(n, ' ', m);
            auto c = getCenter(n, mx, rw);
            writeln(c[0], ' ', c[1]);
        }

        if (solve(n, t/n, mx, rw, cnt)) {
            writeAns(n, t/n);
            return;
        }
        if (solve(t/n, n, mx, rw, cnt)) {
            writeAns(t/n, n);
            return;
        }
    }

    writeln("-1");
}

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

Tuple!(int, int) getCenter(int n, int mx, int rw) {
    int x = rw, y = 1 + mx - (n - x);
    return tuple(x, y);
}

bool solve(int n, int m, int mx, int rw, int[] cnt) {
    auto t = getCenter(n, mx, rw);
    int x = t[0], y = t[1];

    if (n == 4 && m == 5) debug { t.writeln; }

    if (x < 1 || x > n || y < 1 || y > m) return false;

    auto curcnt = new int[] (n*m);
    curcnt[] = 0;

    foreach (int i; 1 .. n + 1) foreach (int j; 1 .. m + 1) ++curcnt[abs(i-x) + abs(j-y)];

    if (n == 4 && m == 5) debug { curcnt.take(10).writeln; }

    return curcnt == cnt[0 .. n*m];
}

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

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

    auto cnt = new int[10 ^^ 6 + 1];
    cnt[] = 0;
    arr.each!(x => ++cnt[x]);

    debug { cnt.take(10).writeln; }

    if (t == 1) {
        if (arr[0] == 0) {
            writeln("1 1");
            writeln("1 1");
            return;
        }

        writeln("-1");
        return;
    }

    if (!cnt.dropOne.canFind!(x => x % 4 != 0)) {
        writeln("-1");
        return;
    }

    debug { cnt.enumerate.dropOne.take(10).writeln; }

    auto rw = cast(int) cnt.enumerate.dropOne.find!(t => t[1] % 4 != 0).front.index;
    auto mx = arr.maxElement;

    foreach (n; t.iota.dropOne.until!(v => v > t / v)) {
        if (t % n != 0) continue;

        debug { n.writeln; }

        void writeAns(int n, int m) {
            writeln(n, ' ', m);
            auto c = getCenter(n, mx, rw);
            writeln(c[0], ' ', c[1]);
        }

        if (solve(n, t/n, mx, rw, cnt)) {
            writeAns(n, t/n);
            return;
        }
        if (solve(t/n, n, mx, rw, cnt)) {
            writeAns(t/n, n);
            return;
        }
    }

    writeln("-1");
}

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

Tuple!(int, int) getCenter(int n, int mx, int rw) {
    int x = rw, y = 1 + mx - (n - x);
    return tuple(x, y);
}

bool solve(int n, int m, int mx, int rw, int[] cnt) {
    auto t = getCenter(n, mx, rw);
    int x = t[0], y = t[1];

    if (n == 4 && m == 5) debug { t.writeln; }

    if (x < 1 || x > n || y < 1 || y > m) return false;

    auto curcnt = new int[] (n*m);
    curcnt[] = 0;

    foreach (int i; 1 .. n + 1) foreach (int j; 1 .. m + 1) ++curcnt[abs(i-x) + abs(j-y)];

    if (n == 4 && m == 5) debug { curcnt.take(10).writeln; }

    return curcnt == cnt[0 .. n*m];
}

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

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

    auto cnt = new int[10 ^^ 6 + 1];
    cnt[] = 0;
    arr.each!(x => ++cnt[x]);

    debug { cnt.take(10).writeln; }

    if (!cnt.dropOne.canFind!(x => x % 4 != 0)) {
        writeln("-1");
        return;
    }

    debug { cnt.enumerate.dropOne.take(10).writeln; }

    auto rw = cast(int) cnt.enumerate.dropOne.find!(t => t[1] % 4 != 0).front.index;
    auto mx = arr.maxElement;

    foreach (n; t.iota.dropOne.until!(v => v > t / v)) {
        if (t % n != 0) continue;

        debug { n.writeln; }

        void writeAns(int n, int m) {
            writeln(n, ' ', m);
            auto c = getCenter(n, mx, rw);
            writeln(c[0], ' ', c[1]);
        }

        if (solve(n, t/n, mx, rw, cnt)) {
            writeAns(n, t/n);
            return;
        }
        if (solve(t/n, n, mx, rw, cnt)) {
            writeAns(t/n, n);
            return;
        }
    }

    writeln("-1");
}


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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto n = RD!int;
	auto q = RD!int;
	auto k = RD!int;
	auto a = RDA;
	auto w = new long[](n);
	a = 0L ~ a ~ (k+1L);
	foreach (i; 0..n)
	{
		w[i] += a[i+1] - a[i] - 1;
		w[i] += a[i+2] - a[i+1] - 1;
	}
	auto ww = new long[](n+1);
	foreach (i; 0..n)
	{
		ww[i+1] = ww[i] + w[i];
	}
	debug writeln("ww:", ww);

	auto ans = new long[](q);
	foreach (i; 0..q)
	{
		auto l = RD!int-1;
		auto r = RD!int-1;
		ans[i] = a[l] + a[$-1] - a[r+2];
		debug writeln("a[l]:", a[l] , " a[r+2]:", a[r+2] );
		ans[i] += ww[r+1] - ww[l];
		debug writeln("ww[r]:", ww[r+1], " ww[l]:", ww[l]);
	}

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

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

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

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

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

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

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

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

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

void main()
{
    int N, Q; long K; get(N, Q, K);
    long[] aa; get(aa);
    auto cs = new long[](N);
    foreach (i; 1..N-1) cs[i] = cs[i-1] + aa[i+1] - aa[i-1] - 2;

    while (Q--) {
        int l, r; get(l, r); --l; --r;
        writeln(l == r ? K-1 : aa[l+1] - 2 + K - aa[r-1] - 1 + cs[r-1] - cs[l]);
    }
}

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

void main ()
{
	int n, q, k;
	while (readf !(" %s %s %s") (n, q, k) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		a = 0 ~ a ~ (k + 1);
		foreach (s; 0..q)
		{
			int l, r;
			readf !(" %s %s") (l, r);
			int res = a[l];
			res += k - a[r] - 1;
			res += 2 * (a[r] - a[l] - r + l);
			writeln (res);
		}
	}
}

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

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

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

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

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

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

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

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

void main()
{
    int N, Q; long K; get(N, Q, K);
    long[] aa; get(aa);
    auto cs = new long[](N);
    foreach (i; 1..N-1) cs[i] = cs[i-1] + aa[i+1] - aa[i-1] - 2;

    while (Q--) {
        int l, r; get(l, r); --l; --r;
        writeln(aa[l+1] - 2 + K - aa[r-1] - 1 + cs[r-1] - cs[l]);
    }
}

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

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

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

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

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

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

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

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

void main()
{
    int N, Q, K; get(N, Q, K);
    int[] aa; get(aa);
    auto cs = new long[](N);
    foreach (i; 1..N-1) {
        cs[i] = cs[i-1];
        cs[i] += aa[i+1] - aa[i-1] - 2;
    }

    while (Q--) {
        int l, r; get(l, r); --l; --r;
        writeln(aa[l+1] - 2 + K - aa[r-1] - 1 + cs[r-1] - cs[l]);
    }
}


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

bool isSquare (int n)
{
	auto p = cast (int) (sqrt (n * 1.0) + 0.5);
	return p * p == n;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		while (true)
		{
			if (n & 1)
			{
				writeln ("NO");
				break;
			}
			n /= 2;
			if (isSquare (n))
			{
				writeln ("YES");
				break;
			}
		}
	}
}

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

		if (n % 2) continue;
		for (long i = 1; i*i <= n; ++i)
		{
			if (n % i) continue;
			if (i*i*2 == n || i*i*4 == n)
			{
				ans[ti] = true;
			}
		}
	}

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

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

void main()
{
	int t = readInt!int;
	while (t--)
	{
		long n = readInt!int;
		bool isSquare(long q) { long r = cast(long) sqrt(cast(real)q); return r * r == q; }
		bool can = only(2, 4).any!(d => n % d == 0 && isSquare(n/d));
		if (can) "YES".writeln; else "NO".writeln;
	}
}

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

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

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

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

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

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

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

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

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

bool isSquare (int n)
{
	auto p = cast (int) (sqrt (n * 1.0) + 0.5);
	return p * p == n;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		foreach (j; 0..2)
		{
			if (n & 1)
			{
				writeln ("NO");
				break;
			}
			n /= 2;
			if (isSquare (n))
			{
				writeln ("YES");
				break;
			}
		}
	}
}

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

		if (n == 1) continue;
		ans[ti] = popcnt(n) == 1;
	}

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


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

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

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

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

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

bool check(int y0, int y1) {
  foreach (x; 0 .. M) {
    int cnt;
    foreach (y; 0 .. N) {
      const a = A[x][(y == y0) ? y1 : (y == y1) ? y0 : y];
      if (a != y) {
        ++cnt;
      }
    }
    if (cnt > 2) {
      return false;
    }
  }
  debug {
    writeln("ok ", y0, " ", y1);
  }
  return true;
}

bool solve() {
  if (check(-1, -1)) {
    return true;
  }
  foreach (y0; 0 .. N) foreach (y1; y0 + 1 .. N) {
    if (check(y0, y1)) {
      return true;
    }
  }
  return false;
}

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

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

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

__gshared:

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

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

int n, m;
int[20][20] a;

bool check(const(int)[ ] where) {
    debug writeln(where);
    int[20][20] b = a;
    foreach (ref line; b[0 .. n]) {
        bool swapped = false;
    again:
        debug writeln("Line: ", line[0 .. m]);
        foreach (i; 0 .. m) {
            const what = line[i] - 1;
            debug writeln(i, ' ', what, ' ', where[what], ' ', i);
            if (where[what] != i) {
                if (swapped)
                    return false;
                foreach (j; 0 .. m)
                    if (where[line[j] - 1] == i) {
                        swap(line[i], line[j]);
                        debug writefln("Swapped %d and %d", i, j);
                        swapped = true;
                        goto again;
                    }
            }
        }
    }
    return true;
}

void main() {
    while (read(&n, &m)) {
        int[20] _trg;
        int[ ] trg = _trg[0 .. m];
        foreach (i; 0 .. m)
            trg[i] = i;
        foreach (ref line; a[0 .. n])
            foreach (ref x; line[0 .. m])
                read(&x);
        foreach (i; 0 .. n) {
            foreach (j; 0 .. m)
                debug write(a[i][j], ' ');
            debug writeln();
        }
        if (check(trg))
            write("YES\n");
        else {
            foreach (i, ref x; trg)
                foreach (ref y; trg[i + 1 .. m]) {
                    swap(x, y);
                    if (check(trg)) {
                        write("YES\n");
                        goto nextCase;
                    }
                    swap(x, y);
                }
            write("NO\n");
        }
    nextCase:
        ;
    }
}


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

immutable long MOD = 10^^9+7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto p = s[1];
    auto S = readln.chomp.to!(dchar[]);

    bool ans = false;

    for (int i = 0; i + p < N; ++i) {
        int j = i + p;
        if (S[i] == '.') {
            ans = true;
            if (S[i] == S[j]) {
                S[i] = '0';
                S[j] = '1';
            } else {
                S[i] = S[j] == '0' ? '1' : '0';
            }
        } else if (S[j] == '.') {
            ans = true;
            S[j] = S[i] == '0' ? '1' : '0';
        } else if (S[i] == '0' && S[j] == '1') {
            ans = true;
        } else if (S[i] == '1' && S[j] == '0') {
            ans = true;
        }
    }

    if (ans) {
        foreach (i; 0..N) if (S[i] == '.') S[i] = '0';
        S.writeln;
    } else {
        writeln("No");
    }
}

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

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

    auto a = readln.chomp.to!(dchar[]);
    auto b = a.dup;
    foreach (ref e; b) if (e == '.') e = '0';

    auto c = b.dup;
    auto pos = a.indexOf('.');
    if (pos != -1) c[pos] = '1';

    auto d = b.dup;
    pos = a.lastIndexOf('.');
    if (pos != -1) d[pos] = '1';

    debug { b.writeln; c.writeln; d.writeln; }

    bool check(const dchar[] s, immutable int p) {
        foreach (st; 0..p) {
            auto sq = s.drop(st).stride(p);
            foreach (a, b; lockstep(sq, sq.dropOne)) {
                if (a != b) return true;
            }
        }
        return false;
    }

    writeln(check(b, p) ? b : check(c, p) ? c : check(d, p) ? d : "No");
}

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

immutable long MOD = 10^^9+7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto p = s[1];
    auto S = readln.chomp.to!(dchar[]);

    bool ans = false;

    for (int i = 0; i + p < N; ++i) {
        int j = i + p;
        if (S[i] == '.') {
            ans = true;
            if (S[i] == S[j]) {
                S[i] = '0';
                S[j] = '1';
            } else {
                S[i] = S[j] == '0' ? '1' : '0';
            }
        } else if (S[j] == '.') {
            ans = true;
            S[j] = S[i] == '0' ? '1' : '0';
        } else if (S[i] == '0' && S[j] == '1') {
            ans = true;
        } else if (S[i] == '1' && S[j] == '0') {
            ans = true;
        }
    }

    if (ans) {
        writeln("Yes");
        foreach (i; 0..N) if (S[i] == '.') S[i] = '0';
        S.writeln;
    } else {
        writeln("No");
    }
}

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

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

    auto a = readln.chomp.to!(dchar[]);
    auto b = a.dup;
    foreach (ref e; b) if (e == '.') e = '0';

    auto c = b.dup;
    auto pos = a.lastIndexOf('.');
    if (pos != -1) c[pos] = '1';

    debug { b.writeln; c.writeln; }

    bool check(const dchar[] s, immutable int p) {
        foreach (st; 0..p) {
            auto sq = s.drop(st).stride(p);
            foreach (a, b; lockstep(sq, sq.dropOne)) {
                if (a != b) return true;
            }
        }
        return false;
    }

    writeln(check(b, p) ? b : check(c, p) ? c : "No");
}

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

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

    auto a = readln.chomp.to!(dchar[]);
    auto b = a.dup;
    foreach (ref e; b) if (e == '.') e = '0';

    auto c = b.dup;
    auto pos = a.indexOf('.');
    if (pos != -1) c[pos] = '1';

    debug { b.writeln; c.writeln; }

    bool check(const dchar[] s, immutable int p) {
        foreach (st; 0..p) {
            auto sq = s.drop(st).stride(p);
            foreach (a, b; lockstep(sq, sq.dropOne)) {
                if (a != b) return true;
            }
        }
        return false;
    }

    writeln(check(b, p) ? b : check(c, p) ? c : "No");
}


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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    long n;
    readf!" %d "(n);
    auto a = readln.splitter.array;
    string ans = a[0];
    string missing;
    int[] candel;
    foreach (x ; a[1 .. $]) {
      if (ans[$ - 1] == x[0]) {
        ans ~= x[1];
      } else if (missing == "") {
        missing ~= ans[$ - 1];
        missing ~= x[0];
        ans ~= missing[1];
        ans ~= x[1];
      } else {
        assert(false);
      }
    }
    if (missing == "") {
      ans ~= ans[$ - 1];
    }
    assert(n == ans.length);
    writeln(ans);
  }
}

immutable multi = true;

void solve(int tc)
{
  auto n = readInt!int;
  auto s = ma(n - 2, cast(byte[])readString);
  byte[] word;
  word ~= s[0][0];
  bool incident = false;
  foreach(i; 1 .. n - 2)
    {
      word ~= s[i-1][1];
      if (s[i][0] != s[i-1][1]) { assert(!incident); word ~= s[i][0]; incident = true; }
    }
  word ~= s[$-1][1];
  if (!incident) word ~= s[$-1][1];
  (cast(string)word).writeln;
}

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

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

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

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

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

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

void solve(){
    long n = scan;
    dchar[][] arr;
    for(int i = 0; i < n-2; ++i){
        arr ~= scan!(dchar[]);
    }
    show(arr);
    dchar[] w;
    w ~= arr[0];
    bool f = 0;
    for(int i = 1; i < n - 2; ++i){
        if(w.back == arr[i][0]){
            w ~= arr[i][1];
        }else{
            f = 1;
            w ~= arr[i];
        }
    }
    if(!f){
        w ~= 'a';
    }
    writeln(w);
}

void main(){
    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; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");


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

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

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

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

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const R = readReal();
      auto X = new real[N];
      foreach (i; 0 .. N) {
        X[i] = readReal();
      }

      auto ans = new real[N];
      foreach (i; 0 .. N) {
        ans[i] = R;
        foreach (j; 0 .. i) {
          const dx = X[j] - X[i];
          if (dx <= 2 * R) {
            chmax(ans[i], ans[j] + sqrt((2 * R)^^2 - dx^^2));
          }
        }
      }

      foreach (i; 0 .. N) {
        if (i > 0) write(" ");
        writef("%.12f", ans[i]);
      }
      writeln();
    }
  } catch (EOFException e) {
  }
}

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

void main() {
    int n,r;
    scan(n,r);

    auto x = readln.split.to!(int[]);
    auto y = new double[](n);
    y[0] = r;

    foreach (i ; 1 .. n) {
        foreach (j ; 0 .. i) {
            if ((x[j] - x[i])^^2 <= 4*r*r) {
                real yi = y[j] + sqrt(4.0*r*r - pow(x[i] - x[j], 2));

                debug {
                    writeln(yi);
                }

                if (y[i].isNaN) {
                    y[i] = yi;
                }
                else if (yi > y[i]) {
                    y[i] = yi;
                }
            }
        }

        if (y[i].isNaN) {
            y[i] = r;
        }
    }

    writefln("%(%.8f %)", y);
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio      : readln, writeln, write, writef;
import std.string     : chomp;
import std.array      : split;
import std.conv       : to;
import std.algorithm  : min, max;
import std.math       : sqrt;

auto getVals(T)() {
    return readln.chomp.split.to!(T[]);
}

void main() {
    auto nr = getVals!int;
    auto n = nr[0], r = nr[1];
    auto ds = getVals!int;
    auto ans = new double[n];
    auto ps = new int[1001];
    auto rf = double(r);
    for (int i = 0; i < 1001; i++) { ps[i] = -1; }
    for (int i = 0; i < n; i++) {
        auto x = ds[i];
        auto lx = max(0, x - r);
        auto rx = min(1000, x + r);
        auto y = rf;
        for (int j = lx; j <= rx; j++) {
            if (ps[j] < 0) { continue; }
            auto pk = ps[j];
            auto px = ds[pk];
            auto ty = (rf+rf)*(rf+rf)-double(px-x)*double(px-x);
            if (ty < 0.0) { continue; }
            y = max(y, ans[pk] + sqrt(ty));
        }
        for (int j = lx; j <= rx; j++) {
            ps[j] = i;
        }
        ans[i] = y;
    }
    for (int i = 0; i < n; i++) {
        if (i > 0) { write(" "); }
        writef("%0.10f", ans[i]);
    }
    writeln();
}

/*
def gs() gets.strip end
def gss() gs.split end
def gis() gss.map &:to_i end
def gfs() gss.map &:to_f end

N, R = gis
DS = gis
Rf = R.to_f
ps = [-1] * 1001
ans = []
DS.each_with_index do |x,i|
    lx = [0, x - R].max
    rx = [1000, x + R].min
    y = Rf
    (lx..rx).each do |j|
        next if ps[j] < 0
        pk = ps[j]
        px = DS[pk]
        ty = (Rf+Rf)**2-(px-x).to_f**2
        next if ty < 0.0
        y = [y, ans[pk]+ty**0.5].max
    end
    (lx..rx).each do |j| ps[j] = i end
    ans << y
end

puts ans*' '

*/

/+ dub.sdl:
    name "C"
    dependency "dunkelheit" version=">=0.9.0"
+/

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

immutable double EPS = 1e-9;
int main() {
    Scanner sc = new Scanner(stdin);
    scope(exit) sc.read!true;

    int n;
    double r;
    sc.read(n, r);
    double[] x;
    sc.read(x);
    double[] y = new double[n];

    r *= 2;
    foreach (i; 0..n) {
        double pos = r/2;
        foreach (j; 0..i) {
            double di = abs(x[i]-x[j]);
            if (di > r + EPS) continue;
            double z = sqrt(max(0.0, r*r - di*di));
            pos = max(pos, y[j] + z);
        }
        y[i] = pos;
        writef("%.20f ", y[i]);
    }
    writeln;
    return 0;
}
/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;

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

    private T* _data;
    private uint len, cap;

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

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

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

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

    void clear() {
        len = 0;
    }

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

/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/foundation.d */

// module dkh.foundation;

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

}
/* IMPORT /Users/yosupo/Program/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;

// import dkh.container.stackpayload;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

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

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

    int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
    void read(bool enforceEOF = false, T, Args...)(ref T x, auto ref Args args) {
        import std.exception;
        enforce(readSingle(x));
        static if (args.length == 0) {
            enforce(enforceEOF == false || !succ());
        } else {
            read!enforceEOF(args);
        }
    }
    void read(bool enforceEOF = false, Args...)(auto ref Args args) {
        import std.exception;
        static if (args.length == 0) {
            enforce(enforceEOF == false || !succ());
        } else {
            enforce(readSingle(args[0]));
            read!enforceEOF(args);
        }
    }
}

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

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

void main ()
{
	int n;
	real r;
	while (readf (" %s %s", &n, &r) > 0)
	{
		readln;
		r *= 2;
		auto x = readln.splitter.map !(to !(real)).array;
		real [] y;
		foreach (i; 0..n)
		{
			auto res = r * 0.5;
			foreach (j; 0..i)
			{
				auto d = abs (x[i] - x[j]);
				if (d <= r)
				{
					auto cur = sqrt (r ^^ 2 - d ^^ 2);
					res = max (res, y[j] + cur);
				}
			}
			y ~= res;
		}
		writefln ("%(%.20g %)", y);
	}
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio      : readln, writeln, write, writef;
import std.string     : chomp;
import std.array      : split;
import std.conv       : to;
import std.algorithm  : min, max;
import std.math       : sqrt;

auto getVals(T)() {
    return readln.chomp.split.to!(T[]);
}

void main() {
    auto nr = getVals!int;
    auto n = nr[0], r = nr[1];
    auto ds = getVals!int;
    auto ans = new double[n];
    auto ps = new int[1001];
    auto rf = double(r);
    for (int i = 0; i < 1001; i++) { ps[i] = -1; }
    for (int i = 0; i < n; i++) {
        auto x = ds[i];
        auto lx = max(0, x - r);
        auto rx = min(1000, x + r);
        auto y = rf;
        for (int j = lx; j <= rx; j++) {
            if (ps[j] < 0) { continue; }
            auto pk = ps[j];
            auto px = ds[pk];
            auto ty = rf*rf*rf*rf-double(px-x)*double(px-x);
            if (ty < 0.0) { continue; }
            y = max(y, ans[pk] + sqrt(ty));
        }
        for (int j = lx; j <= rx; j++) {
            ps[j] = i;
        }
        ans[i] = y;
    }
    for (int i = 0; i < n; i++) {
        if (i > 0) { write(" "); }
        writef("%0.10f", ans[i]);
    }
    writeln();
}

/*
def gs() gets.strip end
def gss() gs.split end
def gis() gss.map &:to_i end
def gfs() gss.map &:to_f end

N, R = gis
DS = gis
Rf = R.to_f
ps = [-1] * 1001
ans = []
DS.each_with_index do |x,i|
    lx = [0, x - R].max
    rx = [1000, x + R].min
    y = Rf
    (lx..rx).each do |j|
        next if ps[j] < 0
        pk = ps[j]
        px = DS[pk]
        ty = (Rf+Rf)**2-(px-x).to_f**2
        next if ty < 0.0
        y = [y, ans[pk]+ty**0.5].max
    end
    (lx..rx).each do |j| ps[j] = i end
    ans << y
end

puts ans*' '

*/


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

bool less (string s, string t)
{
	if (s.length != t.length)
	{
		return s.length < t.length;
	}
	return s < t;
}

string normalize (string s)
{
	int [] a;
	foreach_reverse (c; s)
	{
		a ~= c - '0';
	}
	a ~= 0.repeat (a.length + 10).array;
	bool ok = false;
	while (!ok)
	{
		ok = true;
		foreach_reverse (i; 0..a.length - 2)
		{
			int e = a[i] / 2;
			if (e > 0)
			{
				assert (i >= 2);
				ok = false;
				a[i] -= 2 * e;
				a[i - 2] += e;
				a[i + 1] += e;
			}
			int d = min (a[i], a[i + 1]);
			if (d > 0)
			{
				ok = false;
				a[i + 2] += d;
				a[i] -= d;
				a[i + 1] -= d;
			}
		}
		foreach (i; 0..a.length - 2)
		{
			int e = a[i] / 2;
			if (e > 0)
			{
				assert (i >= 2);
				ok = false;
				a[i] -= 2 * e;
				a[i - 2] += e;
				a[i + 1] += e;
			}
			int d = min (a[i], a[i + 1]);
			if (d > 0)
			{
				ok = false;
				a[i + 2] += d;
				a[i] -= d;
				a[i + 1] -= d;
			}
		}
	}

	while (a.length > 1 && a[$ - 1] == 0)
	{
		a.length--;
	}
	reverse (a);
	return format ("%(%s%)", a);
}

void main ()
{
	string s;
	while (!(s = readln.strip).empty)
	{
		string t = readln.strip;
		s = normalize (s);
		t = normalize (t);
		debug {writeln (s, ' ', t);}
		writeln (less (s, t) ? '<' : less (t, s) ? '>' : '=');
	}
}

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

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

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

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

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

int[] reduce(string s, int n) {
	int[] ret = new int[n];
	foreach (i; 0 .. s.length) {
		ret[n - s.length + i] = s[i] - '0';
	}
	foreach (_; 0 .. 20) {
		foreach_reverse (i; 0 .. n - 2) {
			const tmp = min(ret[i + 1], ret[i + 2]);
			ret[i] += tmp;
			ret[i + 1] -= tmp;
			ret[i + 2] -= tmp;
		}
		foreach (i; 0 .. n - 3) {
			if (ret[i + 1] > 1) {
				ret[i] += 1;
				ret[i + 1] -= 2;
				ret[i + 3] += 1;
			}
		}
	}
	return ret;
}

string A, B;

void main(string[] args) {
	try {
	for (; ; ) {
		A = readToken;
		B = readToken;

		const int n = max(A.length, B.length) + 1;
		auto as = A.reduce(n);
		auto bs = B.reduce(n);
debug{
writeln(as);
writeln(bs);
}

		int ans;
		/*
		foreach (i; 0 .. n) {
			if (as[i] != bs[i]) {
				ans = (as[i] < bs[i]) ? -1 : +1;
				break;
			}
		}
		*/
		/*
		foreach (i; 0 .. n) {
			if (as[i] < bs[i]) {
				if (i < n - 2 && as[i + 1] && as[i + 2]) {
					--bs[i];
					--as[i + 1];
					--as[i + 2];
				} else {
					ans = -1;
					break;
				}
			}
			if (as[i] > bs[i]) {
				if (i < n - 2 && bs[i + 1] && bs[i + 2]) {
					--as[i];
					--bs[i + 1];
					--bs[i + 2];
				} else {
					ans = +1;
					break;
				}
			}
		}
		*/
		ans = (as < bs) ? -1 : (as > bs) ? +1 : 0;
		writeln("<=>"[1 + ans]);

	}
	} catch (EOFException) {}
}

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

bool less (string s, string t)
{
	if (s.length != t.length)
	{
		return s.length < t.length;
	}
	return s < t;
}

string normalize (string s)
{
	int [] a;
	foreach_reverse (c; s)
	{
		a ~= c - '0';
	}
	a ~= 0.repeat (a.length).array;
	int i = 0;
	while (i < a.length)
	{
		if (a[i] >= 2)
		{
			assert (i >= 2);
			a[i] -= 2;
			a[i - 2]++;
			a[i + 1]++;
			i -= 2;
			continue;
		}
		int d = min (a[i], a[i + 1]);
		if (d > 0)
		{
			a[i + 2] += d;
			a[i] -= d;
			a[i + 1] -= d;
		}
		i++;
	}

	while (a.length > 1 && a[$ - 1] == 0)
	{
		a.length--;
	}
	reverse (a);
	return format ("%(%s%)", a);
}

void main ()
{
	string s;
	while (!(s = readln.strip).empty)
	{
		string t = readln.strip;
		s = normalize (s);
		t = normalize (t);
		writeln (less (s, t) ? '<' : less (t, s) ? '>' : '=');
	}
}

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

bool less (string s, string t)
{
	if (s.length != t.length)
	{
		return s.length < t.length;
	}
	return s < t;
}

string normalize (string s)
{
	int [] a;
	foreach_reverse (c; s)
	{
		a ~= c - '0';
	}
	a ~= 0.repeat (a.length + 10).array;
	int i = 0;
	while (i < a.length - 2)
	{
		if (a[i] >= 2)
		{
			assert (i >= 2);
			a[i] -= 2;
			a[i - 2]++;
			a[i + 1]++;
			i -= 2;
			continue;
		}
		int d = min (a[i], a[i + 1]);
		a[i + 2] += d;
		a[i] -= d;
		a[i + 1] -= d;
		i++;
	}

	while (a.length > 1 && a[$ - 1] == 0)
	{
		a.length--;
	}
	reverse (a);
	return format ("%(%s%)", a);
}

void main ()
{
	string s;
	while (!(s = readln.strip).empty)
	{
		string t = readln.strip;
		s = normalize (s);
		t = normalize (t);
		writeln (less (s, t) ? '<' : less (t, s) ? '>' : '=');
	}
}

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

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

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

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

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

int[] reduce(string s, int n) {
	int[] ret = new int[n];
	foreach (i; 0 .. s.length) {
		ret[n - s.length + i] = s[i] - '0';
	}
	/*
	foreach_reverse (i; 0 .. n - 2) {
		const tmp = min(ret[i + 1], ret[i + 2]);
		ret[i] += tmp;
		ret[i + 1] -= tmp;
		ret[i + 2] -= tmp;
	}
	*/
	return ret;
}

string A, B;

void main(string[] args) {
	try {
	for (; ; ) {
		A = readToken;
		B = readToken;

		const int n = max(A.length, B.length) + 1;
		auto as = A.reduce(n);
		auto bs = B.reduce(n);
debug{
writeln(as);
writeln(bs);
}

		int ans;
		/*
		foreach (i; 0 .. n) {
			if (as[i] != bs[i]) {
				ans = (as[i] < bs[i]) ? -1 : +1;
				break;
			}
		}
		*/
		foreach (i; 0 .. n) {
			if (as[i] < bs[i]) {
				if (i < n - 2 && as[i + 1] && as[i + 2]) {
					--bs[i];
					--as[i + 1];
					--as[i + 2];
				} else {
					ans = -1;
					break;
				}
			}
			if (as[i] > bs[i]) {
				if (i < n - 2 && bs[i + 1] && bs[i + 2]) {
					--as[i];
					--bs[i + 1];
					--bs[i + 2];
				} else {
					ans = +1;
					break;
				}
			}
		}
		writeln("<=>"[1 + ans]);

	}
	} catch (EOFException) {}
}

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

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

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

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

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

char[] reduce(string s, int n) {
	char[] ret = new char[n];
	ret[] = '0';
	foreach (i; 0 .. s.length) {
		ret[n - s.length + i] = s[i];
	}
	foreach (i; 0 .. n - 2) {
		if (ret[i + 1] == '1' && ret[i + 2] == '1') {
			ret[i] = '1';
			ret[i + 1] = '0';
			ret[i + 2] = '0';
		}
	}
	return ret;
}

string A, B;

void main(string[] args) {
	try {
	for (; ; ) {
		A = readToken;
		B = readToken;

		const int n = max(A.length, B.length) + 1;
		char[] as = A.reduce(n);
		char[] bs = B.reduce(n);
debug{
writeln(as);
writeln(bs);
}

		int ans;
		foreach (i; 0 .. n) {
			if (as[i] != bs[i]) {
				ans = (as[i] < bs[i]) ? -1 : +1;
				break;
			}
		}
		writeln("<=>"[1 + ans]);

	}
	} catch (EOFException) {}
}


import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,
std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
immutable int mod=1000000007;
@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)
{
	return a/gcd(a,b)*b;
}
pure nothrow @property X binpow(X,Y)(X base,Y exp)
if(is(typeof(exp&1)))
{
	if(exp<0)return X(0);
	X res=X(1);
	while(exp>0)
	{
		if(exp&1)res*=base;
		base*=base;
		exp>>=1;
	}
	return res;
}
pure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
if(is(typeof(exp&1)))
{
	if(mm==0) return binpow(base,exp);
	if(exp<0)return X(0);
	auto res=X(1)%mm;
	while(exp>0)
	{
		if(exp&1)res=(res*base)%mm;
		base*=base;
		base%=mm;
		exp>>=1;
	}
	return res;
}
@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
@property void putarr(X)(X a,in int n,in int m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))
	{
		fi=p.fi;
		se=p.se;
	}
	int opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
X sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}
X cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}
nothrow @nogc @system void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow @nogc @system void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
auto arread(T)(){return readln.split.map!(to!(T)).array;}
nothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (!(a[l]<g))?l:r;
}
pure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(g<a[m])r=m;
		else l=m;
	}
	return (g<a[l])?l:r;
}
pure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (g==a[l])?l:a.length;
}
pure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	return binf(a,g)!=a.length;
}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int n;
	while(input(&n))
	{
		if(n%4!=0){writeln("===");return;}
		readln;
		auto s=readln.strip;
		int[4] d;
		d[0]=s.count('A');
		d[1]=s.count('C');
		d[2]=s.count('G');
		d[3]=s.count('T');
		debug foreach(i;d)writeln(i);
		if(max(d[0],d[1],d[2],d[3])>n/4){writeln("===");return;}
		foreach(i;s)
		{
			if(i!='?')write(i);
			else if(d[0]<n/4)
			{
				write('A');
				d[0]++;
			}
			else if(d[1]<n/4)
			{
				write('C');
				d[1]++;
			}
			else if(d[2]<n/4)
			{
				write('G');
				d[2]++;
			}
			else if(d[3]<n/4)
			{
				write('T');
				d[3]++;
			}
		}
		writeln;
	}
	debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,
std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio:freopen;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
immutable int mod=1000000007;
@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)
{
	return a/gcd(a,b)*b;
}
pure nothrow @property X binpow(X,Y)(X base,Y exp)
if(is(typeof(exp&1)))
{
	if(exp<0)return X(0);
	X res=X(1);
	while(exp>0)
	{
		if(exp&1)res*=base;
		base*=base;
		exp>>=1;
	}
	return res;
}
pure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
if(is(typeof(exp&1)))
{
	if(mm==0) return binpow(base,exp);
	if(exp<0)return X(0);
	auto res=X(1)%mm;
	while(exp>0)
	{
		if(exp&1)res=(res*base)%mm;
		base*=base;
		base%=mm;
		exp>>=1;
	}
	return res;
}
@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
@property void putarr(X)(X a,in int n,in int m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p)
	{
		fi=p.fi;
		se=p.se;
	}
	int opCmp(in pair!(X,Y) s_) const pure nothrow @safe
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
X sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}
X cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}
nothrow @nogc @system void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow @nogc @system void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
auto arread(T)(){return readln.split.map!(to!(T)).array;}
nothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (!(a[l]<g))?l:r;
}
pure @property nothrow size_t upb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(g<a[m])r=m;
		else l=m;
	}
	return (g<a[l])?l:r;
}
pure @property nothrow size_t binf(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	size_t l=0,r=a.length;
	while(r-l>1)
	{
		auto m=(l+r)>>1;
		if(!(a[m]<g))r=m;
		else l=m;
	}
	return (g==a[l])?l:a.length;
}
pure @property nothrow bool binary_search(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
{
	return binf(a,g)!=a.length;
}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join filter
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int n;
	while(input(&n))
	{
		if(n%4!=0){writeln("===");return;}
		readln;
		auto s=readln.strip;
		int[4] d;
		foreach(i;s)
			if(i=='A')d[0]++;
			else if(i=='C')d[1]++;
		else if(i=='G') d[2]++;
		else if(i=='T') d[3]++;
		debug foreach(i;d)writeln(i);
		if(max(d[0],d[1],d[2],d[3])>n/4){writeln("===");return;}
		foreach(i;s)
		{
			if(i!='?')write(i);
			else if(d[0]<n/4)
			{
				write('A');
				d[0]++;
			}
			else if(d[1]<n/4)
			{
				write('C');
				d[1]++;
			}
			else if(d[2]<n/4)
			{
				write('G');
				d[2]++;
			}
			else if(d[3]<n/4)
			{
				write('T');
				d[3]++;
			}
		}
		writeln;
	}
	debug readln;
}