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

// M: prime, G: primitive root
class Fft(int M_, int G, int K) {
  import std.algorithm : reverse;
  import std.traits : isIntegral;
  alias M = M_;
  // 1, 1/4, 1/8, 3/8, 1/16, 5/16, 3/16, 7/16, ...
  int[] gs;
  this() {
    static assert(2 <= K && K <= 30, "Fft: 2 <= K <= 30 must hold");
    static assert(!((M - 1) & ((1 << K) - 1)), "Fft: 2^K | M - 1 must hold");
    gs = new int[1 << (K - 1)];
    gs[0] = 1;
    long g2 = G, gg = 1;
    for (int e = (M - 1) >> K; e; e >>= 1) {
      if (e & 1) gg = (gg * g2) % M;
      g2 = (g2 * g2) % M;
    }
    gs[1 << (K - 2)] = cast(int)(gg);
    for (int l = 1 << (K - 2); l >= 2; l >>= 1) {
      gs[l >> 1] = cast(int)((cast(long)(gs[l]) * gs[l]) % M);
    }
    assert((cast(long)(gs[1]) * gs[1]) % M == M - 1,
           "Fft: g^(2^(K-1)) == -1 (mod M) must hold");
    for (int l = 2; l <= 1 << (K - 2); l <<= 1) {
      foreach (i; 1 .. l) {
        gs[l + i] = cast(int)((cast(long)(gs[l]) * gs[i]) % M);
      }
    }
  }
  void fft(int[] xs) const {
    const n = cast(int)(xs.length);
    assert(!(n & (n - 1)), "Fft.fft: |xs| must be a power of two");
    assert(n <= 1 << K, "Fft.fft: |xs| <= 2^K must hold");
    for (int l = n; l >>= 1; ) {
      foreach (i; 0 .. (n >> 1) / l) {
        const(long) g = gs[i];
        foreach (j; (i << 1) * l .. (i << 1 | 1) * l) {
          const t = cast(int)((g * xs[j + l]) % M);
          if ((xs[j + l] = xs[j] - t) < 0) xs[j + l] += M;
          if ((xs[j] += t) >= M) xs[j] -= M;
        }
      }
    }
  }
  void invFft(int[] xs) const {
    const n = cast(int)(xs.length);
    assert(!(n & (n - 1)), "Fft.invFft: |xs| must be a power of two");
    assert(n <= 1 << K, "Fft.invFft: |xs| <= 2^K must hold");
    for (int l = 1; l < n; l <<= 1) reverse(xs[l .. l << 1]);
    for (int l = 1; l < n; l <<= 1) {
      foreach (i; 0 .. (n >> 1) / l) {
        const(long) g = gs[i];
        foreach (j; (i << 1) * l .. (i << 1 | 1) * l) {
          int t = cast(int)((g * (xs[j] - xs[j + l])) % M);
          if (t < 0) t += M;
          if ((xs[j] += xs[j + l]) >= M) xs[j] -= M;
          xs[j + l] = t;
        }
      }
    }
  }
  T[] convolute(T)(inout(T)[] as, inout(T)[] bs) const if (isIntegral!T) {
    const na = cast(int)(as.length), nb = cast(int)(bs.length);
    int n, invN = 1;
    for (n = 1; n < na + nb - 1; n <<= 1) {
      invN = ((invN & 1) ? (invN + M) : invN) >> 1;
    }
    auto xs = new int[n], ys = new int[n];
    foreach (i; 0 .. na) if ((xs[i] = cast(int)(as[i] % M)) < 0) xs[i] += M;
    foreach (i; 0 .. nb) if ((ys[i] = cast(int)(bs[i] % M)) < 0) ys[i] += M;
    fft(xs);
    fft(ys);
    foreach (i; 0 .. n) {
      xs[i] = cast(int)((((cast(long)(xs[i]) * ys[i]) % M) * invN) % M);
    }
    invFft(xs);
    auto cs = new T[na + nb - 1];
    foreach (i; 0 .. na + nb - 1) cs[i] = cast(T)(xs[i]);
    return cs;
  }
}

alias Fft0 = Fft!(998244353, 3, 20);

void main() {
  const FFT = new Fft0;

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

        auto fs = new int[N + 1];
        auto gs = new int[N + 1];
        foreach (i; 0 .. N) {
          switch (S[i]) {
            case 'V': ++fs[i]; break;
            case 'K': ++gs[N - i]; break;
            default: {}
          }
        }
        const hs = FFT.convolute(fs, gs);
        debug {
          writeln("hs = ", hs);
        }

        auto has = new bool[N + 1];
        foreach (x; -N .. +N + 1) {
          if (hs[N + x]) {
            has[abs(x)] = true;
          }
        }

        int[] ans;
        foreach (k; 1 .. N + 1) {
          bool ok = true;
          for (int l = k; l <= N; l += k) {
            ok = ok && !has[l];
          }
          if (ok) {
            ans ~= k;
          }
        }
        writeln(ans.length);
        foreach (index, k; ans) {
          if (index > 0) write(" ");
          write(k);
        }
        writeln;
      }
    }
  } catch (EOFException e) {
  }
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int tt;
	read(tt);
	auto a = new Complex!double[1 << 20], b = new Complex!double[1 << 20];
	auto ca = a.dup, cb = b.dup;
	auto d = new int[1 << 20];
	auto r = new int[500_000];
	Fft f = new Fft(1 << 20);
	string s;
	foreach (ii; 0 .. tt)
	{
		s = readln;
		int n;
		read(n);
		s = readln.strip;
		int st = 1;
		while (st <= n)
			st *= 2;
		st *= 2;
		auto z = Complex!double(0, 0);
		a[0 .. st] = z;
		b[0 .. st] = z;
		ca[0 .. st] = z;
		cb[0 .. st] = z;
		foreach (i; 0 .. n)
		{
			if (s[i] == 'V')
				a[i] = 1;
			else if (s[i] == 'K')
				b[n - 1 - i] = 1;
		}
		f.fft(a[0 .. st], ca[0 .. st]);
		f.fft(b[0 .. st], cb[0 .. st]);
		ca[0 .. st] *= cb[0 .. st];
		cb[0 .. st] = z;
		debug writeln(ca[0 .. st]);
		f.inverseFft(ca[0 .. st], cb[0 .. st]);
		foreach (i; 0 .. st)
		{
			d[i] = roundTo!int(cb[i].re);
		}
		r[n - 1] = d[n - 1];
		foreach (i; 1 .. n)
		{
			r[i] = d[n - 1 - i] + d[n - 1 + i];
		}
		int[] ans;
		foreach (i; 1 .. n)
		{
			bool flag = true;
			foreach (j; 1 .. (n - 1) / i + 1)
			{
				if (r[i * j])
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				ans ~= i;
			}
		}
		ans ~= n;
		writeln(ans.length);
		foreach (x; ans)
		{
			write(x, ' ');
		}
		writeln;
	}
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int tt;
	read(tt);
	auto a = new Complex!double[1 << 20], b = new Complex!double[1 << 20];
	auto ca = a.dup, cb = b.dup;
	auto d = new int[1 << 20];
	auto r = new int[500_000];
	Fft f = new Fft(1 << 20);
	string s;
	foreach (ii; 0 .. tt)
	{
		s = readln;
		int n;
		read(n);
		s = readln.strip;
		int st = 1;
		while (st <= n)
			st *= 2;
		st *= 2;
		auto z = Complex!double(0, 0);
		a[0 .. st] = z;
		b[0 .. st] = z;
		ca[0 .. st] = z;
		cb[0 .. st] = z;
		foreach (i; 0 .. n)
		{
			if (s[i] == 'V')
				a[i] = 1;
			else if (s[i] == 'K')
				b[n - 1 - i] = 1;
		}
		f.fft(a[0 .. st], ca[0 .. st]);
		f.fft(b[0 .. st], cb[0 .. st]);
		ca[0 .. st] *= cb[0 .. st];
		cb[0 .. st] = z;
		debug writeln(ca[0 .. st]);
		f.inverseFft(ca[0 .. st], cb[0 .. st]);
		foreach (i; 0 .. st)
		{
			d[i] = roundTo!int(cb[i].re);
		}
		r[n - 1] = d[n - 1];
		foreach (i; 1 .. n)
		{
			r[i] = d[n - 1 - i] + d[n - 1 + i];
		}
		int[] ans;
		foreach (i; 1 .. n)
		{
			bool flag = true;
			foreach (j; 1 .. (n - 1) / i + 1)
			{
				if (r[i * j])
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				ans ~= i;
			}
		}
		ans ~= n;
		writeln(ans.length);
		foreach (x; ans)
		{
			write(x, ' ');
		}
	}
}

import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,
	std.complex, std.bitmanip, std.conv, std.math;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.random, std.range, std.regex, std.stdio, std.string, std.traits,
	std.typecons, std.uni;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
const int mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	static if (version_minor >= 74)
	{
		///read without format
		bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
		}
		///readln without format
		bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
		{
			const bool fl = readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
			readln;
			return fl;
		}
	}
	else
	{
		///read without format
		bool input(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			return s == ptrs.length;
		}
		///readln without format
		bool read(T...)(ref T ptrs) if (ptrs.length > 0)
		{
			size_t s;
			foreach (ref e; ptrs)
			{
				if (isSomeChar!(Unqual!(typeof(e))))
					s += readf(" %c", &e);
				else
					s += readf(" %s", &e);
			}
			readln;
			return s == ptrs.length;
		}
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------
void main()
{
	version (home)
	{
		assert(freopen("input.txt", "r", core.stdc.stdio.stdin));
	}
	int tt;
	read(tt);
	auto a = new Complex!double[1 << 20], b = new Complex!double[1 << 20];
	auto ca = a.dup, cb = b.dup;
	auto d = new int[1 << 20];
	auto r = new int[500_000];
	Fft f = new Fft(1 << 20);
	foreach (ii; 0 .. tt)
	{
		auto s = readln;
		int n;
		read(n);
		s = readln.strip;
		int st = 1;
		while (st <= n)
			st *= 2;
		st *= 2;
		auto z = Complex!double(0, 0);
		a[0 .. st] = z;
		b[0 .. st] = z;
		ca[0 .. st] = z;
		cb[0 .. st] = z;
		foreach (i; 0 .. n)
		{
			if (s[i] == 'V')
				a[i] = 1;
			else if (s[i] == 'K')
				b[n - 1 - i] = 1;
		}
		f.fft(a[0 .. st], ca[0 .. st]);
		f.fft(b[0 .. st], cb[0 .. st]);
		ca[0 .. st] *= cb[0 .. st];
		cb[0 .. st] = z;
		debug writeln(ca[0 .. st]);
		f.inverseFft(ca[0 .. st], cb[0 .. st]);
		foreach (i; 0 .. st)
		{
			d[i] = roundTo!int(cb[i].re);
		}
		r[n - 1] = d[n - 1];
		foreach (i; 1 .. n)
		{
			r[i] = d[n - 1 - i] + d[n - 1 + i];
		}
		int[] ans;
		foreach (i; 1 .. n)
		{
			bool flag = true;
			foreach (j; 1 .. (n - 1) / i + 1)
			{
				if (r[i * j])
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				ans ~= i;
			}
		}
		ans ~= n;
		writeln(ans.length);
		foreach (x; ans)
		{
			write(x, ' ');
		}
	}
}


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 N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    int[int] cnt;
    foreach (a; A) cnt[a] += 1;

    auto cumsum = new int[](N+2);
    foreach (a; cnt.values) cumsum[a+1] += 1;
    foreach (i; 0..N+1) cumsum[i+1] += cumsum[i];

    int calc_maxh(int w, int n) {
        return n / w;
    }

    int[][] build(int h, int w) {
        int[] B;
        Tuple!(int, int)[] C;

        foreach (k, v; cnt) C ~= tuple(k, min(w, v));
        C.sort!"a[1] > b[1]";
        foreach (c; C) foreach (_; 0..c[1]) B ~= c[0];

        auto ans = new int[][](h, w);
        int idx = 0;

        for (int r = 0, c = 0; idx < h * w; ++idx) {
            while (ans[r][c] != 0) (c += 1) %= w;
            ans[r][c] = B[idx];
            (r += 1) %= h;
            (c += 1) %= w;
        }

        return ans;
    }

    int maxh = 0;
    int maxw = 0;
    int count = cnt.keys.length.to!int;

    foreach (i; 1..sqrt(N.to!real).to!int+10) {
        if (count < i * i) break;
        int h = calc_maxh(i, count);
        if (h * i >= maxh * maxw) {
            maxh = h;
            maxw = i;
        }
        count += (cumsum[N] - cumsum[i+1]);
    }

    auto ans = build(maxh, maxw);
    writeln(maxh * maxw);
    writeln(maxh, " ", maxw);
    ans.map!(a => a.map!(to!string).join(" ")).each!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 N = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }
      A.sort;

      auto ds = new int[N + 1];
      ds[1 .. $] = 1;
      foreach (d; 1 .. N + 1) {
        for (int m = d; m <= N; m += d) {
          chmax(ds[m], min(d, m / d));
        }
      }
      debug {
        writeln("ds = ", ds);
      }

      BinaryHeap!(Array!(Tuple!(int, int))) que;
      foreach (grp; A.group) {
        que.insert(tuple(cast(int)(grp[1]), grp[0]));
      }
      for (int m = N; m > 0; --m) {
        if (que.front[0] <= ds[m]) {
          const d = ds[m], e = m / ds[m];
          auto ans = new int[][](d, e);
          int pos;
          for (; !que.empty; ) {
            auto t = que.front;
            que.removeFront;
            foreach (_; 0 .. t[0]) {
              ans[pos % d][(pos % d + pos / d) % e] = t[1];
              ++pos;
            }
          }
          writeln(m);
          writeln(d, " ", e);
          foreach (x; 0 .. d) {
            foreach (y; 0 .. e) {
              if (y > 0) write(" ");
              write(ans[x][y]);
            }
            writeln();
          }
          break;
        }
        auto t = que.front;
        que.removeFront;
        if (t[0] >= 2) {
          que.insert(tuple(t[0] - 1, t[1]));
        }
      }
    }
  } catch (EOFException e) {
  }
}

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

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    int[int] cnt;
    foreach (a; A) cnt[a] += 1;

    bool check(int n) {
        int sq = sqrt(n.to!real).to!int;
        while (sq * sq > n) --sq;
        while ((sq + 1) * (sq + 1) <= n) ++sq;
        return cnt.values.map!(a => min(a, sq)).sum >= sq * sq;
    }

    int[][] build(int n) {
        int sq = sqrt(n.to!real).to!int;
        while (sq * sq > n) --sq;
        while ((sq + 1) * (sq + 1) <= n) ++sq;

        int[] B;
        Tuple!(int, int)[] C;

        foreach (k, v; cnt) C ~= tuple(k, v);
        C.sort!"a[1] > b[1]";
        foreach (c; C) foreach (_; 0..c[1]) B ~= c[0];

        auto sm = C.map!(a => a[1]).sum;

        int h = sq, w = sq;
        while ((h + 1) * w <= sm) ++h;

        auto ans = new int[][](h, w);
        int idx = 0;

        for (int r = 0, c = 0; idx < h * w; ++idx) {
            while (ans[r][c] != 0) (c += 1) %= w;
            ans[r][c] = B[idx];
            (r += 1) %= h;
            (c += 1) %= w;
        }

        return ans;
    }

    int hi = sqrt(N.to!real).to!int + 10;
    int lo = 1;

    while (hi - lo > 1) {
        auto mid = (hi + lo) / 2;
        (check(mid) ? lo : hi) = mid;
    }

    auto ans = build(lo);
    auto h = ans.length.to!int;
    auto w = ans.front.length.to!int;
    writeln(h * w);
    writeln(h, " ", w);
    ans.map!(a => a.map!(to!string).join(" ")).each!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 N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    int[int] cnt;
    foreach (a; A) cnt[a] += 1;

    bool check(int n) {
        int sq = sqrt(n.to!real).to!int;
        while (sq * sq > n) --sq;
        while ((sq + 1) * (sq + 1) <= n) ++sq;
        return cnt.values.map!(a => min(a, sq)).sum >= sq * sq;
    }

    int[][] build(int n) {
        int sq = sqrt(n.to!real).to!int;
        while (sq * sq > n) --sq;
        while ((sq + 1) * (sq + 1) <= n) ++sq;

        int[] B;
        Tuple!(int, int)[] C;

        foreach (k, v; cnt) C ~= tuple(k, min(sq, v));
        C.sort!"a[1] > b[1]";
        foreach (c; C) foreach (_; 0..c[1]) B ~= c[0];

        auto sm = C.map!(a => a[1]).sum;

        int h = sq, w = sq;
        while ((h + 1) * w <= sm) ++h;

        auto ans = new int[][](h, w);
        int idx = 0;

        for (int r = 0, c = 0; idx < h * w; ++idx) {
            while (ans[r][c] != 0) (c += 1) %= w;
            ans[r][c] = B[idx];
            (r += 1) %= h;
            (c += 1) %= w;
        }

        return ans;
    }

    int hi = sqrt(N.to!real).to!int + 10;
    int lo = 1;

    while (hi - lo > 1) {
        auto mid = (hi + lo) / 2;
        (check(mid) ? lo : hi) = mid;
    }

    auto ans = build(lo);
    auto h = ans.length.to!int;
    auto w = ans.front.length.to!int;
    writeln(h * w);
    writeln(h, " ", w);
    ans.map!(a => a.map!(to!string).join(" ")).each!writeln;
}


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

int num (int limit, int bit)
{
	auto half = 1 << bit;
	auto full = half << 1;
	auto pieces = limit / full;
	auto tail = limit % full;
	auto res = pieces * half + min (tail, half);
	return res;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int lo, hi;
		readf !(" %s %s") (lo, hi);
		int res = int.max;
		foreach (i; 0..30)
		{
			res = min (res, num (hi + 1, i) - num (lo, i));
		}
		writeln (res);
	}
}

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 euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	auto cnt = new long[][](18, 2*(10^^5)+1);
	foreach (i; 0..18)
	{
		auto bit = 1L << i;
		foreach (j; 1..2*(10^^5)+1)
		{
			cnt[i][j] = cnt[i][j-1];
			if (j & bit)
				++cnt[i][j];
		}
	}
	foreach (ti; 0..t)
	{
		auto l = RD!int;
		auto r = RD!int;

		auto len = r - l + 1;
		ans[ti] = long.max;
		foreach (i; 0..18)
		{
			ans[ti].chmin(len - (cnt[i][r]-cnt[i][l-1]));
		}
	}

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

immutable multi = true;

void solve(int tc)
{
  auto l = readInt!uint;
  auto r = readInt!uint;
  int ans = int.max;
  int getOnes(int n, int b)
  {
    int blksize = (1 << b);
    int blk = n / blksize;
    int off = n % blksize;
    if (blk == 0) return 0;
    int pblk = blk;
    int blk1 = pblk / 2;
    if (blk&1) off++;
    else off = 0;
    return blk1 * blksize + off;
  }
  foreach(bit; 0 .. 32)
    {
      auto or = getOnes(r, bit);
      auto ol = getOnes(l-1, bit);
      debug writeln(bit, " ", or, " ", ol);
      ans = min(ans, r - l + 1 - (or - ol));
    }
  ans.writeln;
}

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

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

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

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

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

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

void cnt_set_bit(ref int[32] bitcnt, int n)
{
  if (n == 0)
    return;

  int p = -1;
  while (1 << (p + 1) <= n)
    p++;

  foreach (i ; 0 .. p)
    bitcnt[i] += (1 << p) / 2;

  bitcnt[p] += n - (1 << p) + 1;

  cnt_set_bit(bitcnt, n - (1 << p));
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    int l, r;
    int[32] bitcnt;
    readf!" %d %d "(l, r);
    int[32] bitcnt1;
    int[32] bitcnt2;
    cnt_set_bit(bitcnt1, l - 1);
    cnt_set_bit(bitcnt2, r);
    foreach (i ; 0 .. 30) {
      bitcnt[i] = bitcnt2[i] - bitcnt1[i];
    }
    int ans = int.max;
    foreach (bt ; 0 .. 30) {
      if (bitcnt[bt] != 0)
        ans = min(ans, r - l + 1 - bitcnt[bt]);
    }
    writeln(ans);
  }
}

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

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

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

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

enum E = 20;
enum LIM = 2 * 10^^5 + 10;

void main() {
  auto sums = new int[][](E, LIM + 1);
  foreach (e; 0 .. E) {
    foreach (i; 0 .. LIM) {
      sums[e][i + 1] = sums[e][i] + (i >> e & 1);
    }
  }

  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const L = readInt();
        const R = readInt() + 1;

        int ans;
        foreach (e; 0 .. 20) {
          chmax(ans, sums[e][R] - sums[e][L]);
        }
        ans = (R - L) - ans;
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

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

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

		auto len = r - l + 1;
		ans[ti] = len - len / 2 - (len % 2 ? l % 2 : 0);
		foreach (i; 0..18)
		{
			auto bit = 1L << i;
			if (bit < l)
			{
				if (l & bit)
					ans[ti].chmin(len - min(r - l + 1, bit));
				else
				{
					auto x = l | bit;
					x >>= i;
					x <<= i;
					ans[ti].chmin(len - min(r - x + 1, bit));
				}
			}
			else
				ans[ti].chmin(len - min(r - bit + 1, bit));
		}
	}

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

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

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

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

		auto len = r - l + 1;
		ans[ti] = len - len / 2 - (len % 2 ? l % 2 : 0);
		foreach (i; 0..18)
		{
			auto bit = 1L << i;
			if (bit < l) continue;
			ans[ti].chmin(len - min(r - bit + 1, bit));
		}
	}

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

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
double euDist(T)(T[] a, T[] b) { auto c = a.dup; c[] -= b[]; c[] *= c[]; return sqrt(cast(double)c.sum); }
double[] rotate(double[] vec, double rad) { return [cos(rad)*vec[0] - sin(rad)*vec[1], sin(rad)*vec[0] + cos(rad)*vec[1]]; }
double norm(double[] vec) { return sqrt(reduce!((a,b)=>a+b*b)(0.0, vec)); }
double dotProd(double[] a, double[] b) { auto r = a.dup; r[] *= b[]; return r.sum; }

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

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

		auto len = r - l + 1;
		ans[ti] = len - (len+1) / 2;
		foreach (i; 0..18)
		{
			auto bit = 1L << i;
			if (bit < l) continue;
			ans[ti].chmin(len - min(r - bit + 1, bit-1));
		}
	}

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


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

void main() {
    debug stdin = File("input.txt", "r");

    int n;
    readf("%d\n", &n);
    string[] words = new string[n];
    foreach (ref word; words) {
        readf("%s\n", &word);
    }

    string s;
    readf("%s\n", &s);

    foreach (ref word; words) {
        word = "<3" ~ word;
    }
    words[$ - 1] ~= "<3";

    string all = join(words);

    int cur = 0;
    foreach (c; s) {
        if (c == all[cur]) {
            ++cur;
        }
        if (cur == all.length){
            writeln("yes");
            return;
        }
    }

    writeln("no");
}

import std.stdio;
import std.conv;

int main(string[] argv)
{
	int n = to!int(readln()[0..$-1]);

	string words = "<3";
	for (int i = 0; i < n; ++i) {

		words ~= readln()[0..$-1] ~ "<3";
	}
	string code = readln()[0..$-1];
	int t = 0;
	foreach (char ch; words) {
		if (t == code.length) {
			writeln("no");
			return 0;
		}
		while (ch != code[t]) {
			t += 1;
			if (t == code.length) {
				writeln("no");
				return 0;
			}
		}
		t += 1;

	}
	writeln("yes");
    return 0;
}

#!/usr/bin/env rdmd
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;

void main()
{
    for(string S; (S=readln().chomp()).length; )
    {
        auto n = S.to!int();
        string w = "<3";
        foreach(i;0..n)
            w ~= readln().chomp() ~ "<3";
        immutable string t = readln().chomp().idup;
        const auto M = w.length;
        const auto N = t.length;
        if(M>N){ writeln("no"); return; }
        auto dp = new int[N+1];
        auto dpn = new int[N+1];
        foreach(j,v;w)
        {
            foreach(i;j..j+N-M+1)
                dpn[i+1]=max(dpn[i],dp[i+(v==t[i]?0:1)]+(v==t[i]?1:0));
            dp.swap(dpn);
        }
        writeln(w.length==dp[N]?"yes":"no");
    }
}

import std.stdio;
import std.conv;

int main(string[] argv)
{
	int n = to!int(readln()[0..$-1]);

	string words = "<3";
	for (int i = 0; i < n; ++i) {

		words ~= readln()[0..$-1] ~ "<3";
	}
	string code = readln()[0..$-1];
	int t = 0;
	foreach (char ch; words) {
		if (t >= code.length) {
			writeln("no");
			return 0;
		}
		while (ch != code[t]) {
			t += 1;
			if (t >= code.length) {
				writeln("no");
				return 0;
			}
		}
		t += 1;

	}
	writeln("yes");
    return 0;
}

import std.stdio;
import std.conv;

int main(string[] argv)
{
	int n;
	readf(" %d", &n);

	string words;
	for (int i = 0; i < n; ++i) {
		words ~= readln() ~ "<3";
	}
	string code = readln();
	int i = 0;
	foreach (char ch; words) {
		while (ch != code[i]) {
			i += 1;
			if (i == code.length - 1) {
				writeln("no");
				return 0;
			}
		}
		i += 1;
		if (i == code.length - 1) {
			writeln("no");
			return 0;
		}
	}
	writeln("yes");
    return 0;
}

import std.stdio;
import std.conv;

int main(string[] argv)
{
	int n = to!int(readln()[0..$-1]);

	string words = "<3";
	for (int i = 0; i < n; ++i) {

		words ~= readln()[0..$-1] ~ "<3";
	}
	string code = readln()[0..$-1];
	int i = 0;
	foreach (char ch; words) {
		while (ch != code[i]) {
			i += 1;
			if (i == code.length) {
				writeln("no");
				return 0;
			}
		}
		i += 1;
		if (i == code.length) {
			writeln("no");
			return 0;
		}
	}
	writeln("yes");
    return 0;
}


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

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

int main() {
    Scanner sc = new Scanner(stdin);
    int n;
    sc.read(n);
    long[long] mp;
    foreach (i; 0..n) {
        long a, b;
        sc.read(a, b);
        mp[a] = b;
    }
    int m;
    sc.read(m);
    foreach (i; 0..m) {
        long a, b;
        sc.read(a, b);
        if (a !in mp) mp[a] = b;
        else mp[a] = max(mp[a], b);
    }
    writeln(mp.values.sum);
    return 0;
}
/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;

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

    private T* _data;
    private uint len, cap;

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

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

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

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

    void clear() {
        len = 0;
    }

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

/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;

// import dkh.container.stackpayload;

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

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

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

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

/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/foundation.d */

// module dkh.foundation;

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

}

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

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

void main() {
    long[long] s;

    auto N = readln.chomp.to!int;
    foreach (_; 0..N) {
        auto t = readln.split.map!(to!long);
        auto a = t[0];
        auto x = t[1];
        if (a in s) s[a] = max(s[a], x);
        else s[a] = x;
    }

    auto M = readln.chomp.to!int;
    foreach (_; 0..M) {
        auto t = readln.split.map!(to!long);
        auto a = t[0];
        auto x = t[1];
        if (a in s) s[a] = max(s[a], x);
        else s[a] = x;
    }

    s.values.sum.writeln;
}

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

void main()
{
    int [int] mp;

    foreach ( _; 0..2 ) {
        int n;
        readf( "%s", &n );
        readln;

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

            mp[k] = max( mp.get(k, 0), v );
        }
    }

    writeln( mp.values().sum(0L) );
}

import std.algorithm;
import std.stdio;

void main ()
{
	while (true)
	{
		int [int] v;
		foreach (k; 0..2)
		{
			int n;
			if (readf (" %s", &n) != 1)
			{
				return;
			}
			foreach (i; 0..n)
			{
				int a, x;
				readf (" %s %s", &a, &x);
				v[a] = max (v.get (a, x), x);
			}
		}
		writeln (v.byValue.sum (0L));
	}
}


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.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 bAdd(T)(T[] bit, int pos, T val)
in {
  assert(0 <= pos && pos < bit.length, "bAdd: 0 <= pos < |bit| must hold");
}
do {
  for (int x = pos; x < bit.length; x |= x + 1) {
    bit[x] += val;
  }
}

// sum of [0, pos)
T bSum(T)(T[] bit, int pos)
in {
  assert(0 <= pos && pos <= bit.length, "bSum: 0 <= pos <= |bit| must hold");
}
do {
  T sum = 0;
  for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) {
    sum += bit[x];
  }
  return sum;
}

// min pos s.t. pred(sum of [0, pos))
//   assume pred(sum of [0, pos)) is non-decreasing
int bBinarySearch(alias pred, T)(T[] bit) {
  import core.bitop : bsr;
  import std.functional : unaryFun;
  alias predFun = unaryFun!pred;
  if (predFun(0)) return 0;
  int pos = 0;
  T sum = 0;
  foreach_reverse (e; 0 .. bsr(bit.length) + 1) {
    const x = (pos | 1 << e) - 1;
    if (x < bit.length && !predFun(sum + bit[x])) {
      pos |= 1 << e;
      sum += bit[x];
    }
  }
  return pos + 1;
}

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }
      const M = readInt();
      auto K = new int[M];
      auto P = new int[M];
      foreach (m; 0 .. M) {
        K[m] = readInt();
        P[m] = readInt();
      }

      auto queries = new int[][N + 1];
      foreach (m; 0 .. M) {
        queries[K[m]] ~= m;
      }
      auto ans = new int[M];

      auto as = new Tuple!(int, int)[N];
      foreach (i; 0 .. N) {
        as[i] = tuple(A[i], i);
      }
      as.sort!((a, b) => ((a[0] != b[0]) ? (a[0] > b[0]) : (a[1] < b[1])));

      auto bit = new int[N];
      foreach (i; 0 .. N) {
        bit.bAdd(as[i][1], 1);
        foreach (m; queries[i + 1]) {
          const res = bit.bBinarySearch!(s => (s >= P[m]));
          ans[m] = A[res - 1];
        }
      }

      foreach (m; 0 .. M) {
        writeln(ans[m]);
      }
    }
  } 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 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; }

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 a = RDA!int;
	auto m = RD!int;

	int[][int] pos;
	foreach (i; 0..n)
	{
		pos[a[i]] ~= i;
	}

	auto keys = pos.keys;
	keys.sort!"a > b"();
	foreach (i; 0..m)
	{
		auto k = RD!int;
		auto p = RD!int-1;
		bool[int] ans;
		int cnt;
		(){
		foreach (key; keys)
		{
			foreach (j; pos[key])
			{
				ans[j] = true;
				++cnt;
				if (cnt == k) return;
			}
		}}();
		auto keys_a = ans.keys;
		keys_a.sort();
		writeln(a[keys_a[p]]);
	}

	stdout.flush();
	debug readln();
}


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

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

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

    int n, r;
    sc.read(n, r);
    int[] f = new int[n], s = new int[n];
    double[] p = new double[n];
    foreach (i; 0..n) {
        sc.read(f[i], s[i], p[i]); p[i] /= 100;
    }

    double[][] dp = new double[][](n+1, r+1);
    double lx = 0, rx = 1e10;
    foreach (ph; 0..100) {
        double md = (lx+rx)/2;

        dp[n][] = 0.0;
        foreach_reverse (i; 0..n) {
            foreach (j; 0..r+1) {
                dp[i][j] = 0.0;
                if (j+f[i] <= r) {
                    dp[i][j] += p[i] * (f[i] + dp[i+1][j+f[i]]);
                } else {
                    dp[i][j] += p[i] * (f[i] + md);
                }
                if (j+s[i] <= r) {
                    dp[i][j] += (1-p[i]) * (s[i] + dp[i+1][j+s[i]]);
                } else {
                    dp[i][j] += (1-p[i]) * (s[i] + md);
                }
                dp[i][j] = min(dp[i][j], md);
            }
        }

        if (md <= dp[0][0]) {
            lx = md;
        } else {
            rx = md;
        }
    }

    writefln("%.20f", dp[0][0]);
    return 0;
}
/* IMPORT /home/yosupo/Program/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;

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

    private T* _data;
    private uint len, cap;

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

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

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

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

    void clear() {
        len = 0;
    }

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

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

// module dkh.foundation;

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

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

// import dkh.container.stackpayload;

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

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

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

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

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

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const R = readInt();
      auto F = new int[N];
      auto S = new int[N];
      auto P = new real[N];
      foreach (i; 0 .. N) {
        F[i] = readInt();
        S[i] = readInt();
        P[i] = readInt() / 100.0L;
      }

      // <= 5000 * (1 / 0.8)^50
      real lo = 0.0L, hi = 1e+12;
      foreach (_; 0 .. 100) {
        const mid = (lo + hi) / 2.0L;
        auto dp = new real[][](N + 1, R + 1);
        dp[N][] = 0.0L;
        foreach_reverse (i; 0 .. N) {
          foreach (x; 0 .. R + 1) {
            dp[i][x] = 0.0;
            dp[i][x] += P[i] * (F[i] + ((x + F[i] <= R) ? dp[i + 1][x + F[i]] : mid));
            dp[i][x] += (1.0L - P[i]) * (S[i] + ((x + S[i] <= R) ? dp[i + 1][x + S[i]] : mid));
            chmin(dp[i][x], mid);
          }
        }
        ((dp[0][0] < mid) ? hi : lo) = mid;
      }
      writefln("%.12f", lo);
    }
  } catch (EOFException e) {
  }
}


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

int main()
{
    auto t = readInt!int;
    foreach(ti; 0 .. t)
    {
        int[4] s;
        s[0] = readInt!int;
        s[1] = readInt!int;
        s[2] = readInt!int;
        s[3] = readInt!int;
        if (min(s[2], s[3]) > max(s[0], s[1]) || min(s[0], s[1]) > max(s[2], s[3]))
        {
            writeln("NO");
        }
        else writeln("YES");
    }
    return 0;
}

/* 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.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;
import std.numeric;

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto arr = readln().chomp.splitter(" ").map!(to!long).array;
        auto rev = arr.retro.array;

        if(arr[0] > arr[2] && arr[1] > arr[2] && arr[0] > arr[3] && arr[1] > arr[3])
            writeln("NO");
        else if(rev[0] > rev[2] && rev[1] > rev[2] && rev[0] > rev[3] && rev[1] > rev[3])
            writeln("NO");
        else
            writeln("YES");
    }
}

// Vicfred
// https://codeforces.com/contest/1535/problem/A
// implementation
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[] s = readln.split.map!(to!int).array;

    int winner_a = max(s[0],s[1]);
    int winner_b = max(s[2],s[3]);

    if(winner_a > winner_b)
        swap(winner_a, winner_b);

    s.sort;
    s = [s[2],s[3]];

    if(winner_a == s[0] && winner_b == s[1])
        "YES".writeln;
    else
        "NO".writeln;
}
}

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

void main()
{
  int t;
  readf!" %d "(t);
  while (t--) {
    auto b = readln.chomp.split.map!(to!int).array;
    auto a = b.dup;
    b.sort;
    int[int] winners;
    winners[b[2]] = true;
    winners[b[3]] = true;
//    writeln(a);
//    writeln(winners);
    if ((winners.get(a[0], false) || winners.get(a[1], false)) &&
        (winners.get(a[2], false) || winners.get(a[3], false))) {
      writeln("YES");
    } else {
      writeln("NO");
    }
  }
}

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 a = readln.splitter.map !(to !(int)).array;
		writeln (min (a[0], a[1]) < max (a[2], a[3]) &&
		    min (a[2], a[3]) < max (a[0], a[1]) ? "YES" : "NO");
	}
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;
import std.numeric;

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto arr = readln().chomp.splitter(" ").map!(to!long).array;
        auto rev = arr.retro.array;

        if(arr[0] > arr[2] && arr[1] > arr[2])
            writeln("NO");
        else if(rev[0] > rev[2] && rev[1] > rev[2])
            writeln("NO");
        else
            writeln("YES");
    }
}

import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.string;
import std.uni;
import std.math;
import std.container.rbtree;
import std.range;
import std.numeric;

void main()
{
    auto t = to!long(readln().chomp);
    OUTER: foreach(_; 0..t)
    {
        auto arr = readln().chomp.splitter(" ").map!(to!long).array;
        auto rev = arr.retro.array;

        if(arr[0] > arr[2] && arr[1] > arr[2] && arr[0] > arr[3] && arr[1] > arr[4])
            writeln("NO");
        else if(rev[0] > arr[2] && rev[1] > rev[2] && rev[0] > rev[3] && rev[1] > rev[4])
            writeln("NO");
        else
            writeln("YES");
    }
}


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

immutable long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    int ans = 0;
    int tmp = 0;

    foreach (i; 0..N) {
        tmp = max(tmp, A[i]);
        if (i + 1 == tmp) ans += 1, tmp = 0;
    }

    ans.writeln;
}

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

int[10^^4+1] MEMO;

void main()
{
    auto N = readln.chomp.to!int;
    int n, r;
    foreach (i, a; readln.split.to!(int[])) {
        ++n;
        ++MEMO[a-1];
        n -= MEMO[i];
        if (!n) ++r;
    }
    writeln(r);
}


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

string FMT_F = "%.10f";

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

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

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

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

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

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

		if (x >= y)
			ans[ti] = [x-1, y];
		else
			ans[ti] = [x-1, y];
	}

	foreach (e; ans)
		writeln(e[0], " ", e[1]);
	stdout.flush;
	debug readln;
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int a, b;
		readf !(" %s %s") (a, b);
		writeln (a - 1, " ", b);
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

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

		if (x >= y)
			ans[ti] = [x-y, 1];
		else
			ans[ti] = [x-1, y];
	}

	foreach (e; ans)
		writeln(e[0], " ", e[1]);
	stdout.flush;
	debug readln;
}

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

string FMT_F = "%.10f";

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

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

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

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

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

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

		if (x >= y)
			ans[ti] = [x-y, 1];
		else
			ans[ti] = [0, y-x+1];
	}

	foreach (e; ans)
		writeln(e[0], " ", e[1]);
	stdout.flush;
	debug readln;
}


immutable multi = true;

void solve(int tc)
{
  auto str = readString;
  if (str.length == 2)
    {
      if (str[0] != str[1]) return writeln("NO");
    }
  if (str.count!(ci => ci == 'N') == 1) return writeln("NO");
  return writeln("YES");
}

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

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

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

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

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

import std.stdio;
import std.algorithm;

void main () {
    auto readN = () { int n; readf("%s\n", n); return n; };

    immutable n = readN();

    foreach (i; 0 .. n) {
        string s = readln()[0 .. $ - 1];
        writeln(s.count('N') == 1 ? "NO" : "YES");
    }
}

// ""

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

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto s = readln.strip;
    writeln(s.count('N') == 1 ? "NO" : "YES");
  }
}

immutable multi = true;

void solve(int tc)
{
  auto str = readString;
  if (str.length == 2)
    {
      if (str[0] != str[1]) return writeln("NO");
    }
  if (str[0 .. $ - 1].count!(ci => ci == 'N') == 1) return writeln("NO");
  return writeln("YES");
}

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

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

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

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

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

immutable multi = true;

void solve(int tc)
{
  auto str = readString;
  if (str.length == 2)
    {
      if (str[0] != str[1]) return writeln("NO");
    }
  return writeln("YES");
}

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

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

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

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

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


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		auto g = a.group.map !(q{a[0]}).array;
		int [int] v;
		foreach (x; g)
		{
			v[x] += 1;
		}
		int res = int.max;
		foreach (x, num; v)
		{
			res = min (res, num - (x == g.front) - (x == g.back));
		}
		writeln (res + 1);
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		long[] b = [a[0]];
		foreach (i; 1..n)
		{
			if (a[i-1] != a[i])
				b ~= a[i];
		}
		auto cnt = new long[](n);
		foreach (e; b)
		{
			++cnt[cast(int)e];
		}
		ans[ti] = long.max;
		foreach (i; 0..n)
		{
			if (cnt[i] == 0) continue;
			if (i == b[0])
				--cnt[i];
			if (i == b[$-1])
				--cnt[i];
			ans[ti].chmin(cnt[i]+1);
		}
	}

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