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

void main()
{
	int n,q;
	while(input(&n,&q))
	{
		auto s=new int[n];
		foreach(i;0..q)
		{
			int t,k,d;
			input(&t,&k,&d);
			int r;
			foreach(j;s)if(j<=t)r++;
			//writeln(r);
			if(r<k)writeln(-1);
			else
			{
				int p=0,ans;
				while(k)
				{
					if(s[p]<=t) {s[p]=t+d;k--;ans+=p+1;}
					p++;
				}
				writeln(ans);
			}
		}
	}
	debug readln;
}

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

__gshared:

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

T[ ] allocate(T)(size_t n) {
    return (cast(T*)malloc(n * T.sizeof))[0 .. n];
}

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

struct Mask {
    size_t[(100 + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)] data;

    int bsf() const {
        foreach (i, x; data)
            if (x)
                return cast(int)(.bsf(x) + (i * size_t.sizeof * 8));
        return -1;
    }
}

alias Event = Tuple!(int, `t`, bool, `open`, int, `k`, int, `id`);

Event[200_000] _events;
Mask[100_000] _masks;

void main() {
    int n, q;
    while (read(&n, &q)) {
        auto events = _events[0 .. q << 1];
        auto masks = _masks[0 .. q];
        version (LocalProject)
            foreach (ref m; masks)
                m.data[ ] = 0x0;
        foreach (i; 0 .. q) {
            int t, k, d;
            read(&t, &k, &d);
            events[i << 1] = Event(t, true, k, i);
            events[i << 1 | 0x1] = Event(t + d, false, k, i);
        }
        events.multiSort!(`a.t < b.t`, `a.open < b.open`);

        Mask cur;
        memset(cur.data.ptr, 0xFF, cur.data.sizeof);
        nextEvent: foreach (ref e; events)
            if (e.open) {
                debug writeln("start ", e.id);
                int result = 0;
                foreach (i; 0 .. e.k) {
                    int t = cur.bsf();
                    debug writeln("Got ", t);
                    if (~t && t < n) {
                        result += t;
                        btr(cur.data.ptr, t);
                        bts(masks[e.id].data.ptr, t);
                    } else {
                        writeln("-1");
                        cur.data[ ] |= masks[e.id].data[ ];
                        masks[e.id].data[ ] = 0x0;
                        continue nextEvent;
                    }
                }
                writeln(result + e.k);
            } else {
                debug writeln("stop ", e.id);
                cur.data[ ] |= masks[e.id].data[ ];
            }
        debug writeln();
    }
}

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

__gshared:

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

T[ ] allocate(T)(size_t n) {
    return (cast(T*)malloc(n * T.sizeof))[0 .. n];
}

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

struct Mask {
    size_t[(100 + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)] data;

    int bsf() const {
        foreach (i, x; data)
            if (x)
                return cast(int)(.bsf(x) + (i << size_t.sizeof));
        return -1;
    }
}

alias Event = Tuple!(int, `t`, bool, `open`, int, `k`, int, `id`);

Event[200_000] _events;
Mask[100_000] _masks;

void main() {
    int n, q;
    while (read(&n, &q)) {
        auto events = _events[0 .. q << 1];
        auto masks = _masks[0 .. q];
        version (LocalProject)
            foreach (ref m; masks)
                m.data[ ] = 0x0;
        foreach (i; 0 .. q) {
            int t, k, d;
            read(&t, &k, &d);
            events[i << 1] = Event(t, true, k, i);
            events[i << 1 | 0x1] = Event(t + d, false, k, i);
        }
        events.multiSort!(`a.t < b.t`, `a.open < b.open`);

        Mask cur;
        memset(cur.data.ptr, 0xFF, cur.data.sizeof);
        nextEvent: foreach (ref e; events)
            if (e.open) {
                debug writeln("start ", e.id);
                int result = 0;
                foreach (i; 0 .. e.k) {
                    int t = cur.bsf();
                    debug writeln("Got ", t);
                    if (~t && t < n) {
                        result += t;
                        btr(cur.data.ptr, t);
                        bts(masks[e.id].data.ptr, t);
                    } else {
                        writeln("-1");
                        cur.data[ ] |= masks[e.id].data[ ];
                        masks[e.id].data[ ] = 0x0;
                        continue nextEvent;
                    }
                }
                writeln(result + e.k);
            } else {
                debug writeln("stop ", e.id);
                cur.data[ ] |= masks[e.id].data[ ];
            }
        debug writeln();
    }
}


import std.stdio;
import std.algorithm.comparison;
import std.algorithm.sorting;
import std.algorithm.mutation;
import std.range;
import std.range.primitives;
import std.conv;
import std.bigint;

int main() {
    debug stdin = File("in.txt", "r");

    string str;
    readf(" %s\n", &str);
    bool[] prefnd = new bool[str.length];
    int a, b;
    readf(" %s %s\n", &a, &b);
    int pre = 0, pm = 0;
    foreach ( i; 0 .. str.length - 1 ) {
        pre += str[i] - '0';
        pm = pre % a;
        if (pm == 0) prefnd[i] = true;
        pre = pm * 10;
    }
    int ten = 1, sm = 0;
    foreach_reverse( i; 1 .. str.length ) {
        sm = (sm + (str[i] - '0') * ten) % b;
        if (sm == 0 && prefnd[i - 1] && str[i] != '0') {
            writeln("YES\n", str[0 .. i], "\n", str[i .. $]);
            return 0;
        }
        ten = (ten * 10) % b;
    }
    writeln("NO");

    return 0;
}

import std.stdio;
import std.algorithm.comparison;
import std.algorithm.sorting;
import std.algorithm.mutation;
import std.range;
import std.range.primitives;
import std.conv;
import std.bigint;

int main() {
    debug stdin = File("in.txt", "r");

    string str;
    readf(" %s\n", &str);
    bool[] prefnd = new bool[str.length];
    int a, b;
    readf(" %s %s\n", &a, &b);
    long pre = 0, pm = 0;
    foreach ( i; 0 .. str.length - 1 ) {
        pre += str[i] - '0';
        pm = pre % a;
        if (pm == 0) prefnd[i] = true;
        pre = pm * 10;
    }
    long ten = 1, sm = 0;
    foreach_reverse( i; 1 .. str.length ) {
        sm = (sm + (str[i] - '0') * ten) % b;
        if (sm == 0 && prefnd[i - 1] && str[i] != '0') {
            writeln("YES\n", str[0 .. i], "\n", str[i .. $]);
            return 0;
        }
        ten = (ten * 10) % b;
    }
    writeln("NO");

    return 0;
}


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

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

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

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void printSpaces(int n) {
        while (n--) {
                write(" ");
        }
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        while (t--) {
                string[] arr = stdin.byLineCopy.array;
                // writeln(arr[0..$]);
                int max_len = -999;
                foreach(i; arr) {
                        max_len = max(max_len, cast(int)i.length);
                }

                for (int i = 0; i < max_len + 2; i++) {
                        write("*");
                }
                int alt = 0;
                writeln();
                for (int i = 0; i < arr.length; i++) {
                        write("*");
                        int sample_len = cast(int)arr[i].length;
                        int diff = (max_len - sample_len);
                        if (diff % 2 == 0) {
                                printSpaces(diff / 2);
                                write(arr[i]);
                                printSpaces(diff / 2);
                        } else {
                                if (alt % 2 == 0) {
                                        printSpaces(diff / 2);
                                        write(arr[i]);
                                        printSpaces(diff / 2 + 1);
                                        alt = 1;
                                } else {
                                        printSpaces(diff / 2 + 1);
                                        write(arr[i]);
                                        printSpaces(diff / 2);
                                        alt = 0;
                                }
                        }
                        writeln("*");
                }

                for (int i = 0; i < max_len + 2; i++) {
                        write("*");
                }
        }
}

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

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

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

        double read_double() {
                return read_string.to!double;
        }

        string[] tokens;
}

void printSpaces(int n) {
        while (n--) {
                write(" ");
        }
}

void main() {
        IO cin;
        int t = 1;
        // t = cin.read_int;
        string[] arr;
        while (t--) {
                string x;
                foreach (line; stdin.byLineCopy)
                        arr ~= line;

                // writeln(arr[0..$]);
                int max_len = -999;
                foreach(i; arr) {
                        max_len = max(max_len, cast(int)i.length);
                }

                for (int i = 0; i < max_len + 2; i++) {
                        write("*");
                }
                int alt = 0;
                writeln();
                for (int i = 0; i < arr.length; i++) {
                        write("*");
                        int sample_len = cast(int)arr[i].length;
                        int diff = (max_len - sample_len);
                        if (diff % 2 == 0) {
                                printSpaces(diff / 2);
                                write(arr[i]);
                                printSpaces(diff / 2);
                        } else {
                                if (alt % 2 == 0) {
                                        printSpaces(diff / 2);
                                        write(arr[i]);
                                        printSpaces(diff / 2 + 1);
                                        alt = 1;
                                } else {
                                        printSpaces(diff / 2 + 1);
                                        write(arr[i]);
                                        printSpaces(diff / 2);
                                        alt = 0;
                                }
                        }
                        writeln("*");
                }

                for (int i = 0; i < max_len + 2; i++) {
                        write("*");
                }
        }
}

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

void main() {
    string[] text;
    int longest = 0;
    immutable border = "*";
    immutable fill = " ";

    string line;
    while ((line = readln) != null) {
        line = line.chomp;
        text ~= line;
        longest = max(longest, line.length);
    }

    bool roundLeft = true;

    writeln(border, border.replicate(longest), border);
    foreach (string s; text) {
        int numSpaces = (longest - s.length) / 2;

        string spaces = fill.replicate(numSpaces);

        if ((s.length + longest) % 2 == 1) {
            if (roundLeft) {
                writeln(border, spaces, s, spaces, fill, border);
            } else {
                writeln(border, fill, spaces, s, spaces, border);
            }

            roundLeft = !roundLeft;
        } else {
            writeln(border, spaces, s, spaces, border);
        }
    }
    writeln(border, border.replicate(longest), border);
}


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

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

    auto s = readln.chomp.split.array;

    auto total = s.map!(x => x.length).sum + s.length - 1;

    debug { total.writeln; }

    int mx = 1;
    int [string] vals;

    int[] nrs;
    foreach (e; s) {
        if (e !in vals) vals[e] = mx++;

        nrs ~= vals[e];
    }

    debug { nrs.writeln; }

    auto ans = total;
    foreach (st; 0 .. n) {
        auto gain = 0;
        auto len = 0;
        foreach (end; st+1 .. n) {
            debug { nrs[st..end].writeln; }
            auto regs = 1;

            len += 1;
            gain += s[end-1].length - 1 + cast(int)(end-1 != st);

            for (int p = end; p + len <= n; ++p) {
                if (nrs[st..end] == nrs[p..p+len]) {
                    debug { p.writeln; }
                    ++regs;
                    p += len - 1;
                }
            }

            if (regs > 1) ans = min(ans, total - gain * regs);
        }
    }

    ans.writeln;
}

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

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

    auto s = readln.chomp.split.array;

    auto total = s.length - 1 + s.map!(x => x.length).sum;

    debug { total.writeln; }

    int mx = 1;
    int [string] vals;

    int[] nrs;
    foreach (e; s) {
        if (e !in vals) vals[e] = mx++;

        nrs ~= vals[e];
    }

    debug { nrs.writeln; }

    auto ans = total;
    foreach (st; 0 .. n) {
        auto gain = 0;
        foreach (end; st+1 .. n) {
            debug { nrs[st..end].writeln; }
            auto regs = 1;

            gain += s[end-1].length - 1 + cast(int)(end-1 != st);

            for (int p = end; p + end - st <= n; ++p) {
                if (nrs[st..end] == nrs[p..p+end-st]) {
                    debug { p.writeln; }
                    ++regs;
                    p += end-st - 1;
                }
            }

            if (regs > 1) ans = min(ans, total - gain * regs);
        }
    }

    ans.writeln;
}


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

void solve(){
    auto n = scan!int;
    dchar[][] words;
    for(int i = 0; i < n; ++i){ words ~= scan!(dchar[]); }
    auto rbt = redBlackTree!(dchar[])(words);

    auto after = redBlackTree!(dchar[]);

    auto cback = new dchar[][n];

    bool f = 0;
    for(int i = 0; i < n; ++i){
        if(words[i].front == words[i].back){
            f = 1;
            break;
        }else if(words[i].length >= 2){
            dchar[] rev;
            rev ~= words[i];
            rev.reverse;
            if(rev in rbt || words[i] in after){
                f = 1;
                break;
            }

            if(rev.length == 3){
                after.insert(rev[1..$]);
                cback[i] ~= rev[0..2];
                show("af: ", rev[1..$], "bef: ", rev[0..2]);
            }
        }
    }
    auto before = redBlackTree!(dchar[]);
    for(int i = n-1; i >= 0; --i){
        if(cback[i].length){
            before.insert(cback[i]);
        }else if(words[i] in before){
            f = 1;
            break;
        }
    }
    writeln( (f) ? "YES" : "NO");
}

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

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

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

bool solve (string [] s, int n)
{
	if (s.any !(c => c.front == c.back))
	{
		return true;
	}
	auto t = s.map !(c => c.retro.text).array;
	int [string] first2;
	int [string] last2;
	int [string] first3;
	int [string] last3;
	foreach_reverse (i; 0..n)
	{
		first2[s[i][0..2]] = i;
		first3[s[i]] = i;
	}
	foreach (i; 0..n)
	{
		last2[t[i][0..2]] = i;
		last3[t[i]] = i;
	}
	foreach (c, posC; first3)
	{
		if (c in last3 && posC < last3[c])
		{
			return true;
		}
		if (c.length == 2 && c in last2 && posC < last2[c])
		{
			return true;
		}
	}
	foreach (d, posD; last3)
	{
		if (d in first3 && first3[d] < posD)
		{
			return true;
		}
		if (d.length == 2 && d in first2 && first2[d] < posD)
		{
			return true;
		}
	}
	return false;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto s = new string [n];
		foreach (ref c; s)
		{
			c = readln.strip;
		}
		writeln (solve (s, n) ? "YES" : "NO");
	}
}

import std;

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }

void solve() {
    int N = read!int;
    auto X = new string[N];
    foreach (i; 0 .. N) X[i] = readln.chomp;

    bool f() {
        bool[string] s;
        foreach (i; 0 .. N) {
            auto x = X[i];
            auto r = reverse(x.dup);
            if (x == r) return true;
            if (r in s) return true;
            if (x.length == 2) {
                for (char c = 'a'; c <= 'z'; c++) {
                    auto x1 = [c] ~ x;
                    auto r1 = reverse(x1.dup);
                    if (r1 in s) return true;
                }
            } else if (x.length == 3) {
                auto x1 = x[1 .. $];
                auto r1 = reverse(x1.dup);
                if (r1 in s) return true;
            }
            s[x] = true;
        }
        return false;
    }
    writeln(f() ? "YES" : "NO");
}

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

import std;

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }

void solve() {
    int N = read!int;
    auto X = new string[N];
    foreach (i; 0 .. N) X[i] = readln.chomp;

    bool f() {
        bool[string] s;
        foreach (i; 0 .. N) {
            auto x = X[i];
            if (x.length == 1) return true;
            auto r = reverse(x.dup);
            if (x == r) return true;
            if (r in s) return true;
            if (x.length == 2) {
                for (char c = 'a'; c <= 'z'; c++) {
                    auto r1 = [c] ~ r;
                    if (r1 in s) return true;
                }
            } else if (x.length == 3) {
                auto x1 = x[1 .. $];
                auto r1 = reverse(x1.dup);
                if (r1 in s) return true;
            }
            s[x] = true;
        }
        return false;
    }
    writeln(f() ? "YES" : "NO");
}

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

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

bool solve (string [] s, int n)
{
	if (s.any !(c => c.front == c.back))
	{
		return true;
	}
	auto t = s.map !(c => c.retro.text).array;
	int [string] first;
	int [string] last;
	foreach_reverse (i; 0..n)
	{
		first[s[i][0..2]] = i;
	}
	foreach (i; 0..n)
	{
		last[t[i][0..2]] = i;
	}
	foreach (c, posC; first)
	{
		if (c in last && posC < last[c])
		{
			return true;
		}
	}
	return false;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto s = new string [n];
		foreach (ref c; s)
		{
			c = readln.strip;
		}
		writeln (solve (s, n) ? "YES" : "NO");
	}
}


import std.algorithm, std.array, std.stdio, std.string;
void main () {
	auto s = readln.strip;
	bool [string] ans;
	auto n = s.length;
	auto f = new bool [2] [n + 1];
	f[n] = [true, true];
	foreach_reverse (p; 0..n + 1)
		foreach (k; 0..2) {
			int m = k + 2;
			if (p - m >= 5 && (f[p][!k] || f[p][k] && (p + m > n || s[p..p + m] != s[p - m..p]))) {
				f[p - m][k] = true;
				ans[s[p - m..p]] = true;
			}
		}
	writefln ("%s%-(\n%s%)", ans.length, ans.byKey.array.sort);
}

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.chomp;
    auto N = S.length.to!int;

    auto used = new bool[][](N+1, 4);
    bool[string] ans;

    void dfs(int r, int plen) { // [0..r)
        if (used[r][plen]) return;
        used[r][plen] = true;

        foreach (i; 2..4) {
            if (r - i > 4 && (i != plen || S[r-i..r] != S[r..r+plen])) {
                ans[S[r-i..r]] = true;
                dfs(r-i, i);
            }
        }
    }

    dfs(N, 0);
    auto anss = ans.keys.dup;
    anss.sort();

    ans.keys.length.writeln;
    foreach (a; anss) a.writeln;
}

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

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		string [] ans;
		auto n = s.length;
		auto f = new bool [2] [n + 1];
		f[n][0] = true;
		f[n][1] = true;
		for (int p = n; p >= 5; p--)
		{
			if (p + 2 <= n && (f[p + 2][1] ||
			    f[p + 2][0] && (p + 2 + 2 > n ||
			    s[p + 2..p + 2 + 2] != s[p..p + 2])))
			{
				f[p][0] = true;
				ans ~= s[p..p + 2];
			}
			if (p + 3 <= n && (f[p + 3][0] ||
			    f[p + 3][1] && (p + 3 + 3 > n ||
			    s[p + 3..p + 3 + 3] != s[p..p + 3])))
			{
				f[p][1] = true;
				ans ~= s[p..p + 3];
			}
		}

		sort (ans);
		ans = ans.uniq.array;
		writeln (ans.length);
		foreach (t; ans)
		{
			writeln (t);
		}
	}
}


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

immutable int letters = 26;

void main ()
{
	foreach (test; 0..readln.strip.to !(int))
	{
		auto s = readln.strip;
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		int [letters] num;
		foreach (ref c; s)
		{
			num[c - 'a'] += 1;
		}

		auto answer = new char [n];
		char now = 'z';
		int res = 0;
		while (res < n)
		{
			auto zeroes = a.count (0);
			while (num[now - 'a'] < zeroes)
			{
				now = cast (char) (now - 1);
			}

			foreach (i; 0..n)
			{
				if (a[i] == 0)
				{
					answer[i] = now;
				}
			}
			res += zeroes;

			foreach (i; 0..n)
			{
				if (answer[i] == now)
				{
					foreach (j; 0..n)
					{
						a[j] -= abs (i - j);
					}
				}
			}

			foreach (i; 0..n)
			{
				if (answer[i] == now)
				{
					a[i] = -1;
				}
			}

			now = cast (char) (now - 1);
		}
		writeln (answer);
	}
}

import std.stdio;
import std.string : split, strip;
import std.algorithm : map, group, sort, filter;
import std.conv : to;
import std.utf : toUTF32;
import std.array : array;
import std.range : enumerate, walkLength;
import std.math : abs;

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

  foreach (i; 0..q) {
    int m;
    dchar[] s = readln.strip.toUTF32.dup;
    readf!"%d\n"(m);
    auto t = readln.strip.split.map!(to!int).array;
    auto r = new dchar[m]; // result
    auto f = 0; // filled chars

    // letters available in s
    s.sort!"a > b";
    auto g = s.group;

    // fill zeros in t with largest available letter
    while (f < m) {
      // indices of zeros
      auto c = t.enumerate.filter!"a.value == 0".array;
      while (g.front[1] < c.length) {
        g.popFront;
      }

      foreach (e; c) {
        // fill zeros from largest valid letter
        r[e.index] = g.front[0];

        // update distance for all other letters
        foreach (j; 0..m) {
          if (t[j] > 0) {
            t[j] -= abs(cast(int) j - cast(int) e.index);
          }
        }

        t[e.index] = -1;
      }

      f += c.length;
      g.popFront; // letter is now invalid
    }

    writeln(r);
  }
}


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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto n = readln.split.to!(int[]);
        writeln(n[1], " ", n[2], " ", n[2]);
    }
}

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

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

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  foreach (tid; 0 .. nt) {
    auto a = r.nextA!uint (4);
    writeln (a[1], ' ', a[2], ' ', a[2]);
  }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new long[][](t);
	foreach (ti; 0..t)
	{
		auto abcd = RDA;
		ans[ti] = [abcd[1], abcd[2], abcd[2]];
	}

	foreach (e; ans)
		writeln(e[0], " ", e[1], " ", e[2]);
	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(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto t = RD!int;
	auto ans = new long[][](t);
	foreach (ti; 0..t)
	{
		auto abcd = RDA;
		ans[ti] = [abcd[2], abcd[2], abcd[1]];
	}

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


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

void main()
{
    auto nm = readln.split.map!(to!int);
    auto n = nm[0], m = nm[1];
    auto lines  = n.iota.map!(_ => readln.chomp).array;
    lines = lines.strip!(a => a == repeat(".").take(lines[0].length).array.join(""));
    auto lines1 = lines[0].length.iota.array.map!(i => lines.transversal(i).array);
    auto lines2 = lines1.strip!(a => a == repeat(".").take(lines1[0].length).array.join(""));
    lines2[0].length.iota.array.map!(i => lines2.transversal(i).array).each!writeln;
}

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

class Line
{
    public const ptrdiff_t firstStar;
    public const ptrdiff_t lastStar;
    public const string line;

    this(in string line)
    {
        this.firstStar = std.string.indexOf(line, '*');
        this.lastStar = std.string.lastIndexOf(line, '*');
        this.line = line;
    }

    invariant()
    {
        assert(firstStar <= lastStar, format("Last star cannot be before the first one: %s, %s", firstStar, lastStar));
        assert(firstStar >= 0 || (firstStar == -1 && lastStar == -1), "Both indexes must be -1 or >= 0");
    }
}

void testDotsCount(in string line, in ptrdiff_t firstStar, in ptrdiff_t lastStar)
{
    Line l;
    l = new Line(line);
    assert(l.firstStar == firstStar, format("Bad first star index: expected %s, got %s", firstStar, l.firstStar));
    assert(l.lastStar == lastStar, format("Bad last star index: expected %s, got %s", lastStar, l.lastStar));
}

unittest
{
    testDotsCount("..*...", 2, 2);
}

unittest
{
    testDotsCount("*...", 0, 0);
}

unittest
{
    testDotsCount("*", 0, 0);
}

unittest
{
    testDotsCount("***", 0, 2);
}

unittest
{
    testDotsCount("..***...*.*..", 2, 10);
}

void main()
{
    string firstLine = stdin.readln();
    int rows;
    int cols;
    formattedRead(firstLine, "%s %s", &rows, &cols);

    ptrdiff_t minFirstStar = -1;
    ptrdiff_t maxLastStar = -1;

    Line[50] lines;

    int firstLineWithStar = rows;
    int lastLineWithStar = 0;

    for (int i = 0; i < rows; i++) {
        Line l = new Line(stdin.readln());
        lines[i] = l;
        maxLastStar = max(maxLastStar, l.lastStar);
        if (l.firstStar != -1) {
            lastLineWithStar = i;
            firstLineWithStar = min(firstLineWithStar, i);
            if (minFirstStar == -1) {
                minFirstStar = l.firstStar;
            } else {
                minFirstStar = min(minFirstStar, l.firstStar);
            }
        }
    }
    for (int i = firstLineWithStar; i <= lastLineWithStar; i++)
    {
        stdout.writeln(lines[i].line[minFirstStar .. maxLastStar + 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 = 998244353;
//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 main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto a = RD;
		auto b = RD;
		auto c = RD;
		auto n = RD;
		if ((a+b+c+n) % 3 != 0)
			continue;

		auto m = max(a, b, c);
		auto d = m * 3 - a - b - c;
		ans[ti] = d <= n;
	}

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

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

DList!string _words;

void read(T...)(ref T t)
{
  void singleRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  static foreach(i; 0 .. T.length)
    {
      static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))
        {
          foreach(ref element; t[i])
            read(element);
        }
      else
        {
          singleRead(t[i]);
        }
    }
}

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

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

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

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

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

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

    }
}

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

void main()
{
  int t;
  read(t);
 testCase:foreach(tc; 0 .. t)
    {
      long[3] a;
      read(a);
      long n = next!long;
      sort(a[]);
      if (a[2] - a[1] + a[2] - a[0] <= n)
        {
          n -= 2 * a[2] - a[1] - a[0];
          if (n % 3 == 0)
            {
              writeln("YES");
              continue testCase;
            }
        }
      writeln("NO");
    }
}

import std.stdio;
int main()
{
	int t=0;
	readf(" %d", &t);
	for (int i=0; i<t; i++)
	{
		int a=0;
		int b=0;
		int c=0;
		int d=0;
		readf(" %d", &a);
		readf(" %d", &b);
		readf(" %d", &c);
		readf(" %d", &d);
		if ((a+b+c+d)%3==0)
		{
			int r=(a+b+c+d)/3;
			if (r-a>=0 && r-b>=0 && r-c>=0)
			{
				writeln("YES");
			}
			else
			{
				writeln("NO");
			}
		}
		else
		{
			writeln("NO");
		}
	}
	return 0;
}

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

void main ()
{
	int tests;
	readf !(" %s") (tests);
	foreach (test; 0..tests)
	{
		int a, b, c, n;
		readf !(" %s %s %s %s") (a, b, c, n);
		auto s = a + b + c + n;
		bool ok = (s % 3 == 0);
		s /= 3;
		ok &= (s >= a) && (s >= b) && (s >= c);
		writeln (ok ? "YES" : "NO");
	}
}

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

string[] tokens;

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

int readInt()
{
    return readToken.to!int;
}

bool solve()
{
    int a = readInt;
    int b = readInt;
    int c = readInt;
    int n = readInt;
    int sum = a + b + c + n;
    if (sum % 3)
    {
        return false;
    }
    sum /= 3;
    return a <= sum && b <= sum && c <= sum;
}

void main()
{
    int T = readInt;
    while (T--)
    {
        writeln(solve ? "YES" : "NO");
    }
}


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

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

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  foreach (tid; 0 .. nt) {
    auto n = r.next!uint;
    writeln (n);
  }
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto N = readln.chomp.to!long;
        writeln(N);
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

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

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto N = readln.chomp.to!long;
        if (N == 1) {
            writeln(1);
        } else {
            writeln(2);
        }
    }
}

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

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

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  foreach (tid; 0 .. nt) {
    auto n = r.next!uint;
    writeln (n > 1 ? 2 : 1);
  }
}


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

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

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

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

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

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

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

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

void main()
{
    int T; get(T);
    while (T--) {
        int N; long X; get(N, X);
        long[] AA; get(AA);
        long s, b;
        foreach (a; AA) {
            s += a;
            b += (a + X - 1) / X;
        }
        writeln((s + X - 1) / X, " ", 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); }

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

		auto tot = a.sum;
		ans[ti][0] = (tot+x-1) / x;
		foreach (i; 0..n)
		{
			ans[ti][1] += (a[i]+x-1) / x;
		}
	}

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

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

void theCode(){
    int n;
    n = scan!int;
    ll x = scan;
    auto arr = scanArray;
    ll maxx = 0, rem = 0;
    foreach(a; arr){
        maxx += (a/x) + (a % x != 0);
        ll r = a % x;
        if(r == 0) r = x;
        rem += x - r;
    }
    writeln(maxx - rem/x, " ", maxx);
}

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

void main()
{
	int n;

	while(input(&n))
	{
		if(n==1) writeln(-1);
		else writeln(n,' ',n+1,' ',n*(n+1));
	}
}

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

__gshared:

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

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

void main() {
    int n;
    while (read(&n)) {
        if (n == 1)
            writeln("-1");//Thanks to Alexit.
        else
            foreach (y; n + 1L .. 1_000_000_001L) {
                //I just believe it works.
                long num = n * y;
                long denom = y - n;
                if (!(num % denom) && num / denom <= 1_000_000_000) {
                    writeln(n, ' ', num / denom, ' ', y);
                    break;
                }
            }
    }
}

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

__gshared:

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

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

void main() {
    int n;
    while (read(&n))
        foreach (y; n + 1L .. 1_000_000_001L) {
            //I just believe it works.
            long num = n * y;
            long denom = y - n;
            if (!(num % denom) && num / denom <= 1_000_000_000) {
                writeln(n, ' ', num / denom, ' ', y);
                break;
            }
        }
}

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

__gshared:

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

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

void main() {
    int n;
    while (read(&n))
        foreach (y; n + 1L .. 1_000_000_001L) {
            //I just believe it works.
            long num = n * y;
            long denom = y - n;
            if (!(num % denom)) {
                writeln(n, ' ', num / denom, ' ', y);
                break;
            }
        }
}


// stay simple, stay naive

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

void main() {

  int n; readf!"%d"(n);
  int[] a = new int[n + 2];
  int[] cnt = new int[n + 2];
  foreach(i; 1 .. n + 1) {
    readf!" %d"(a[i]);
    cnt[a[i]]++;
  }
  int mx = 1;
  foreach(i; 2 .. n + 1) {
    if (cnt[i] > cnt[mx]) mx = i;
  }

  immutable int B = cast(int)(std.math.sqrt(cast(real)(n)));
  debug { writefln!"B = %s"(B); }
  int ans = 0;

  int[] c = new int[n + 1];
  foreach(i; 1 .. B) {
    int l = 1, tot = 0, num = i;
    void upd(int x, int d) {
      tot -= (c[x] == num);
      c[x] += d;
      tot += (c[x] == num);
    }
    foreach(r; 1 .. n + 1) {
      upd(a[r], 1);
      while (l <= r && c[a[r]] > num) {
        upd(a[l++], -1);
      }
      if (tot > 1) {
        ans = max(ans, r - l + 1);
      }
    }
    while (l <= n) {
      upd(a[l++], -1);
    }
  }
  debug { "Fuck!".writeln; }

  int[] lastPos = new int[n + 2];
  foreach(i; 1 .. n + 1) {
    if (i != mx && cnt[i] >= B) {
      foreach(j; 0 .. n + 1) {
        lastPos[j] = -1;
      }
      int t = cnt[mx];
      lastPos[t] = 0;
      foreach(j; 1 .. n + 1) {
        t += (a[j] == i) - (a[j] == mx);
        if (lastPos[t] == -1) lastPos[t] = j;
        else ans = max(ans, j - lastPos[t]);
      }
    }
  }

  ans.writeln;

}

// stay simple, stay naive

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

void main() {

  int n; readf!"%d"(n);
  int[] a = new int[n + 2];
  int[] cnt = new int[n + 2];
  foreach(i; 1 .. n + 1) {
    readf!" %d"(a[i]);
    cnt[a[i]]++;
  }
  int mx = 1;
  foreach(i; 2 .. n + 1) {
    if (cnt[i] > cnt[mx]) mx = i;
  }

  immutable int B = 314;
  int ans = 0;

  int[] c = new int[n + 1];
  foreach(i; 1 .. B) {
    int l = 1, tot = 0;
    void upd(int x, int d) {
      tot -= (c[x] == i);
      c[x] += d;
      tot += (c[x] == i);
    }
    foreach(r; 1 .. n + 1) {
      upd(a[r], 1);
      while (l <= r && c[a[r]] > i) {
        upd(a[l++], -1);
      }
      if (tot > 1) {
        ans = max(ans, r - l + 1);
      }
    }
    while (l <= n) {
      upd(a[l++], -1);
    }
  }
  debug { "Fuck!".writeln; }

  int[] lastPos = new int[n + 2];
  foreach(i; 1 .. n + 1) {
    if (i != mx && cnt[i] >= B) {
      foreach(j; 0 .. n + 1) {
        lastPos[j] = -1;
      }
      int t = cnt[mx];
      lastPos[t] = 0;
      foreach(j; 1 .. n + 1) {
        t += (a[j] == i) - (a[j] == mx);
        if (lastPos[t] == -1) lastPos[t] = j;
        else ans = max(ans, j - lastPos[t]);
      }
    }
  }

  ans.writeln;

}


// Vicfred
// https://codeforces.com/contest/1520/problem/C
// greedy
import std.stdio;

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

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

    if(n == 2) {
        "-1".writeln;
        continue;
    }

    int[][] matrix = new int[][](n,n);
    int i = 1;
    bool flag = false;
    for(int y = 0; y < n; ++y) {
        for(int x = 0; x < n; ++x) {
            if(!flag && i*2 > n*n) {
                flag = true;
                i = 1;
            }
            if(flag) {
                matrix[y][x] = i*2-1;
                i += 1;
            }
            else {
                matrix[y][x] = i*2;
                i+=1;
            }
        }
    }
    for(int k = 0; k < n; k++) {
        for(int j = 0; j < n; j++) {
            writef("%s ", matrix[k][j]);
        } "".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 int[][][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;

		if (n == 2) continue;

		ans[ti] = new int[][](n, n);
		int num = 1;
		foreach (i; 0..n)
		{
			ans[ti][i][i] = num;
			++num;
		}
		foreach (i; 1..n)
		{
			foreach (j; 0..n-i)
			{
				ans[ti][i+j][j] = num;
				++num;
			}
			foreach (j; 0..n-i)
			{
				ans[ti][j][i+j] = num;
				++num;
			}
		}
	}

	foreach (e; ans)
	{
		if (e.empty)
			writeln(-1);
		else
		{
			foreach (ee; e)
				ee.map!(to!string).join(" ").writeln;
		}
	}
	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 n = RD!int;
		auto a = RDA;

		auto cnt = new long[](n+1);
		foreach (i; 0..n)
			cnt[i+1] = cnt[i] + (a[i] == 0 ? 1 : 0);
		foreach (l; 0..n)
		{
			foreach (r; l+1..n+1)
			{
				ans[ti] += r-l + cnt[r]-cnt[l];
			}
		}
	}

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

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;

		auto x = new int [] [] (n + 1, n + 1);
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n + 1)
			{
				bool [int] s;
				foreach (k; i..j)
				{
					s[a[k]] = true;
				}
				x[i][j] = 0;
				while (x[i][j] in s)
				{
					x[i][j] += 1;
				}
				x[i][j] += 1;
			}
		}

		auto f = new int [] [] (n + 1, n + 1);
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n + 1)
			{
				f[i][j] = x[i][j];
				foreach (k; i..j)
				{
					f[i][j] = max (f[i][j],
					    f[i][k] + x[k][j]);
				}
			}
		}

		int res = 0;
		foreach (i; 0..n)
		{
			foreach (j; i + 1..n + 1)
			{
				res += f[i][j];
			}
		}
		writeln (res);
	}
}

// cheese-cracker [2022-02-12]

void solve(){
    int n = scan!int;
    auto arr = scanArray;
    long summ = 0;
    for(int i = 1; i <= n; ++i){
        summ += i * (n + 1 - i);
    }
    for(int i = 1; i <= n; ++i){
        if(arr[i-1] == 0){
            summ += i * (n + 1 - i);
        }
    }
    writeln(summ);
}

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

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];
        foreach (i; 0 .. N) {
          A[i] = readInt;
        }

        auto mex = new int[][](N + 1, N + 1);
        foreach (i; 0 .. N) {
          bool[int] app;
          foreach (j; i .. N) {
            app[A[j]] = true;
            for (int x = 0; ; ++x) {
              if (x !in app) {
                mex[i][j + 1] = x;
                break;
              }
            }
          }
        }

        auto dp = new int[][](N + 1, N + 1);
        foreach_reverse (i; 0 .. N) foreach (j; i + 1 .. N + 1) {
          dp[i][j] = 1 + mex[i][j];
          foreach (k; i + 1 .. j) {
            chmax(dp[i][j], dp[i][k] + dp[k][j]);
          }
        }
        int ans;
        foreach_reverse (i; 0 .. N) foreach (j; i + 1 .. N + 1) {
          ans += dp[i][j];
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}


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 n = readln().chomp.to!int;
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;
        auto sorted = arr.array.sort;

        if(arr.equal(sorted))
            writeln(0);
        else if(arr[0] == 1 || arr[arr.length-1] == arr.length)
            writeln(1);
        else if(arr[0] != arr.length || arr[arr.length-1] != 1)
            writeln(2);
        else
            writeln(3);
    }
}

// Vicfred
// https://codeforces.com/contest/1525/problem/B
// greedy
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

while(t--) {
    int n;
    readf("%d\n", &n);
    int[] a = readln.split.map!(to!int).array;
    bool is_sorted = true;
    for(int i = 1; i < n; ++i) {
        if(a[i] < a[i - 1]) {
            is_sorted = false;
            break;
        }
    }
    if(is_sorted) {
        "0".writeln;
        continue;
    }
    if(a[0] == 1 || a[$-1] == n) {
        "1".writeln;
        continue;
    }
    if(a[0] == n && a[$-1] == 1) {
        "3".writeln;
        continue;
    }
    "2".writeln;
}
}

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 n = readln().chomp.to!int;
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;
        auto sorted = arr.array.sort;

        if(arr.equal(sorted))
            writeln(0);
        else if(arr[0] == 1 || arr[arr.length-1] == arr.length)
            writeln(1);
        else if(arr[0] != arr.length || arr[arr.length-1] == 1)
            writeln(2);
        else
            writeln(3);
    }
}

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 n = readln().chomp.to!int;
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;
        auto sorted = arr.array.sort.array;

        int res = 0;
        int o = 0;
        int e = 0;

        if(arr == sorted)
            writeln(0);
        else if(arr[0] == 1 || arr[$] == arr.length)
            writeln(1);
        else if(arr[0] != arr.length || arr[$] == 1)
            writeln(2);
        else
            writeln(3);
    }
}

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 n = readln().chomp.to!int;
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;

        int res = 0;
        int o = 0;
        int e = 0;
        while(e < arr.length)
        {
            if(arr[e] != e+1)
            {
                res++;
                while(e < arr.length && arr[e] != e+1)
                    e++;
                e--;
            }
            else
            {
                o++;
            }
            e++;
        }

        if(o == 0)
            writeln(res+1);
        else
            writeln(res);
    }
}

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 n = readln().chomp.to!int;
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;

        int res = 0;
        int o = 0;
        int e = 0;
        while(e < arr.length)
        {
            if(arr[e] != e+1)
            {
                res++;
                while(e < arr.length && arr[e] != e+1)
                    e++;
                e--;
            }
            else
            {
                o++;
            }
            e++;
        }

        if(o == 0)
            writeln(2);
        else
            writeln(res);
    }
}

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 n = readln().chomp.to!int;
        auto arr = readln().chomp.splitter(" ").map!(to!int).array;

        int res = 0;
        int o = 0;
        int e = 0;
        while(e < arr.length)
        {
            if(arr[e] != e+1)
            {
                res++;
                while(e < arr.length && arr[e] != e+1)
                    e++;
            }
            else
            {
                o++;
            }
            e++;
        }

        if(o == 0)
            writeln(2);
        else
            writeln(res);
    }
}

// Vicfred
// https://codeforces.com/contest/1525/problem/B
// greedy
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

while(t--) {
    int n;
    readf("%d\n", &n);
    int[] a = readln.split.map!(to!int).array;
    bool is_sorted = true;
    for(int i = 1; i < n; ++i) {
        if(a[i] < a[i - 1]) {
            is_sorted = false;
            break;
        }
    }
    if(is_sorted) {
        "0".writeln;
        continue;
    }
    if(a[0] == 1 || a[$-1] == 1) {
        "1".writeln;
        continue;
    }
    if(a[0] == n && a[$-1] == 1) {
        "3".writeln;
        continue;
    }
    "2".writeln;
}
}

// Vicfred
// https://codeforces.com/contest/1525/problem/B
// greedy
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

while(t--) {
    int n;
    readf("%d\n", &n);
    int[] a = readln.split.map!(to!int).array;
    bool is_sorted = true;
    for(int i = 1; i < n; ++i) {
        if(a[i] < a[i - 1]) {
            is_sorted = false;
            break;
        }
    }
    if(is_sorted) {
        "0".writeln;
        continue;
    }
    if(a[0] == 1) {
        "1".writeln;
        continue;
    }
    if(a[0] == n && a[$-1] == 1) {
        "3".writeln;
        continue;
    }
    "2".writeln;
}
}


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

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

void main() {
  auto r = new InputReader;
  immutable int n = r.next!uint;
  immutable int m = r.next!uint;
  auto a = uninitializedArray!(uint[][]) (n, m);
  auto b = uninitializedArray!(uint[][]) (n, m);
  foreach (i; 0 .. n) foreach (j; 0 .. m) a[i][j] = r.next!uint;
  foreach (i; 0 .. n) foreach (j; 0 .. m) b[i][j] = r.next!uint;
  bool test () {
    foreach (d; 0 .. n + m - 1) {
      uint[] X, Y;
      foreach (i; 0 .. n) {
        immutable j = d - i;
        if (j >= 0 && j < m) {
          X ~= a[i][j];
          Y ~= b[i][j];
        }
      }
      X.sort ();
      Y.sort ();
      debug stderr.writeln ("d = ", d);
      debug stderr.writeln ("X = ", X);
      debug stderr.writeln ("Y = ", Y);
      if (!equal (X, Y)) return false;
    }
    return true;
  }
  write (test () ? "YES" : "NO");
}

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

alias Tree = RBT!int;

void main() {

    int n, m;

    readf(" %s %s", n, m);
    auto a = new int[][n];
    auto diga = new int[][m+n];
    foreach(i; 0.. n) {
      a[i] = new int[m];

      foreach(j; 0..m) {
        readf(" %s", a[i][j]);
        diga[i+j]  ~= a[i][j];
      }
    }

    auto b = new int[][n];
    auto digb = new int[][m+n];
    foreach(i; 0.. n) {
      b[i] = new int[m];

      foreach(j; 0..m) {
        readf(" %s", b[i][j]);
        digb[i+j]  ~= b[i][j];
      }
    }

    foreach(i;0..m+n) {
      sort(diga[i]);
      sort(digb[i]);
      //foreach
      //bool eq = zip(diga[i], digb[i]).array.all!(a=>a[0]==a[1]);
      foreach(j;0..diga[i].length) {
        if (diga[i][j] != digb[i][j]) { writeln("NO"); return; }
      }
    }

    // writeln(a);
    // writeln(b);

    writeln("YES");

}

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

alias Tree = RBT!int;

void main() {

    int n, m;

    readf(" %s %s", n, m);
    auto a = new int[][n];
    auto diga = new int[][2*n];
    foreach(i; 0.. n) {
      a[i] = new int[m];

      foreach(j; 0..m) {
        readf(" %s", a[i][j]);
        diga[i+j]  ~= a[i][j];
      }
    }

    auto b = new int[][n];
    auto digb = new int[][2*n];
    foreach(i; 0.. n) {
      b[i] = new int[m];

      foreach(j; 0..m) {
        readf(" %s", b[i][j]);
        digb[i+j]  ~= b[i][j];
      }
    }

    foreach(i;0..2*n) {
      sort(diga[i]);
      sort(digb[i]);
      //foreach
      //bool eq = zip(diga[i], digb[i]).array.all!(a=>a[0]==a[1]);
      foreach(j;0..diga[i].length) {
        if (diga[i][j] != digb[i][j]) { writeln("NO"); return; }
      }
    }

    // writeln(a);
    // writeln(b);

    writeln("YES");

}


import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

const INF = 1<<28;

string s;

bool isVowel(char c) {
    return "aiueoAIUEO".count(c) > 0;
}

void main() {
    s = readln.chomp;
    int N = cast(int)s.length;
    auto xs = new int[N];
    foreach (i, c; s) {
        xs[i] = c.isVowel ? -1 : 2;
    }
    auto sum = new int[N + 1]; sum[0] = 0;
    foreach (int i; 0 .. N) {
        sum[i + 1] = sum[i] + xs[i];
    }
    struct P {
        int index, value;
    }

    auto ys = new P[N + 1];
    foreach (int i; 0 .. N + 1) {
        ys[i] = P(i, sum[i]);
    }
    ys.sort!"a.value == b.value ? a.index < b.index : a.value < b.value";
    auto t = new RedBlackTree!int(iota(0, N + 1, 1).array);
    int ans = 0;
    foreach (y; ys) {
        auto end = t.back;
        ans = max(ans, end - y.index);
        t.removeKey(y.index);
    }

    if (ans == 0) {
        writeln("No solution");
        return;
    }

    int count = 0;
    foreach (int i; 0 .. N + 1) {
        if (i + ans > N) break;
        if (sum[i + ans] - sum[i] >= 0) {
            count++;
        }
    }
    writeln(ans, " ", count);
}

import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

string s;

bool isVowel(dchar c) {
    return "aiueo".count(std.ascii.toLower(c)) > 0;
}

void main() {
    s = readln.chomp.dup;
    int N = cast(int)s.length;

    auto sum = new int[N + 1];
    sum[0] = 0;
    foreach (int i, c; s) {
        sum[i + 1] = sum[i] + (!c.isVowel);
    }
    //writeln(sum);

    bool check(int c) {
        int minLen = int.max / 2;
        for (int i = 0; i < N; i++) {
            int lb = i, ub = N; // (lb, ub]
            if (sum[N] - sum[i] < c) break;
            while (lb + 1 < ub) {
                int mid = (lb + ub) / 2;
                //writeln("c", [lb, ub]);
                (sum[mid] - sum[i] >= c ? ub : lb) = mid;
            }
            minLen = min(minLen, ub - i);
        }
        //writeln([c, minLen]);
        return 3 * c >= minLen;
    }

    int lb = 0, ub = sum[N] + 1;
    while (lb + 1 < ub) {
        //writeln([lb, ub]);
        int mid = (lb + ub) / 2;
        (check(mid) ? lb : ub) = mid;
    }
    int ans = min(N, lb * 3);

    if (ans == 0) {
        writeln("No solution");
        return;
    }

first:
    int count = 0;
    for (int i = 0; i < N; i++) {
        if (i + ans > N) break;
        if ( 3 * (sum[i + ans] - sum[i]) >= ans ) {
            if ( ans != min(ans * 2, N - i) && 3 * (sum[min(i + ans * 2, N)] - sum[i]) >= min(ans * 2, N - i) ) {
                ans = min(ans * 2, N - i);
                goto first;
            }
            count++;
        }
    }
    writeln(ans, " ", count);
}

import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

string s;

bool isVowel(dchar c) {
    return "aiueo".count(std.ascii.toLower(c)) > 0;
}

void main() {
    s = readln.chomp.dup;
    int N = cast(int)s.length;

    auto sum = new int[N + 1];
    sum[0] = 0;
    foreach (int i, c; s) {
        sum[i + 1] = sum[i] + (!c.isVowel);
    }
    //writeln(sum);

    bool check(int l) {
        for (int i = 0; i < N; i++) {
            if (i + l > N) break;
            if ( 3 * (sum[i + l] - sum[i]) >= l ) return true;
        }
        return false;
    }

    int lb = 0, ub = N + 1;
    while (lb + 1 < ub) {
        int mid = (lb + ub) / 2;
        (check(mid) ? lb : ub) = mid;
    }
    int ans = lb;

    if (ans == 0) {
        writeln("No solution");
        return;
    }

    int count = 0;
    for (int i = 0; i < N; i++) {
        if (i + ans > N) break;
        if ( 3 * (sum[i + ans] - sum[i]) >= ans ) {
            count++;
        }
    }
    writeln(ans, " ", count);
}

import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

string s;

bool isVowel(dchar c) {
    return "aiueo".count(std.ascii.toLower(c)) > 0;
}

void main() {
    s = readln.chomp.dup;
    int N = cast(int)s.length;

    auto sum = new int[N + 1];
    sum[0] = 0;
    foreach (int i, c; s) {
        sum[i + 1] = sum[i] + (!c.isVowel);
    }
    //writeln(sum);

    bool check(int c) {
        int minLen = N;
        for (int i = 0; i < N; i++) {
            int lb = i, ub = N; // (lb, ub]
            if (sum[N] - sum[i] < c) break;
            while (lb + 1 < ub) {
                int mid = (lb + ub) / 2;
                (sum[mid] - sum[i] >= c ? lb : ub) = mid;
            }
            minLen = min(minLen, ub);
        }
        return 3 * c >= minLen;
    }

    int lb = 0, ub = sum[N] + 1;
    while (lb + 1 < ub) {
        //writeln([lb, ub]);
        int mid = (lb + ub) / 2;
        (check(mid) ? lb : ub) = mid;
    }
    int ans = min(N, lb * 3);

    if (ans == 0) {
        writeln("No solution");
        return;
    }

    int count = 0;
    for (int i = 0; i < N; i++) {
        if (i + ans > N) break;
        if ( 3 * (sum[i + ans] - sum[i]) >= ans ) {
            count++;
        }
    }
    writeln(ans, " ", count);
}

import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

string s;

bool isVowel(dchar c) {
    return "aiueo".count(std.ascii.toLower(c)) > 0;
}

void main() {
    s = readln.chomp.dup;
    int N = cast(int)s.length;

    auto sum = new int[N + 1];
    sum[0] = 0;
    foreach (int i, c; s) {
        sum[i + 1] = sum[i] + (!c.isVowel);
    }
    //writeln(sum);

    bool check(int c) {
        int minLen = int.max / 2;
        for (int i = 0; i < N; i++) {
            int lb = i, ub = N; // (lb, ub]
            if (sum[N] - sum[i] < c) break;
            while (lb + 1 < ub) {
                int mid = (lb + ub) / 2;
                //writeln("c", [lb, ub]);
                (sum[mid] - sum[i] >= c ? ub : lb) = mid;
            }
            minLen = min(minLen, ub - i);
        }
        //writeln([c, minLen]);
        return 3 * c >= minLen;
    }

    int lb = 0, ub = sum[N] + 1;
    while (lb + 1 < ub) {
        //writeln([lb, ub]);
        int mid = (lb + ub) / 2;
        (check(mid) ? lb : ub) = mid;
    }
    int ans = min(N, lb * 3);

    if (ans == 0) {
        writeln("No solution");
        return;
    }

    int count = 0;
    for (int i = 0; i < N; i++) {
        if (i + ans > N) break;
        if ( 3 * (sum[i + ans] - sum[i]) >= ans ) {
            count++;
        }
    }
    writeln(ans, " ", count);
}

import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

const INF = 1<<28;

string s;

bool isVowel(char c) {
    return "aiueoAIUEO".count(c) > 0;
}

void main() {
    s = readln.chomp;
    int N = cast(int)s.length;
    auto xs = new int[N];
    foreach (i, c; s) {
        xs[i] = c.isVowel ? -1 : 2;
    }
    auto sum = new int[N + 1]; sum[0] = 0;
    foreach (int i; 0 .. N) {
        sum[i + 1] = sum[i] + xs[i];
    }
    struct P {
        int index, value;
    }

    auto ys = new P[N + 1];
    foreach (int i; 0 .. N + 1) {
        ys[i] = P(i, sum[i]);
    }
    ys.sort!"a.value == b.value ? a.index < b.index : a.value < b.value";
    auto t = new RedBlackTree!int(iota(0, N + 1, 1).array);
    int ans = 0;
    foreach (y; ys) {
        auto end = t.back;
        ans = max(ans, end - y.index);
        t.removeKey(y.index);
    }

    if (ans == 0) {
        writeln("No solution");
    }

    int count = 0;
    foreach (int i; 0 .. N + 1) {
        if (i + ans > N) break;
        if (sum[i + ans] - sum[i] >= 0) {
            count++;
        }
    }
    writeln(ans, " ", count);
}


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

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

  while (t--) {
    int n;
    readf!" %d "(n);
    auto a = readln.strip.split.map!(to!long).array.sort.array;
    long mindiff = a[1] - a[0];
    size_t minidx = 0;
    foreach (i ; 1 .. n - 1) {
      if (a[i + 1] - a[i] < mindiff) {
        mindiff = a[i + 1] - a[i];
        minidx = i;
      }
    }
//    writeln(mindiff);
//    writeln(minidx);
//    writeln(a);
    if (a.length <= 2) {
      writeln(a.map!text.joiner(" "));
    } else {
      auto b = a[minidx + 1 .. $] ~ a[0 .. minidx + 1];
      writeln(b.map!text.joiner(" "));
    }
  }
}

// Vicfred
// https://codeforces.com/contest/1537/problem/C
//
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--) {
    int n = readln.chomp.to!int;
    long[] h = readln.split.map!(to!long).array;

    h.sort;

    if(n == 2) {
        writefln("%s %s", h[0], h[1]);
        continue;
    }

    int idx = 0;
    long minima = long.max;

    for(int i = 0; i < n - 1; ++i) {
        if(h[i + 1] - h[i] < minima) {
            minima = h[i + 1] - h[i];
            idx = i + 1;
        }
    }
    for(int i = idx; i < n; ++i) {
        writef("%s ", h[i]);
    }
    for(int i = 0; i < idx; ++i) {
        writef("%s ", h[i]);
    }
    "".writeln;
}
}

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

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

  while (t--) {
    int n;
    readf!" %d "(n);
    auto a = readln.strip.split.map!(to!long).array.sort.array;
    long mindiff = a[1] - a[0];
    size_t minidx = 0;
    foreach (i ; 1 .. n - 1) {
      if (a[i + 1] - a[i] < mindiff) {
        mindiff = a[i + 1] - a[i];
        minidx = i;
      }
    }
    auto b = a[minidx .. $] ~ a[0 .. minidx];
    writeln(b.map!text.joiner(" "));
  }
}