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

        auto ans = new int[N + 1];
        foreach (i; 1 .. N + 1) {
          ans[A[i]] = i + 1;
        }
        ans[A[N]] = 1;

        foreach (j; 1 .. N + 1) {
          if (j > 1) write(" ");
          write(ans[j]);
        }
        writeln;

        debug {
          auto as = A.dup;
          writeln(as);
          foreach (j; 1 .. N + 1) {
            as[ans[j] .. N + 1] += j;
            writeln(as);
          }
        }
      }
    }
  } catch (EOFException e) {
  }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto p = readln.splitter.map !(to !(int)).array;
		auto q = new int [n];
		foreach (i; 0..n)
		{
			q[n - p[i]] = i + 1;
		}
		writefln !("%(%s %)") (q);
	}
}

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 p = readln.splitter.map !(to !(int)).array;
		p[] -= 1;
		auto q = new int [n];
		foreach (i; 0..n)
		{
			q[p[i]] = i;
		}
		q[] = n - q[];
		writefln !("%(%s %)") (q);
	}
}

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

        auto ans = new int[N + 1];
        foreach (i; 1 .. N + 1) {
          ans[A[i]] = N - i;
        }
        ans[A[N]] = N;

        foreach (j; 1 .. N + 1) {
          if (j > 1) write(" ");
          write(ans[j]);
        }
        writeln;
      }
    }
  } catch (EOFException e) {
  }
}


import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.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 = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto n = RD!int;
	auto h1 = RDA;
	auto h2 = RDA;

	auto dp = new long[][](n+1, 3);
	foreach (i; 0..n)
	{
		dp[i+1][0] = max(dp[i][1], dp[i][2]) + h1[i];
		dp[i+1][1] = max(dp[i][0], dp[i][2]) + h2[i];
		dp[i+1][2] = max(dp[i][0], max(dp[i][1], dp[i][2]));
	}

	writeln(max(dp[n][0], max(dp[n][1], dp[n][2])));
	stdout.flush();
	debug readln();
}

/// https://codeforces.com/problemset/problem/1195/c
/// PS> dmd cf.d; if($?) {cat in.txt | .\cf.exe}
import std.stdio : stdin, writeln;
import std.array : array, split;
import std.conv  : to;
import std.algorithm : map, max;

void main()
{
  int n, q, sum = 0;
  stdin.readf!"%d\n"(n);

  int[] a = stdin.readln().split().map!(to!int).array;
  int[] b = stdin.readln().split().map!(to!int).array;

  long m1 = 0, m2 = 0, _m1, _m2;
  for (int i = 0; i < n; i++) {
    _m1 = max(m1, m2 + a[i]);
    _m2 = max(m2, m1 + b[i]);
    m1 = _m1; m2 = _m2;
  }

  writeln(max(m1, m2));
}

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

void solve(){
	int n = read.to!int;
	long[] as, bs;
	foreach(i; 0 .. n) as ~= read.to!long;
	foreach(i; 0 .. n) bs ~= read.to!long;

	long[] xs, ys;
	foreach(i; 0 .. n){
		if(i == 0) xs ~= as[0], ys ~= bs[0];
		else{
			xs ~= max(ys[i - 1] + as[i], xs[i - 1]);
			ys ~= max(xs[i - 1] + bs[i], ys[i - 1]);
		}
	}

	long ans = max(xs[n - 1], ys[n - 1]);
	ans.writeln;

}

/// https://codeforces.com/problemset/problem/1195/c
/// PS> dmd cf.d; if($?) {cat in.txt | .\cf.exe}
import std.stdio : stdin, writeln;
import std.array : array, split;
import std.conv  : to;
import std.algorithm : map, max;

void main()
{
  int n, q, sum = 0;
  stdin.readf!"%d\n"(n);

  int[] a = stdin.readln().split().map!(to!int).array;
  int[] b = stdin.readln().split().map!(to!int).array;

  int m1 = 0, m2 = 0, _m1, _m2;
  for (int i = 0; i < n; i++) {
    _m1 = max(m1, m2 + a[i]);
    _m2 = max(m2, m1 + b[i]);
    m1 = _m1; m2 = _m2;
  }

  writeln(max(m1, m2));
}


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

immutable int logHalf = 20;
immutable int half = 1 << logHalf;
immutable int limit = half << 1;

struct Tree
{
	int [] d;
	int [] tMin;
	int [] tMax;

	this (int _)
	{
		d = new int [limit];
		tMin = new int [limit];
		tMax = new int [limit];
	}

	void relax (int tv)
	{
		if (d[tv] == 0)
		{
			return;
		}
		if (tv < half)
		{
			d[tv * 2 + 0] += d[tv];
			d[tv * 2 + 1] += d[tv];
			tMin[tv * 2 + 0] += d[tv];
			tMin[tv * 2 + 1] += d[tv];
			tMax[tv * 2 + 0] += d[tv];
			tMax[tv * 2 + 1] += d[tv];
		}
		d[tv] = 0;
	}

	void recalc (int tv)
	{
		if (tv < half)
		{
			tMin[tv] = min (tMin[tv * 2 + 0], tMin[tv * 2 + 1]);
			tMax[tv] = max (tMax[tv * 2 + 0], tMax[tv * 2 + 1]);
		}
	}

	void add (int lo, int tv, int tlo, int thi, int value)
	{
		if (thi <= lo)
		{
			return;
		}
		if (lo <= tlo)
		{
			d[tv] += value;
			tMin[tv] += value;
			tMax[tv] += value;
			return;
		}
		relax (tv);
		auto tme = (tlo + thi) >> 1;
		add (lo, tv * 2 + 0, tlo, tme, value);
		add (lo, tv * 2 + 1, tme, thi, value);
		recalc (tv);
	}
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto commands = readln.strip;
		int pos = 0;
		int total = 0;
		auto s = new char [half];
		auto t = Tree (-1);

		void go (int pos, int delta)
		{
			total += delta;
			t.add (pos, 1, 0, half, delta);
		}

		auto ans = new int [n];
		ans[] = -1;
		foreach (i, const ref char c; commands)
		{
			if (c == 'L')
			{
				pos = max (0, pos - 1);
			}
			else if (c == 'R')
			{
				pos += 1;
			}
			else if (s[pos] != c)
			{
				int delta = 0;
				delta -= (s[pos] == '(');
				delta += (s[pos] == ')');
				delta += (c == '(');
				delta -= (c == ')');
				if (delta != 0)
				{
					go (pos, delta);
				}
				s[pos] = c;
			}

			if (total == 0)
			{
				if (t.tMin[1] >= 0)
				{
					ans[i] = t.tMax[1];
				}
			}
		}
		writefln ("%(%s %)", ans);
	}
}

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

immutable int logHalf = 20;
immutable int half = 1 << logHalf;
immutable int limit = half << 1;

struct Tree
{
	int [] d;
	int [] tMin;
	int [] tMax;

	this (int _)
	{
		d = new int [limit];
		tMin = new int [limit];
		tMax = new int [limit];
	}

	void relax (int tv)
	{
		if (d[tv] == 0)
		{
			return;
		}
		if (tv < half)
		{
			d[tv * 2 + 0] += d[tv];
			d[tv * 2 + 1] += d[tv];
			tMin[tv * 2 + 0] += d[tv];
			tMin[tv * 2 + 1] += d[tv];
			tMax[tv * 2 + 0] += d[tv];
			tMax[tv * 2 + 1] += d[tv];
		}
		d[tv] = 0;
	}

	void recalc (int tv)
	{
		if (tv < half)
		{
			tMin[tv] = min (tMin[tv * 2 + 0], tMin[tv * 2 + 1]);
			tMax[tv] = max (tMax[tv * 2 + 0], tMax[tv * 2 + 1]);
		}
	}

	void add (int lo, int tv, int tlo, int thi, int value)
	{
		if (thi <= lo)
		{
			return;
		}
		if (lo <= tlo)
		{
			d[tv] += value;
			tMin[tv] += value;
			tMax[tv] += value;
			return;
		}
		relax (tv);
		auto tme = (tlo + thi) >> 1;
		add (lo, tv * 2 + 0, tlo, tme, value);
		add (lo, tv * 2 + 1, tme, thi, value);
		recalc (tv);
	}

	auto ask (int lo, int tv, int tlo, int thi)
	{
		if (thi <= lo)
		{
			return tuple (0, 0);
		}
		if (lo <= tlo)
		{
			return tuple (tMin[tv], tMax[tv]);
		}
		relax (tv);
		auto tme = (tlo + thi) >> 1;
		auto x = ask (lo, tv * 2 + 0, tlo, tme);
		auto y = ask (lo, tv * 2 + 1, tme, thi);
		recalc (tv);
		return tuple (min (x[0], y[0]), max (x[1], y[1]));
	}
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto commands = readln.strip;
		int pos = 0;
		int total = 0;
		auto s = new char [half];
		auto t = Tree (-1);

		void go (int pos, int delta)
		{
			total += delta;
			t.add (pos, 1, 0, half, delta);
		}

		auto ans = new int [n];
		ans[] = -1;
		foreach (i, const ref char c; commands)
		{
			if (c == 'L')
			{
				pos = max (0, pos - 1);
			}
			else if (c == 'R')
			{
				pos += 1;
			}
			else if (s[pos] != c)
			{
				int delta = 0;
				delta -= (s[pos] == '(');
				delta += (s[pos] == ')');
				delta += (c == '(');
				delta -= (c == ')');
				go (pos, delta);
				s[pos] = c;
			}

			if (total == 0)
			{
				auto cur = t.ask (0, 1, 0, half);
				if (cur[0] >= 0)
				{
					ans[i] = cur[1];
				}
			}
		}
		writefln ("%(%s %)", ans);
	}
}


import std;

void main()
{
    int t;
    scanf("%d", &t);
    getchar();
    foreach(_; 0..t)
    {
        auto s = readln.strip;
        auto z = count(s, '0');
        auto o = s.length - z;
        if (z == 0 || o == 0)
            writeln(0);
        else if (o == z)
            if (s.length > 2)
                writeln(o - 1);
            else
                writeln(0);
        else
            writeln(min(o, z));
    }
}

// cheese-cracker [2022-01-31]

void solve(){
    auto s = scan!(dchar[]);
    long on = 0;
    long off = 0;
    long res = 0;
    foreach(c; s){
        on += (c == '1');
        off += (c == '0');
        if(max(on, off) > min(on, off) && max(on, off) > 1){
            res = max(res, min(on, off));
        }
    }
    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, 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; } }


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

pure nothrow @nogc
T gcdext(T) (T a, T b, ref T x, ref T y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  T res = gcdext (b, a % b, y, x);
  y -= x * (a / b);
  return res;
}

pure
X genericPower(alias mul, X, Y) (X x, Y y, X one = 1.to!X)
  if (isUnsigned!Y) {
  X a = one, b = x;
  while (y > 0) {
    if (y & 1) {
      a = binaryFun!mul (a, b);
    }
    b = binaryFun!mul (b, b);
    y >>>= 1;
  }
  return a;
}

struct IntM(int q = 1_000_000_007) {
  alias N = IntM!q;
  private:
  int v;
  //invariant () { assert (v >= 0 && v < q); }
  pure nothrow @nogc
  static int from(T) (const T m) if (isIntegral!T) {
    int v = m % q;
    static if (isSigned!T) {
      if (v < 0) {
        v += q;
      }
    }
    return v;
  }
  public:
  pure nothrow @nogc
  this(T) (const T m) if (isIntegral!T) {
    v = from!T (m);
  }
  pure nothrow @nogc
  N opAssign(T) (const T m) if (isIntegral!T) {
    v = from!T (m);
    return this;
  }
  pure nothrow @nogc
  N opUnary (string op : "-")() const {
    return N (-v);
  }
  pure nothrow @nogc
  ref N opUnary (string op : "++")() {
    if (++v >= q) {
      v -= q;
    }
    return this;
  }
  pure nothrow @nogc
  ref N opUnary (string op : "--")() {
    if (--v < 0) {
      v += q;
    }
    return this;
  }
  pure nothrow @nogc
  ref N opOpAssign (string op : "+")(in N rhs) {
    v = (v + rhs.v) % q;
    return this;
  }
  pure nothrow @nogc
  ref N opOpAssign (string op : "-")(in N rhs) {
    v = (v - rhs.v + q) % q;
    return this;
  }
  pure nothrow @nogc
  ref N opOpAssign (string op : "*")(in N rhs) {
    v = (v.to!(long) * rhs.v) % q;
    return this;
  }
  pure nothrow @nogc
  ref N opOpAssign (string op : "/")(in N rhs) {
    return this *= rhs.inversion ();
  }
  pure nothrow @nogc
  ref N opOpAssign (string op)(in int rhs) if (op == "+" || op == "-" || op == "*" || op == "/") {
    mixin ("return this " ~ op ~ "= N(rhs);");
  }
  pure nothrow @nogc
  N opBinary (string op)(in N rhs) const if (op == "+" || op == "-" || op == "*" || op == "/") {
    N t = this;
    mixin ("t " ~ op ~ "= rhs;");
    return t;
  }
  pure nothrow @nogc
  N opBinary(string op,T)(const T rhs) const if (isIntegral!T && (op == "+" || op == "-" || op == "*" || op == "/")) {
    mixin ("return this " ~ op ~ " N(rhs);");
  }
  pure nothrow @nogc
  N opBinaryRight(string op,T)(const T rhs) const if (isIntegral!T && (op == "+" || op == "*")) {
    mixin ("return this " ~ op ~ " N(rhs);");
  }
  pure nothrow @nogc
  N inversion () const {
    int x, y;
    immutable g = gcdext!int (v, q, x, y);
    assert (g == 1);
    return N (x);
  }
  pure nothrow @nogc
  N opBinary (string op : "^^")(in ulong rhs) const {
    return genericPower! ("a * b", N, ulong) (this, rhs);
  }
  pure nothrow @nogc
  int opCast(T : int)() const { return v; }
  pure nothrow @nogc
  int opCmp (const N rhs) const {
    if (v < rhs.v) {
      return -1;
    }
    if (v > rhs.v) {
      return 1;
    }
    return 0;
  }
  pure nothrow
  string toString() const { return v.text; }
}

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

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

alias N = IntM!998244353;

void main() {
  auto r = new InputReader;
  auto n = r.next!uint;
  auto a = new uint[][n];
  uint maxA;
  size_t maxL;
  foreach (i; 0 .. n) {
    a[i] = r.nextA!uint(r.next!uint);
    foreach (x; a[i]) {
      if (maxA < x) maxA = x;
    }
    if (maxL < a[i].length) maxL = a[i].length;
  }
  auto c = new int[maxA+1];
  auto il = new N[maxL+1];
  foreach (i; 0 .. n) {
    foreach (x; a[i]) ++c[x];
    auto l = a[i].length;
    if (il[l].v == 0) il[l] = N (l.to!int).inversion ();
  }
  auto invN = N (n).inversion();
  N res = 0;
  foreach (i; 0 .. n) {
    N t = 0;
    foreach (x; a[i]) {
      N u;
      u.v = c[x];
      t += u * invN;
    }
    res += t * il[a[i].length];
  }
  writeln (res * invN);
}

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

int N = 1_000_099;

void solve(){
	int n = rint;
	Finite[] ps;
	foreach(i; 0 .. N) ps ~= Finite(0);
	long[] us = new long[](N);
	foreach(i; 0 .. n){
		int k = rint;
		int[] as = rint(k).map!(x => x - 1).array;
		foreach(a; as){
			ps[a] += Finite(1) / k;
			us[a] += 1;
		}
	}
	Finite ans = Finite(0);
	foreach(a; 0 .. N) ans += ps[a] * us[a] / n / n;

	ans.writeln;
}

import std.conv;
struct Finite{
	long value; static long mod = 998244353;
	private static long[] _inv = [0, 1], _frac = [1, 1], _invfrac = [1, 1];
	this(long v){ value = val(v); }
	static long val(long v){
		if(v >= 0) return v % mod;
		else return (v + mod  - (v / mod) * mod) % mod;
	}
	bool opCast(T: bool)(){ return value != 0; }
	Finite opUnary(string s){ long v;
		if(s == "+") v = value;
		else if(s == "-") v = mod - value;
		else if(s == "++") v = value + 1;
		else if(s == "--") v = value + mod - 1;
		else assert(0, "Operator unary " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opBinary(string s)(Finite b){
		return opBinary!s(b.value);
	}
	Finite opBinary(string s)(long u){ long v;
		if(s == "+") v = value + u;
		else if(s == "-") v = value + mod - u;
		else if(s == "*") v = value * u;
		else if(s == "/") v = value * inv(u);
		else assert(0, "Operator " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opBinaryRight(string s)(long u){ long v;
		if(s == "+") v = u + value;
		else if(s == "-") v = u + mod - value;
		else if(s == "*") v = u * value;
		else if(s == "/") v = u * invvalue;
		else assert(0, "Operator " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opAssign(long v){ value = v; return this; }
	Finite opOpAssign(string s)(Finite b){
		return opOpAssign!s(b.value);
	}
	Finite opOpAssign(string s)(long v){
		if(s == "+") value = (value + v) % mod;
		else if(s == "-") value = (value + mod - v) % mod;
		else if(s == "*") value = (value * v) % mod;
		else if(s == "/") value = (value * inv(v)) % mod;
		else assert(0, "Operator " ~ s ~ "= not implemented");
		return this;
	}
	bool opEquals(Finite b){
		return(value == b.value);
	}
	string toString(){ return value.to!string; }
	long inv(long v){
		v = val(v);
		while(v >= _inv.length){
			_inv ~= _inv[(mod % $).to!int] * (mod - mod / _inv.length) % mod;
		}
		return _inv[v.to!int];
	}
	long invvalue(){
		return inv(value);
	}
	static Finite opCall(long v){ return Finite(val(v)); }

}

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

pure nothrow @nogc
T gcdext(T) (T a, T b, ref T x, ref T y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  T res = gcdext (b, a % b, y, x);
  y -= x * (a / b);
  return res;
}

pure
X genericPower(alias mul, X, Y) (X x, Y y, X one = 1.to!X)
  if (isUnsigned!Y) {
  X a = one, b = x;
  while (y > 0) {
    if (y & 1) {
      a = binaryFun!mul (a, b);
    }
    b = binaryFun!mul (b, b);
    y >>>= 1;
  }
  return a;
}

struct IntM(int q = 1_000_000_007) {
  alias N = IntM!q;
  private:
  int v;
  //invariant () { assert (v >= 0 && v < q); }
  pure nothrow @nogc
  static int from(T) (const T m) if (isIntegral!T) {
    int v = m % q;
    static if (isSigned!T) {
      if (v < 0) {
        v += q;
      }
    }
    return v;
  }
  public:
  pure nothrow @nogc
  this(T) (const T m) if (isIntegral!T) {
    v = from!T (m);
  }
  pure nothrow @nogc
  N opAssign(T) (const T m) if (isIntegral!T) {
    v = from!T (m);
    return this;
  }
  pure nothrow @nogc
  N opUnary (string op : "-")() const {
    return N (-v);
  }
  pure nothrow @nogc
  ref N opUnary (string op : "++")() {
    if (++v >= q) {
      v -= q;
    }
    return this;
  }
  pure nothrow @nogc
  ref N opUnary (string op : "--")() {
    if (--v < 0) {
      v += q;
    }
    return this;
  }
  pure nothrow @nogc
  ref N opOpAssign (string op : "+")(in N rhs) {
    v = (v + rhs.v) % q;
    return this;
  }
  pure nothrow @nogc
  ref N opOpAssign (string op : "-")(in N rhs) {
    v = (v - rhs.v + q) % q;
    return this;
  }
  pure nothrow @nogc
  ref N opOpAssign (string op : "*")(in N rhs) {
    v = (v.to!(long) * rhs.v) % q;
    return this;
  }
  pure nothrow @nogc
  ref N opOpAssign (string op : "/")(in N rhs) {
    return this *= rhs.inversion ();
  }
  pure nothrow @nogc
  ref N opOpAssign (string op)(in int rhs) if (op == "+" || op == "-" || op == "*" || op == "/") {
    mixin ("return this " ~ op ~ "= N(rhs);");
  }
  pure nothrow @nogc
  N opBinary (string op)(in N rhs) const if (op == "+" || op == "-" || op == "*" || op == "/") {
    N t = this;
    mixin ("t " ~ op ~ "= rhs;");
    return t;
  }
  pure nothrow @nogc
  N opBinary(string op,T)(const T rhs) const if (isIntegral!T && (op == "+" || op == "-" || op == "*" || op == "/")) {
    mixin ("return this " ~ op ~ " N(rhs);");
  }
  pure nothrow @nogc
  N opBinaryRight(string op,T)(const T rhs) const if (isIntegral!T && (op == "+" || op == "*")) {
    mixin ("return this " ~ op ~ " N(rhs);");
  }
  pure nothrow @nogc
  N inversion () const {
    int x, y;
    immutable g = gcdext!int (v, q, x, y);
    assert (g == 1);
    return N (x);
  }
  pure nothrow @nogc
  N opBinary (string op : "^^")(in ulong rhs) const {
    return genericPower! ("a * b", N, ulong) (this, rhs);
  }
  pure nothrow @nogc
  int opCast(T : int)() const { return v; }
  pure nothrow @nogc
  int opCmp (const N rhs) const {
    if (v < rhs.v) {
      return -1;
    }
    if (v > rhs.v) {
      return 1;
    }
    return 0;
  }
  pure nothrow
  string toString() const { return v.text; }
}

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

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

alias N = IntM!998244353;

void main() {
  auto r = new InputReader;
  auto n = r.next!uint;
  auto a = new uint[][n];
  uint maxA;
  foreach (i; 0 .. n) {
    a[i] = r.nextA!uint(r.next!uint);
    foreach (x; a[i]) {
      if (maxA < x) maxA = x;
    }
  }
  auto c = new int[maxA+1];
  auto il = new N[n+1];
  foreach (i; 0 .. n) {
    foreach (x; a[i]) ++c[x];
    auto l = a[i].length;
    if (il[l].v == 0) il[l] = N (l.to!int).inversion ();
  }
  auto invN = N (n).inversion();
  N res = 0;
  foreach (i; 0 .. n) {
    N t = 0;
    foreach (x; a[i]) {
      N u;
      u.v = c[x];
      t += u * invN;
    }
    res += t * il[a[i].length];
  }
  writeln (res * invN);
}


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;
import std.variant;
import std.concurrency;

void main(string[] args)
{
  auto n = next!int;
  auto k = next!long;
  auto a = next!long(n);
  auto origA = a.dup;
  int[11] pot;
  pot[0] = 1;
  foreach(i; 1 .. 11)
    {
      pot[i] = (pot[i - 1] * 10) % k;
    }
  int[int][11] cnt;
  foreach(p; 0 .. 11)
    {
      foreach(ref ai; a)
	{
	  ai %= k;
	}
      foreach(ref ai; a)
	{
	  cnt[p].require(cast(int)ai, 0)++;
	  ai *= 10;
	}
    }
  long totalCount = 0;
  foreach(ref ai; origA)
    {
      auto digs = noDigs(ai);
      long req = (((-ai) % k + k))%k;
      debug writeln("I require ", req, " in ", digs);
      if (cast(int)req in cnt[digs])
	{
	  totalCount += cnt[digs][cast(int)req];
	  if ((pot[digs] * (ai % k) + ai % k) % k == 0)
	    totalCount --;
	}
    }
  totalCount.writeln;
}

auto noDigs(long num)
{
  auto res = int(0);
  while(num)
    {
      num /= 10;
      res++;
    }
  return res;
}

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 std.stdio, std.string;
import std.math;

int calcLength(int num)
{
    auto res = 0;
    while (num)
    {
        num /= 10;
        ++ res;
    }
    return res;
}

void solve(int[] a, int n, int k)
{
    auto h = new int[int][10];
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        foreach (j; 0 .. 10)
        {
            num = cast(int)((cast(long)num * 10) % k);
            if (num !in h[j])
            {
                h[j][num] = 1;
            }
            else
            {
                ++ h[j][num];
            }
        }
    }
    long res = 0;
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        auto L = calcLength(a[i]);
        auto target = (k - num) % k;
        if (target in h[L - 1])
        {
            res += h[L - 1][target];
        }
        num = cast(int)((cast(long)a[i] * (cast(long)pow(10L, L) % k)) % k);
        num = (num + (a[i] % k)) % k;
        if (num == 0)
        {
            -- res;
        }
    }
    writeln(res);
}

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

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

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

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

    int [int][int] cnt;
    void add(int e, int v) { cnt[e.to!string.length.to!int][e % k] += v; }

    foreach (e; arr) {
        add(e, 1);
    }

    debug { cnt.writeln; }

    auto ans = 0L;
    foreach (e; arr) {
        add(e, -1);
        auto r = e % k;
        foreach (d; 1 .. 11) {
            r = cast(long)r * 10 % k;
            debug { r.writeln; }
            if (d in cnt && ((k-r) % k) in cnt[d]) ans += cnt[d][(k-r) % k];
        }
        add(e, 1);
    }

    ans.writeln;
}

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

void main() {
    auto s = readln.split.map!(to!int);
    auto n = s[0];
    auto m = s[1];
    auto A = readln.split.map!(to!long).array;

    long ans = 0;
    auto cnt = new long[long][](11);
    foreach (a; A) {
        auto v = a;
        foreach (i; 0..11) {
            cnt[i][v] += 1;
            v = v * 10 % m;
        }
    }

    foreach (a; A) {
        long keta = a.to!string.length.to!long;
        long target = (m - a % m) % m;
        if (target in cnt[keta.to!int]) ans += cnt[keta.to!int][target];
        if ((powmod(10, keta, m) * a % m + a) % m == 0) ans -= 1;
    }

    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}

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

int calcLength(int num)
{
    auto res = 0;
    while (num)
    {
        num /= 10;
        ++ res;
    }
    return res;
}

void solve(int[] a, int n, int k)
{
    auto h = new int[int][10];
    foreach (i; 0 .. n)
    {
        foreach (j; 0 .. 10)
        {
            auto num = cast(int)((cast(long)a[i] * (cast(long)pow(10L, j + 1) % k)) % k);
            if (num !in h[j])
            {
                h[j][num] = 1;
            }
            else
            {
                ++ h[j][num];
            }
        }
    }
    long res = 0;
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        auto L = calcLength(a[i]);
        auto target = (k - num) % k;
        if (target in h[L - 1])
        {
            res += h[L - 1][target];
        }
        num = cast(int)((cast(long)a[i] * (cast(long)pow(10L, L) % k)) % k);
        num = (num + (a[i] % k)) % k;
        if (num == 0)
        {
            -- res;
        }
    }
    writeln(res);
}

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

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

int calcLength(int num)
{
    auto res = 0;
    while (num)
    {
        num /= 10;
        ++ res;
    }
    return res;
}

void solve(int[] a, int n, int k)
{
    auto h = new int[int][10];
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        foreach (j; 0 .. 10)
        {
            num = cast(int)((cast(long)num * 10) % k);
            if (num !in h[j])
            {
                h[j][num] = 1;
            }
            else
            {
                ++ h[j][num];
            }
        }
    }
    long res = 0;
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        auto L = calcLength(a[i]);
        auto target = (k - num) % k;
        if (target in h[L - 1])
        {
            res += h[L - 1][target];
        }
        num = cast(int)((cast(long)a[i] * (pow(10, L) % k)) % k);
        num = (num + (a[i] % k)) % k;
        if (num == 0)
        {
            -- res;
        }
    }
    writeln(res);
}

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

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

int calcLength(int num)
{
    auto res = 0;
    while (num)
    {
        num /= 10;
        ++ res;
    }
    return res;
}

void solve(int[] a, int n, int k)
{
    auto h = new int[int][10];
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        foreach (j; 0 .. 10)
        {
            num = (num * 10) % k;
            if (num !in h[j])
            {
                h[j][num] = 1;
            }
            else
            {
                ++ h[j][num];
            }
        }
    }
    long res = 0;
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        auto L = calcLength(a[i]);
        auto target = (k - num) % k;
        if (target in h[L - 1])
        {
            res += h[L - 1][target];
        }
        num = cast(int)((cast(long)a[i] * (pow(10, L) % k)) % k);
        num = (num + (a[i] % k)) % k;
        if (num == 0)
        {
            -- res;
        }
    }
    writeln(res);
}

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

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

int calcLength(int num)
{
    auto res = 0;
    while (num)
    {
        num /= 10;
        ++ res;
    }
    return res;
}

void solve(int[] a, int n, int k)
{
    auto h = new int[int][10];
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        foreach (j; 0 .. 10)
        {
            num = cast(int)((cast(long)num * 10) % k);
            if (num !in h[j])
            {
                h[j][num] = 1;
            }
            else
            {
                ++ h[j][num];
            }
        }
    }
    long res = 0;
    foreach (i; 0 .. n)
    {
        auto num = a[i] % k;
        auto L = calcLength(a[i]);
        auto target = (k - num) % k;
        if (target in h[L - 1])
        {
            res += h[L - 1][target];
        }
        num = cast(int)((cast(long)(a[i] % k) * (cast(long)pow(10, L) % k)) % k);
        num = (num + (a[i] % k)) % k;
        if (num == 0)
        {
            -- res;
        }
    }
    writeln(res);
}

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

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

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

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

    int [int][int] cnt;
    void add(int e, int v) { cnt[e.to!string.length.to!int][e % k] += v; }

    foreach (e; arr) {
        add(e, 1);
    }

    debug { cnt.writeln; }

    auto ans = 0L;
    foreach (e; arr) {
        add(e, -1);
        auto r = e % k;
        foreach (d; 1 .. 10) {
            r = r * 10 % k;
            if (d in cnt && ((k-r) % k) in cnt[d]) ans += cnt[d][(k-r) % k];
        }
        add(e, 1);
    }

    ans.writeln;
}

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

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

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

    int [int][int] cnt;
    void add(int e, int v) { cnt[e.to!string.length.to!int][e % k] += v; }

    foreach (e; arr) {
        add(e, 1);
    }

    debug { cnt.writeln; }

    auto ans = 0L;
    foreach (e; arr) {
        add(e, -1);
        auto r = e % k;
        foreach (d; 1 .. 11) {
            r = r * 10 % k;
            if (d in cnt && ((k-r) % k) in cnt[d]) ans += cnt[d][(k-r) % k];
        }
        add(e, 1);
    }

    ans.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 char[][][](t);
	foreach (ti; 0..t)
	{
		auto h = RD!int;
		auto w = RD!int;

		ans[ti].length = h;
		foreach (i; 0..h)
		{
			ans[ti][i].length = w;
			foreach (j; 0..w)
			{
				ans[ti][i][j] = '0';
			}
		}
		foreach (i; 0..w)
		{
			if (i % 2 == 0)
			{
				ans[ti][0][i] = '1';
				ans[ti][h-1][i] = '1';
			}
		}
		foreach (i; 2..h-2)
		{
			if (i % 2 == 0)
			{
				ans[ti][i][0] = '1';
				ans[ti][i][w-1] = '1';
			}
		}
	}

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

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

void main()
{
	int t = readInt!int;
	while (t--) solve;

}

void solve()
{
	int h = readInt!int;
	int w = readInt!int;
	if (w % 2 == 1 && h % 2 == 1)
	{
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
				{
					write((i + j + 1)%2);
				}
				else write(0);
			}
			writeln;
		}
		writeln;
		return;
	}
	else if (w % 2 == 0 && h % 2 == 0)
	{
		auto ans = new int[][](h, w);
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if(i == 0 || i == h - 1)
				{
					ans[i][j] = (i + j)%2;
					continue;
				}
				if (j == 0 || j == w - 1)
				{
					ans[i][j] = (i + j + 1)%2;
				}
			}
		}
		ans[0][0] = ans[0][w-1] = ans[h-1][0] = ans[h-1][w-1] = 0;
		foreach(row; ans) { row.each!write; writeln; }
		writeln;
		return;
	}
	foreach(i; 0 .. h)
	{
		foreach(j; 0 .. w)
		{
			if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
			{
				int ch = w%2;
				if (i == 0 && j == 0 || i == h - 1 &&  j == w - 1) {0.write; continue;}
				if (i == 0 || j == w - 1)
				{
					((i+j+ch)%2).write;
				}
				else
				{
					((i + j + 1+ch)%2).write;
				}
			}
			else 0.write;
		}
		writeln;
	}
	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, 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); }

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

  while (t--) {
    int h, w;
    read(h, w);

    auto table = new int[][](h, w);

    table[0][0] = table[0][w - 1] = table[h - 1][0] = table[h - 1][w - 1] = 1;

    foreach (i; 0 .. (h - 3) / 2) {
      table[i * 2 + 2][0] = table[i * 2 + 2][w - 1] = 1;
    }

    foreach (i; 0 .. (w - 3) / 2) {
      table[0][i * 2 + 2] = table[h - 1][i * 2 + 2] = 1;
    }

    foreach (i; 0 .. h) {
      foreach (j; 0 .. w) {
        write(table[i][j]);
      }
      writeln;
    }
    writeln;
  }
}

// code by cutx64

module main;

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

void main() {

  int tests; readf!"%s\n"(tests);
  while(tests--) {
    int n, m;
    readf!"%s %s\n"(n, m);
    bool[][] a = new bool[][](n, m);
    foreach(i; 0 .. n) {
      foreach(j; 0 .. m) {
        if (i == 0 || i == n - 1 || j == 0 || j == m - 1) {
          if (i > 0 && a[i - 1][j]) continue;
          if (i > 0 && j > 0 && a[i - 1][j - 1]) continue;
          if (j > 0 && a[i][j - 1]) continue;
          if (i > 0 && j + 1 < m && a[i - 1][j + 1]) continue;
          a[i][j] = true;
        }
      }
    }
    writefln!"%(%(%d%)\n%)"(a);
  }

} // main

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;

bool good(int x, int y, int w, int h, int[][] a)
{
  if (x > 0 && a[x - 1][y])
    return false;
  if (x + 1 < w && a[x + 1][y])
    return false;
  if (y > 0 && a[x][y - 1])
    return false;
  if (y + 1 < h && a[x][y + 1])
    return false;

  if (x > 0 && y > 0 && a[x - 1][y - 1])
    return false;
  if (x + 1 < w && y > 0 && a[x + 1][y - 1])
    return false;
  if (x > 0 && y + 1 < h && a[x - 1][y + 1])
    return false;
  if (x + 1 < w && y + 1 < h && a[x + 1][y + 1])
    return false;

  return true;
}

long solve(int x, int y, int w, int h, int[][] a)
{
  long result = 0;
  while (x < w) {
    if (good(x, y, w, h, a)) {
      result++;
      a[x][y] = 1;
    }
    x++;
  }
  x = w - 1;
  while (y < h) {
    if (good(x, y, w, h, a)) {
      result++;
      a[x][y] = 1;
    }
    y++;
  }
  y = h - 1;
  while (x >= 0) {
    if (good(x, y, w, h, a)) {
      result++;
      a[x][y] = 1;
    }
    x--;
  }
  x = 0;
  while (y >= 0) {
    if (good(x, y, w, h, a)) {
      result++;
      a[x][y] = 1;
    }
    y--;
  }
  return result;
}

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    int h, w;
    readf!" %d %d "(h, w);
    auto a1 = new int[][](w, h);
    auto a2 = new int[][](w, h);
    a1[0][0] = 1;
    a2[1][0] = 1;
    long result1 = solve(0, 0, w, h, a1);
    long result2 = solve(0, 0, w, h, a2);
    if (result1 > result2) {
      foreach (row ; a1.transposed) {
        writeln(row.map!text.joiner(""));
      }
      writeln;
    } else {
      foreach (row ; a2.transposed) {
        writeln(row.map!text.joiner(""));
      }
      writeln;
    }
  }
}

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

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

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

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

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

        auto ans = new char[][](M, N);
        foreach (x; 0 .. M) {
          ans[x][] = '0';
        }
        ans[0][0] = ans[0][N - 1] = ans[M - 1][0] = ans[M - 1][N - 1] = '1';
        for (int y = 2; y < N - 2; y += 2) {
          ans[0][y] = ans[M - 1][y] = '1';
        }
        for (int x = 2; x < M - 2; x += 2) {
          ans[x][0] = ans[x][N - 1] = '1';
        }

        foreach (x; 0 .. M) {
          writeln(ans[x]);
        }
        writeln;
      }
    }
  } catch (EOFException e) {
  }
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int rows, cols;
		readf !(" %s %s") (rows, cols);
		auto s = new bool [] [] (rows, cols);
		foreach (row; 0..rows)
		{
			foreach (col; 0..cols)
			{
				if (row == 0 || row == rows - 1 ||
				    col == 0 || col == cols - 1)
				{
					if (row > 0 && s[row - 1][col])
					{
						continue;
					}
					if (row > 0 && col > 0 &&
					    s[row - 1][col - 1])
					{
						continue;
					}
					if (col > 0 && s[row][col - 1])
					{
						continue;
					}
					if (row > 0 && col + 1 < cols &&
					    s[row - 1][col + 1])
					{
						continue;
					}
					s[row][col] = true;
				}
			}
		}
		writefln !("%(%(%d%)\n%)\n") (s);
	}
}

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

void main()
{
	int t = readInt!int;
	while (t--) solve;

}

void solve()
{
	int h = readInt!int;
	int w = readInt!int;
	if (w % 2 == 1 && h % 2 == 1)
	{
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
				{
					write((i + j + 1)%2);
				}
				else write(0);
			}
			writeln;
		}
		writeln;
		return;
	}
	else if (w % 2 == 0 && h % 2 == 0)
	{
		auto ans = new int[][](h, w);
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if(i == 0 || i == h - 1)
				{
					ans[i][j] = (i + j)%2;
					continue;
				}
				if (j == 0 || j == w - 1)
				{
					ans[i][j] = (i + j + 1)%2;
				}
			}
		}
		ans[0][0] = ans[0][w-1] = ans[h-1][0] = ans[h-1][w-1] = 0;
		foreach(row; ans) { row.each!write; writeln; }
		writeln;
		return;
	}
	foreach(i; 0 .. h)
	{
		foreach(j; 0 .. w)
		{
			if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
			{
				int ch = w%2;
				if (j > i)
				{
					((i+j+ch)%2).write;
				}
				else if (i > j)
				{
					((i + j + 1+ch)%2).write;
				}
				else
				{
					0.write;
				}
			}
			else 0.write;
		}
		writeln;
	}
	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.stdio;
import std.ascii;
import std.algorithm;
import std.range;
import core.stdc.stdio;

void main()
{
	int t = readInt!int;
	while (t--) solve;

}

void solve()
{
	int h = readInt!int;
	int w = readInt!int;
	if (w % 2 == 1 && h % 2 == 1)
	{
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
				{
					write((i + j + 1)%2);
				}
				else write(0);
			}
			writeln;
		}
		writeln;
		return;
	}
	else if (w % 2 == 0 && h % 2 == 0)
	{
		auto ans = new int[][](h, w);
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if(i == 0 || i == h - 1)
				{
					ans[i][j] = (i + j)%2;
					continue;
				}
				if (j == 0 || j == w - 1)
				{
					ans[i][j] = (i + j + 1)%2;
				}
			}
		}
		ans[0][0] = ans[0][w-1] = ans[h-1][0] = ans[h-1][w-1] = 0;
		foreach(row; ans) { row.each!write; writeln; }
		writeln;
		return;
	}
	foreach(i; 0 .. h)
	{
		foreach(j; 0 .. w)
		{
			if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
			{
				if (j > i)
				{
					((i+j)%2).write;
				}
				else if (i > j)
				{
					((i + j + 1)%2).write;
				}
				else
				{
					0.write;
				}
			}
			else 0.write;
		}
		writeln;
	}
	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.stdio;
import std.ascii;
import std.algorithm;
import std.range;
import core.stdc.stdio;

void main()
{
	int t = readInt!int;
	while (t--) solve;

}

void solve()
{
	int h = readInt!int;
	int w = readInt!int;
	if (w % 2 == 1 && h % 2 == 1)
	{
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
				{
					write((i + j + 1)%2);
				}
				else write(0);
			}
			writeln;
		}
		writeln;
		return;
	}
	else if (w % 2 == 0 && h % 2 == 0)
	{
		auto ans = new int[][](h, w);
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if(i == 0 || i == h - 1)
				{
					ans[i][j] = (i + j)%2;
					continue;
				}
				if (j == 0 || j == w - 1)
				{
					ans[i][j] = (i + j + 1)%2;
				}
			}
		}
		ans[0][0] = ans[0][h-1] = ans[w-1][0] = ans[w-1][h-1] = 0;
		foreach(row; ans) { row.each!write; writeln; }
		writeln;
	}
	foreach(i; 0 .. h)
	{
		foreach(j; 0 .. w)
		{
			if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
			{
				if (j > i)
				{
					((i+j)%2).write;
				}
				else if (i > j)
				{
					((i + j + 1)%2).write;
				}
				else
				{
					0.write;
				}
			}
			else 0.write;
		}
		writeln;
	}
	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.stdio;
import std.ascii;
import std.algorithm;
import std.range;
import core.stdc.stdio;

void main()
{
	int t = readInt!int;
	while (t--) solve;

}

void solve()
{
	int h = readInt!int;
	int w = readInt!int;
	int l = 2 * h + 2 * w - 4;
	int m = l - l/2;
	int[][] fm;
	bool tryF(int x)
	{
		int t = 0;
		fm = new int[][](h, w);
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
				{
					fm[i][j] = (i + j + x)%2;
					t += fm[i][j];
				}
			}
		}
		if (t == m) return true;
		return false;
	}
	if (tryF(1)) goto print;
	if (tryF(0)) goto print;
	assert(0);
print:
	foreach(row; fm)
	{
		row.each!write; writeln;
	}
	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.stdio;
import std.ascii;
import std.algorithm;
import std.range;
import core.stdc.stdio;

void main()
{
	int t = readInt!int;
	while (t--) solve;

}

void solve()
{
	int h = readInt!int;
	int w = readInt!int;
	int l = 2 * h + 2 * w - 4;
	int m = l - l/2;
	int[][] fm;
	bool tryF(int x)
	{
		int t = 0;
		fm = new int[][](h, w);
		foreach(i; 0 .. h)
		{
			foreach(j; 0 .. w)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
				{
					fm[i][j] = (i + j + x)%2;
					t += fm[i][j];
				}
			}
		}
		if (t == m) return true;
		return false;
	}
	if (tryF(0)) goto print;
	if (tryF(1)) goto print;
	assert(0);
print:
	foreach(row; fm)
	{
		row.each!write; writeln;
	}
	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);
	}
}


// Cheese-Cracker: cheese-cracker.github.io
int[] primes;
void prime_sieve(){
    const int sz = 100;
    auto isPrime = new bool[](sz + 1);
    isPrime[] = 1;
    foreach(p; 2..15){
        if(isPrime[p]){
            for(ll divi = p*p; divi <= sz; divi += p){
                isPrime[divi.to!int] = 0;
            }
        }
    }
    isPrime[0] = 0; isPrime[1] = 0;
    primes = isPrime.enumerate.filter!(a => a[1]).map!(a => a[0].to!(int)).array;
    foreach(k; 2..sz+1){
        if(isPrime[k]) primes ~= k;
    }
}

void theCode(){
    ll k = scan;
    auto n = scan!(dchar[]);
    auto w = "2357".to!(dchar[]);
    ll[4] freq;
    foreach(c; n){
        bool f = 1;
        for(int i = 0; i < 4; ++i){
            dchar d = w[i];
            if(c == d){
                ++freq[i];
                f = 0;
                break;
            }
        }
        if(f){
            writeln(1);
            writeln(c);
            return;
        }
    }
    for(int i = 0; i < k; ++i){
        int d1 = n[i] - '0';
        for(int j = i+1; j < k; ++j){
            int d2 = n[j] - '0';
            int num = d1* 10 + d2;
            bool f = 1;
            foreach(pm; primes){
                if(num == pm){
                    f = 0;
                }
            }
            if(f){
                writeln(2);
                writeln(num);
                return;
            }
        }
    }
}

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

/*********  That's All Folks!  *********/
import std.stdio, std.random, std.functional, std.container, std.algorithm;
import std.numeric, std.range, std.typecons, std.string, std.math, std.conv;
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.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 string[](t);
	foreach (ti; 0..t)
	{
		auto k = RD!int;
		auto s = RD!string;

		auto cnt = new long[](10);
		foreach (c; s)
		{
			++cnt[c-'0'];
		}

		auto set = [1:true, 4:true, 6:true, 8:true, 9:true];
		bool ok;
		foreach (i; 0..10)
		{
			if (set.get(i, false) == false) continue;
			if (cnt[i] > 0)
			{
				ok = true;
				ans[ti] = [cast(char)('0'+i)];
				break;
			}
		}
		if (ok) continue;

		foreach (i; 0..10)
		{
			if (cnt[i] >= 2)
			{
				ok = true;
				ans[ti] ~= [cast(char)('0'+i)];
				ans[ti] ~= [cast(char)('0'+i)];
				break;
			}
		}
		if (ok) continue;

		foreach (i; 1..2^^k)
		{
			string str;
			foreach (j; 0..k)
			{
				auto bit = 1L << j;
				if (i & bit)
				{
					str ~= s[j];
				}
			}
			auto x = str.to!long;
			for (long j = 2; j*j <= x; ++j)
			{
				if (x % j) continue;
				ok = true;
				ans[ti] = str;
				break;
			}
			if (ok) break;
		}
	}
	debug writeln(ans);

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

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

bool check_subsequence(string main, string sub)
{
  int i, j;
  while (i < main.length && j < sub.length) {
    if (main[i] == sub[j]) {
      i++;
      j++;
      continue;
    }
    i++;
  }
  return j == sub.length;
}

void main()
{
  auto nonprimes = ["1", "4", "6", "8", "9", "20", "22", "25", "27", "30", "32", "33", "35", "50", "52", "55", "57", "70", "72", "75", "77"];
  long t;
  readf!" %d "(t);
  while (t--) {
    long n;
    readln.formattedRead!" %d "(n);
    string s = readln.strip;
    bool good = false;
    foreach (nonprime ; nonprimes) {
      if (check_subsequence(s, nonprime)) {
        writeln(nonprime.length);
        writeln(nonprime);
        good = true;
        break;
      }
    }
    if (!good)
      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)); }
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 string[](t);
	foreach (ti; 0..t)
	{
		auto k = RD!int;
		auto s = RD!string;

		auto cnt = new long[](10);
		foreach (c; s)
		{
			++cnt[c-'0'];
		}

		auto set = [1:true, 4:true, 6:true, 8:true];
		bool ok;
		foreach (i; 0..10)
		{
			if (set.get(i, false) == false) continue;
			if (cnt[i] > 0)
			{
				ok = true;
				ans[ti] = [cast(char)('0'+i)];
				break;
			}
		}
		if (ok) continue;

		foreach (i; 0..10)
		{
			if (cnt[i] >= 2)
			{
				ok = true;
				ans[ti] ~= [cast(char)('0'+i)];
				ans[ti] ~= [cast(char)('0'+i)];
				break;
			}
		}
		if (ok) continue;

		foreach (i; 1..2^^k)
		{
			string str;
			foreach (j; 0..k)
			{
				auto bit = 1L << j;
				if (i & bit)
				{
					str ~= s[j];
				}
			}
			auto x = str.to!long;
			for (long j = 2; j*j <= x; ++j)
			{
				if (x % j) continue;
				ok = true;
				ans[ti] = str;
				break;
			}
			if (ok) break;
		}
	}
	debug writeln(ans);

	foreach (e; ans)
	{
		writeln(e.length);
		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.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.range.interfaces;

void Add(int n, ref int[] arr, int m) {
    if (n / m == 0) return;
    Add(n, arr, m*2);
    auto v = n / m;
    while (arr.length < v) arr ~= m;
}

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

    if (n <= 3) {
        auto ans = [n].padLeft(1, n);

        ans.writefln!("%(%s %)");
        return;
    }

    int[] ans;
    Add(n, ans, 1);
    if (ans[1] == ans[2]) ans[0] += ans[1];
    ans.reverse();

    ans.writefln!("%(%s %)");
}

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

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

    int m = n;
    int p = 1;
    int[] ans;

    while (m > 0) {
        if (m == 3) {
            ans ~= p;
            ans ~= p;
            ans ~= p * 3;
            break;
        }
        foreach (i ; 0 .. (m + 1) / 2) {
            ans ~= p;
        }
        m -= (m + 1) / 2;
        p *= 2;
    }

    writefln("%(%s %)", ans);
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    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);
        }
    }
}

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

  int n;
  rd(n);
  int g = 1;
  int[] ans;
  while (n) {
    if (n == 3) {
      ans ~= g;
      ans ~= g;
      ans ~= g * 3;
      break;
    }
    int k = (n + 1) / 2;
    n -= k;
    foreach (_; 0 .. k)
      ans ~= g;
    g *= 2;
  }
  writefln("%(%s %)", ans);

}

// 5 => 1 1 1 2 4
// 6 => 1 1 1 2 2 6
// 7 => 1 1 1 1 2 2 6
// 8 => 1 1 1 1 2 2 4 8
// 10 => 1 1 1 1 1 2 2 2 4 8
// 12 => 1 1 1 1 1 1 2 2 2 4 4 12

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

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

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

immutable int MD = 998244353;

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

    if (n <= 3) {
        auto ans = [n].padLeft(1, n);

        ans.writefln!("%(%s %)");
        return;
    }

    auto pws = recurrence!((a,n) => a[n-1] * 2)(2).until!(x => x > n).array;

    auto ans = pws.padLeft(1, n);

    ans.writefln!("%(%s %)");
}

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

  int n;
  rd(n);
  import std.range : iota;
  import std.array : array;
  import std.numeric : gcd;

  auto a = iota(1, n + 1).filter!((val) => val % 2 == 0).array;
  int[] result;
  foreach (_; 0 .. (n - a.length))
    result ~= 1;
  while (result.length < n) {
    int[] b;
    if (a.length <= 2) {
      auto g = gcd(a[0], a[$ - 1]);
      result ~= g;
      if (a.length > 1) {
        b ~= a[$ - 1];
      }
    } else {
      auto g = reduce!((gg, val) => gcd(gg, val))(0, a);
      result ~= g;
      foreach (val; a[1 .. $]) {
        if (val % g == 0) {
          b ~= val;
        }
      }
      int[] b2;
      foreach (val; a[1 .. $]) {
        if (val % a[1] == 0) {
          b2 ~= val;
        }
      }
      if (b2.length >= 2) {
        b = b2.dup;
      }
      foreach (_; 0 .. (a.length - b.length - 1)) {
        result ~= g;
      }
    }
    a.swap(b);
  }
  writefln("%(%s %)", result);
}

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

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


// Vicfred
// https://codeforces.com/contest/1537/problem/A
// simple math
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

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

    if(sum < n) {
        "1".writeln;
        continue;
    }
    writefln("%s", sum - n);
}
}

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

void main()
{
  long t, n;
  readf!" %d "(t);

  while (t--) {
    readf!" %d "(n);
    auto a = readln.strip.split.map!(to!long);
    long sum = a.sum;
    long result = 0;
    if (sum - n >= 0) {
      writeln(sum - n);
    } else {
      writeln(1);
    }
  }
}

// Vicfred
// https://codeforces.com/contest/1537/problem/A
// simple math
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

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

    if(sum <= 0) {
        "1".writeln;
        continue;
    }
    writefln("%s", sum - n);
}
}

// Vicfred
// https://codeforces.com/contest/1537/problem/A
// simple math
import std.algorithm;
import std.array;
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[] a = readln.split.map!(to!int).array;
    long sum = a.sum;

    if(sum <= 0) {
        "1".writeln;
        continue;
    }
    writefln("%s", sum - n);
}
}


import std.stdio : write, writeln, writefln, stdin;
import std.array;
import std.range;
import std.typecons;
import std.algorithm : max, min;

int n;
int k;
void main(){
	n.next;
	k.next;

	int cnt;
	foreach(i; n.iota){
		string str = next!string();
		int con;
		foreach(c; str){
			if( c == '4' || c == '7' ) ++con;
		}
		if( con <= k ) ++cnt;
	}

	cnt.writeln;
}

import std.stdio : readln;
import std.conv : to;
import std.string : split, chomp;
shared string[] input;
shared string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

void next(T)(ref T v){
	v = next!T();
}

bool hasNext(){
	if(input.length > 0){
		return true;
	}

	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return true;
	}else{
		return false;
	}
}

void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}

	return v_;
}

import std.stdio;

int main() {
    int N, K;
    readf(" %s %s", &N, &K);
    int ans = 0;
    foreach (i; 0..N) {
        int n;
        readf(" %s", &n);
        int nd = 0;
        while (n > 0) {
            int d = n % 10;
            n /= 10;
            if (d == 4 || d == 7) {
                nd++;
            }
        }
        if (nd <= K) {
            ans++;
        }
    }
    writefln("%s", ans);
    return 0;
}


import std.math,
       std.conv,
       std.stdio,
       std.ascii,
       std.range,
       std.array,
       std.regex,
       std.format,
       std.bigint,
       std.traits,
       std.string,
       std.numeric,
       std.variant,
       std.typecons,
       std.algorithm,
       std.typetuple,
       std.exception;

void main() {

	char[] s = readln.strip.dup;
	int k = readln.strip.to!int;

	if (s.length < k || s.length % k != 0) {
		writeln("NO");
		return;
	}

	int ans, i, it = s.length / k, idx = s.length / k;
	while (it <= s.length) {
		debug writeln("s = ", s[i .. it]);
		if (s[i .. it] == s[i .. it].retro.text) {
			++ans;
		}
		else {
			break;
		}
		i = it;
		it += idx;
		debug writefln("i = %s, it = %s, s.len = %s", i, it, s.length);
	}

	writeln(ans == k ? "YES" : "NO");
}

import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInt() {
	return readInts()[0];
}
auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}

bool isPalindrome(string s) {
	foreach(i; 0..s.length) {
		if(s[i] != s[$-i-1]){
			return false;
		}
	}
	return true;
}
void main() {
	auto s = readln().strip();
	auto k = readInt();
	if(s.length%k != 0) {
		writeln("NO");
		return;
	}
	foreach(i; 0..k) {
		auto t = s[s.length/k*i..s.length/k*(i+1)];
		if(!isPalindrome(t)){
			writeln("NO");
			return;
		}
	}
	writeln("YES");
}

import std.math,
       std.conv,
       std.stdio,
       std.ascii,
       std.range,
       std.array,
       std.regex,
       std.format,
       std.bigint,
       std.traits,
       std.string,
       std.numeric,
       std.variant,
       std.typecons,
       std.algorithm,
       std.typetuple,
       std.exception;

void main() {

	char[] s = readln.strip.dup;
	int k = readln.strip.to!int;

	if (s.length < k) {
		writeln("NO");
		return;
	}

	int ans, i, it = s.length / k, idx = s.length / k;
	while (it <= s.length) {
		debug writeln("s = ", s[i .. it]);
		if (s[i .. it] == s[i .. it].retro.text) {
			++ans;
		}
		else {
			break;
		}
		i = it;
		it += idx;
		debug writefln("i = %s, it = %s, s.len = %s", i, it, s.length);
	}

	writeln(ans == k ? "YES" : "NO");
}

import std.math,
       std.conv,
       std.stdio,
       std.ascii,
       std.range,
       std.array,
       std.regex,
       std.format,
       std.bigint,
       std.traits,
       std.string,
       std.numeric,
       std.variant,
       std.typecons,
       std.algorithm,
       std.typetuple,
       std.exception;

void main() {

	char[] s = readln.strip.dup;
	int k = readln.strip.to!int;

	int ans, i, it = s.length / k;
	while (it <= s.length) {
		debug writeln("s = ", s[i .. it]);
		if (s[i .. it] == s[i .. it].retro.to!string) {
			++ans;
		}
		i = it;
		it += k;
		debug writefln("i = %s, it = %s, s.len = %s", i, it, s.length);
	}

	writeln(ans == k ? "YES" : "NO");
}


// problem: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A
// require: graph/articulation_points.d

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

const int[] P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31];

void solve() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = new int[](N);

    foreach (i, a; A) foreach (j, p; P) {
        if (a % p == 0) {
            B[i.to!int] = j.to!int + 1;
            break;
        }
    }

    auto X = B.dup.sort().uniq.array;
    int[int] Y;
    foreach (i; 0..X.length.to!int) Y[X[i]] = i + 1;
    foreach (i; 0..N) B[i] = Y[B[i]];
    X.length.writeln;
    B.map!(to!string).join(" ").writeln;
}

void main() {
    auto T = readln.chomp.to!int;
    while (T--) {
        solve();
    }
}

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 int[][](t);
	auto m = new int[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA!int;

		ans[ti].length = n;
		bool[int] set;
		foreach (i; 0..n)
		{
			for (int j = 2; j*j <= a[i]; ++j)
			{
				if (a[i] % j == 0)
				{
					set[j] = true;
					ans[ti][i] = j;
					break;
				}
			}
		}
		auto keys = set.keys;
		m[ti] = cast(int)keys.length;
		int[int] keyToNum;
		foreach (i, key; keys)
		{
			keyToNum[key] = cast(int)(i+1);
		}
		foreach (i; 0..n)
		{
			ans[ti][i] = keyToNum[ans[ti][i]];
		}
	}

	foreach (ti, e; ans)
	{
		writeln(m[ti]);
		e.map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}

// problem: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A
// require: graph/articulation_points.d

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

const int[] P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31];

void solve() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = new int[](N);

    foreach (i, a; A) foreach (j, p; P) {
        if (a % p == 0) {
            B[i.to!int] = j.to!int + 1;
            break;
        }
    }

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

void main() {
    auto T = readln.chomp.to!int;
    while (T--) {
        solve();
    }
}