module cf_78A;

import std.stdio;

bool isVowel(char letter) {
    return letter == 'a' || letter == 'e' || letter == 'i' ||
           letter == 'o' || letter == 'u';
}

void main() {
    immutable MAX_ROWS = 3;
    immutable ROW_SYLLABLES = [ 5, 7, 5 ];

    string row;

    bool haiku = true;
    for (int i = 0; i < MAX_ROWS; ++i) {
        readf("%s\n", &row);

        int syllables = 0;
        for (int j = 0; j < row.length; ++j) {
            if (isVowel(row[j])) {
                ++syllables;
            }
        }
        if (syllables != ROW_SYLLABLES[i]) {
            haiku = false;
        }
    }

    writeln(haiku? "YES": "NO");
}

module main;
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,
	std.stdio,std.bitmanip;
import core.stdc.stdio : freopen;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias boyerMooreFinder strfind;
alias make_pair mp;
alias binary_search bins;
alias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
immutable int mod=10^^9+7;
immutable long hashmod=10L^^18+3;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	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;
	}
	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;
	}
	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;
	}
	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;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n,in size_t m) if(isRandomAccessRange!X)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n) if(hasSlicing!X)
{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;}
bool read(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------
void main()
{
	/*int n;
	loop:while(read(&n))
	{

	}*/
	auto a=new int[3];
	foreach(i;0..3)
	{
		auto s=readln.strip;
		a[i]=count!q{a=='a' || a=='o' || a=='e' || a=='u' || a=='i'}(s);
	}
	if(a==[5,7,5])writeln("YES");
	else writeln("NO");
}


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

void solve() {
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    int pos = -1;
    foreach (i; 0..N) if (S[i] == '8') {
        pos = i;
        break;
    }
    if (pos == -1 || N - pos < 11) {
        writeln("NO");
    } else {
        writeln("YES");
    }
}

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

import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	long t = read.to!long;
	foreach(q; 0 .. t){

		long n = read.to!long;
		string s = readln.chomp;

		bool f = 0;
		for(int i = 0; i < n - 10; i ++) if(s[i] == '8') f = 1;

		if(f) "YES".writeln;
		else "NO".writeln;

	}

}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto T = RD!int;
	string[] ans;
	foreach (i; 0..T)
	{
		auto N = RD!int;
		auto s = RD!string;
		bool a;
		foreach (j; 0..N)
		{
			if (j > N - 11) break;

			if (s[j] == '8')
			{
				a = true;
				break;
			}
		}
		ans ~= a ? "YES" : "NO";
	}

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

module cf1167a;
import std.stdio;
import std.string : indexOf, strip;
import std.conv : to;
void main() {
	int n;
	char[] buf;
	readln(buf);
	n = buf.strip.to!int;
	debug writeln(n);
	foreach(i; 0..n) {
		int x;
		readln(buf);
		x = buf.strip.to!int;
		readln(buf);
		immutable eight = buf.indexOf('8');
		debug writeln(eight, " ", x);
		if (eight >= 0 && eight + 11 <= x) {
			writeln("YES");
		}else {
			writeln("NO");
		}
	}
}

//ahmat
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.string;
import std.algorithm;
import std.functional;
import std.array;
import std.container;
import std.conv;
import std.container;
import std.typecons;
import std.math;
import std.numeric;
pragma(inline,true);

void main(){
    int n,t;
    t=readln.chomp.to!int;
    string s;
    while(t--){
        n=readln.chomp.to!int;
        s=readln.strip;
        long k=s.indexOf('8');
        if(k>=0 && n-k>=11)
            writeln("YES");
        else writeln("NO");
    }
}

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

void main() {
  int nt = readln.strip.to!int;
  foreach (tid; 0 .. nt) {
    int n = readln.strip.to!int;
    auto s = readln.take (n).array;
    auto res = "NO";
    foreach (i; 0 .. n) {
      if (s[i] == '8' && (n - 1) - i >= 10) {
        res = "YES";
        break;
      }
    }
    writeln (res);
  }
}

//ahmat
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.string;
import std.algorithm;
import std.functional;
import std.array;
import std.container;
import std.conv;
import std.container;
import std.typecons;
import std.math;
import std.numeric;
pragma(inline,true);

void main(){
    int n,t;
    t=readln.chomp.to!int;
    string s;
    while(t--){
        n=readln.chomp.to!int;
        s=readln.strip;
        long k=s.indexOf('8');
        if(n>=11 && k>=0 && n-k+1>=10)
            writeln("YES");
        else writeln("NO");
    }
}

//ahmat
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.string;
import std.algorithm;
import std.functional;
import std.array;
import std.container;
import std.conv;
import std.container;
import std.typecons;
import std.math;
import std.numeric;
pragma(inline,true);

void main(){
    int n,t;
    t=readln.chomp.to!int;
    string s;
    while(t--){
        n=readln.chomp.to!int;
        s=readln.strip;
        long k=s.indexOf('8');
        if(n>=11 && k>=0 && n-k>=10)
            writeln("YES");
        else writeln("NO");
    }
}


import std.stdio;

void main()
{
    int curvas, curvasPerigosas;
    int[1001] x;
    int[1001] y;

    readf(" %s ", &curvas);
    for(int i = 0; i <= curvas; ++i)
    {
        readf(" %s %s", &x[i], &y[i]);
    }

    for (int i = 1; i < curvas; ++i)
    {
        if (y[i] - y[i - 1] > 0 && x[i + 1] - x[i] < 0
        || x[i] - x[i - 1] > 0 && y[i + 1] - y[i] > 0
        || y[i] - y[i - 1] < 0 && x[i + 1] - x[i] > 0
        || x[i] - x[i - 1] < 0 && y[i + 1] - y[i] < 0)
            ++curvasPerigosas;
    }

    writeln(curvasPerigosas);
}

import std.stdio;
import std.typecons;

void main()
{
    int n;
    Tuple!(int, int)[] points;

    readf("%d", &n);
    points = new Tuple!(int, int)[n + 2];
    for (int i = 0; i < n + 1; i++) {
        readf(" %d %d", &points[i][0], &points[i][1]);
    }
    points[n + 1] = points[1];

    int result = 0;
    for (int i = 1; i <= n; i++) {
        Tuple!(int, int) d[2];

        d[0][0] = points[i][0] - points[i - 1][0];
        d[0][1] = points[i][1] - points[i - 1][1];
        d[1][0] = points[i + 1][0] - points[i][0];
        d[1][1] = points[i + 1][1] - points[i][1];

        if (d[0][0] * d[1][1] - d[1][0] * d[0][1] > 0) {
            result++;
        }
    }

    writef("%d\n", result);
}

import std.stdio;

void main()
{
    int curvas, curvasPerigosas;
    int[1001] x;
    int[1001] y;

    readf(" %s ", &curvas);
    readf(" %s %s", &x[0], &y[0]);
    for(int i = 1; i <= curvas; ++i)
    {
        readf(" %s %s", &x[i], &y[i]);
        if (y[i] - y[i - 1] > 0 && x[i + 1] - x[i] < 0
        || x[i] - x[i - 1] > 0 && y[i + 1] - y[i] > 0
        || y[i] - y[i - 1] < 0 && x[i + 1] - x[i] > 0
        || x[i] - x[i - 1] < 0 && y[i + 1] - y[i] < 0)
            ++curvasPerigosas;
    }

    writeln(curvasPerigosas);
}


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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long s, n;
    readf!" %d %d "(s, n);
    long[] ans;
    auto numpool = redBlackTree!("a<b", true, long)();
    long mul = 1;
    while (s > 0) {
      long digit = s % 10;
      foreach (i ; 0 .. digit)
        numpool.insert(mul);
      s /= 10;
      mul *= 10;
    }
    while (true) {
      if (n == 1) {
        long final_num = 0;
        while (!numpool.empty) {
          final_num += numpool.front;
          numpool.removeFront;
        }
        ans ~= final_num;
        break;
      }
      if (n <= numpool.length || numpool.front == 1) {
        ans ~= numpool.front;
        numpool.removeFront;
        n--;
        continue;
      }
      long tmp = numpool.front;
      numpool.removeFront;
      assert(tmp > 0 && tmp % 10 == 0);
      foreach (i ; 0 .. 10)
        numpool.insert(tmp / 10);
    }
    writeln(ans.map!text.joiner(" "));
  }
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		auto a = new int[](s.length);
		foreach (i; 0..s.length)
			a[i] = s[i]-'0';

		long cnt = a.sum;
		while (n > cnt)
		{
			int p = cast(int)a.length-2;
			while (a[p] == 0)
				--p;
			--a[p];
			a[p+1] += 10;
			cnt += 9;
		}

		(){
		foreach (i; 0..a.length)
		{
			foreach (j; 0..a[i])
			{
				ans[ti] ~= 10^^(a.length-i-1);
				--a[i];
				if (ans[ti].length == n) return;
			}
		}}();
		foreach (i; 0..a.length)
		{
			foreach (j; 0..a[i])
			{
				ans[ti][j%n] += 10^^(a.length-i-1);
			}
		}
	}

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

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

bool solve(long s, long n, ref long[] a)
{
  long[] ans;
  foreach (i ; 0 .. n - 1) {
    ans ~= 1;
  }
  if (s - (n - 1) <= 0)
    return false;

  ans ~= s - (n - 1);
  if (ans.length > 1 && ans.back >= 10) {
    ans.front += ans.back % 10;
    ans.back -= ans.back % 10;
  }
  a = ans;
  return true;
}

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long s, n;
    readf!" %d %d "(s, n);
    long[] best_a;
    long best_div = 1;
    solve(s, n, best_a);
    long div = 10;
    while (s / div * div == s) {
      long[] a;
      if (solve(s / div, n, a)) {
        best_a = a;
        best_div = div;
      }
      div *= 10;
    }
    writeln(best_a.map!(x => (x * best_div).text).joiner(" "));
/*
    long[] ans;
    foreach (i ; 0 .. n - 1) {
      ans ~= 1;
    }
    ans ~= s - (n - 1);
    if (ans.length > 1 && ans.back >= 10) {
      ans.front += ans.back % 10;
      ans.back -= ans.back % 10;
    }
    writeln(ans.map!text.joiner(" "));
*/
  }
}

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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long s, n;
    readf!" %d %d "(s, n);
    long[] ans;
    foreach (i ; 0 .. n - 1) {
      ans ~= 1;
    }
    ans ~= s - (n - 1);
    if (ans.length > 1 && ans.back >= 10) {
      ans.front += ans.back % 10;
      ans.back -= ans.back % 10;
    }
    writeln(ans.map!text.joiner(" "));
  }
}

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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long s, n;
    readf!" %d %d "(s, n);
    long[] ans;
    foreach (i ; 0 .. n - 1) {
      ans ~= 1;
    }
    ans ~= s - (n - 1);
    if (ans.length > 1) {
      ans.front += ans.back % 10;
      ans.back -= ans.back % 10;
    }
    writeln(ans.map!text.joiner(" "));
  }
}

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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long s, n;
    readf!" %d %d "(s, n);
    long[] ans;
    foreach (i ; 0 .. n - 1) {
      ans ~= 1;
    }
    ans ~= s - (n - 1);
    ans.front += ans.back % 10;
    ans.back -= ans.back % 10;
    writeln(ans.map!text.joiner(" "));
  }
}

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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long s, n;
    readf!" %d %d "(s, n);
    long[] ans;
    foreach (i ; 0 .. n - 1) {
      ans ~= 1;
    }
    ans ~= s - (n - 1);
    writeln(ans.map!text.joiner(" "));
  }
}


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

string FMT_F = "%.10f";

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

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

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

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

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

		long x, y;
		foreach (i; 0..n)
		{
			if (x == a[i])
				++x;
			else if (y == a[i])
				++y;
		}
		ans[ti] = x+y;
	}

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

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

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void gen(){
}
void jury(){
}
void solve(){
    foreach(_; 0 .. scan!int){
        int n = scan!int;
        int[] as = scan!int(n);

        int[int] acnt;
        foreach(a; as){
            if(a !in acnt) acnt[a] = 0;
            acnt[a] += 1;
        }

        int ans = 0;
        int i = 0;

        while(i in acnt && acnt[i] >= 2) i ++;
        ans += i;

        while(i in acnt && acnt[i] >= 1) i ++;
        ans += i;

        ans.writeln;
    }
}


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

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = N.iota.map!(i => tuple(A[i], i)).array;
    B.sort();

    auto used = new int[](N);
    auto uf = new UnionFind(N);

    used[B[0][1]] = true;
    int max_locs = 1;
    int ans = B[0][0] + 1;
    uf.cnt = 1;
    uf.lens[1] = 1;

    foreach (i; 1..N) {
        int v = B[i][0];
        int n = B[i][1];
        used[n] = true;
        uf.cnt += 1;
        uf.lens[1] += 1;
        int lens = uf.lens[1];
        if (n > 0 && used[n-1]) lens = uf.unite(n, n-1);
        if (n < N-1 && used[n+1]) lens = uf.unite(n, n+1);
        if (lens == uf.cnt) {
            if (uf.cnt > max_locs) {
                max_locs = uf.cnt;
                ans = v + 1;
            }
        }
    }

    ans.writeln;
}

class UnionFind {
    int N;
    int[] table;
    Tuple!(int, int)[] segs;
    int[] lens;
    int cnt;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
        segs = N.iota.map!(i => tuple(i, i)).array;
        lens = new int[](N+10);
        cnt = 0;
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    int unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return -1;
        if (table[x] > table[y]) swap(x, y);
        cnt -= 1;
        table[x] += table[y];
        lens[segs[x][1] - segs[x][0] + 1] -= 1;
        lens[segs[y][1] - segs[y][0] + 1] -= 1;
        segs[x] = tuple(min(segs[x][0], segs[y][0]), max(segs[x][1], segs[y][1]));
        lens[segs[x][1] - segs[x][0] + 1] += 1;
        table[y] = x;
        return lens[segs[x][1] - segs[x][0] + 1];
    }
}

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

auto biggestBit(T)(T t)
{
  debug assert(t != 0);
  int bitpos = -1;
  while(t)
    {
      t >>= 1;
      bitpos++;
    }
  return bitpos;
}

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);

  auto n = next!int;
  auto a = next!int(n);
  auto numRows = n.biggestBit;
  auto maxIn = new int[][](numRows + 1, n);
  foreach(r; 0 .. numRows + 1)
    maxIn[r][] = -1;
  foreach(i; 0 .. n)
    maxIn[0][i] = i;
  auto maxInd(int i, int j)
  {
    return a[i] > a[j]? i : j;
  }
  foreach(p; 1 .. numRows + 1)
    {
      foreach(i; 0 .. n)
        {
          if ((i + (1 << (p)) - 1) >= n)
            continue;
          maxIn[p][i] = maxInd(maxIn[p - 1][i], maxIn[p - 1][i + (1 << (p - 1))]);
        }
    }
  debug writeln(maxIn);
  auto maxInRange(int s, int e)
  {
    auto len = e - s + 1;
    auto p = len.biggestBit;
    auto lenwithoutbb = len - (1 << p);
    return maxInd(maxIn[p][s], maxIn[p][s + lenwithoutbb]);
  }

  auto poolSize = new int[](n);
  void doPoolSize(int s, int e)
  {
    if (s > e)
      return;
    auto len = e - s + 1;
    auto mxi = maxInRange(s, e);
    debug writeln("in range ", s, " - ", e, " max is ", a[mxi], " with len ", len);
    assert(mxi >= s && mxi <= e);
    poolSize[mxi] = len;
    doPoolSize(s, mxi - 1);
    doPoolSize(mxi + 1, e);
  }
  doPoolSize(0, n - 1);
  debug writeln(poolSize);
  auto sortedIndexes = iota(0, n).array.sort!((i, j) => a[i] < a[j]).array;
  auto lastInd = new int[](n + 1);
  auto sizeCnt = new int[](n + 1);
  auto bestBySize = new int[](n + 1);
  int bestSize = 0;
  lastInd[] = -1;
  debug foreach(i, ind; sortedIndexes)
    {
      write(poolSize[ind], " ");
    }
  debug writeln;
  foreach(i, ind; sortedIndexes)
    {
      auto s = poolSize[ind];
      sizeCnt[s]++;
      auto l = lastInd[s];
      debug if (s == 3) {writeln("sizeCnt ", s, " ", sizeCnt[s], " i ", i);}
      if (sizeCnt[s] * s - 1 == i)
        {
          bestBySize[s] = sizeCnt[s];
          bestSize = max(bestBySize[s], bestSize);
          lastInd[s] = cast(int)i;
        }
    }
  debug writeln("bestBySize: ", bestBySize);
  int minimalUp = int.max;
  foreach(s, b; bestBySize)
    {
      if (s != 0 && b == bestSize)
        {
          minimalUp = min(minimalUp, s * b - 1);
        }
    }
  auto minV = a[sortedIndexes[minimalUp]];
  (minV + 1).writeln;
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

auto biggestBit(T)(T t)
{
  debug assert(t != 0);
  int bitpos = -1;
  while(t)
    {
      t >>= 1;
      bitpos++;
    }
  return bitpos;
}

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);

  auto n = next!int;
  auto a = next!int(n);
  auto numRows = n.biggestBit;
  auto maxIn = new int[][](numRows + 1, n);
  foreach(r; 0 .. numRows + 1)
    maxIn[r][] = -1;
  foreach(i; 0 .. n)
    maxIn[0][i] = i;
  foreach(p; 1 .. numRows + 1)
    {
      foreach(i; 0 .. n)
        {
          if ((i + (1 << (p)) - 1) >= n)
            continue;
          auto v0 = a[maxIn[p - 1][i]];
          auto v1 = a[maxIn[p - 1][i + (1 << (p - 1))]];
          if (v0 > v1)
            maxIn[p][i] = maxIn[p - 1][i];
          else
            maxIn[p][i] = maxIn[p - 1][i + (1 << (p - 1))];
        }
    }
  debug writeln(maxIn);
  auto maxInRange(int s, int e)
  {
    auto len = e - s + 1;
    auto p = len.biggestBit;
    auto lenwithoutbb = len - (1 << p);
    auto v0 = a[maxIn[p][s]];
    auto v1 = a[maxIn[p][s + lenwithoutbb]];
    if (v0 > v1)
      return maxIn[p][s];
    return maxIn[p][s + lenwithoutbb];
  }

  auto poolSize = new int[](n);
  void doPoolSize(int s, int e)
  {
    if (s > e)
      return;
    auto len = e - s + 1;
    auto mxi = maxInRange(s, e);
    debug writeln("in range ", s, " - ", e, " max is ", a[mxi], " with len ", len);
    assert(mxi >= s && mxi <= e);
    poolSize[mxi] = len;
    doPoolSize(s, mxi - 1);
    doPoolSize(mxi + 1, e);
  }
  doPoolSize(0, n - 1);
  debug writeln(poolSize);
  auto sortedIndexes = iota(0, n).array.sort!((i, j) => a[i] < a[j]).array;
  auto lastInd = new int[](n + 1);
  auto bestBySize = new int[](n + 1);
  int bestSize = 0;
  lastInd[] = -1;
  debug foreach(i, ind; sortedIndexes)
    {
      write(poolSize[ind], " ");
    }
  debug writeln;
  foreach(i, ind; sortedIndexes)
    {
      auto s = poolSize[ind];
      auto l = lastInd[s];
      if (i - l == s)
        {
          bestBySize[s]++;
          bestSize = max(bestBySize[s], bestSize);
          lastInd[s] = cast(int)i;
        }
    }
  debug writeln(bestBySize);
  int minimalUp = int.max;
  foreach(s, b; bestBySize)
    {
      if (s != 0 && b == bestSize)
        {
          minimalUp = min(minimalUp, s * b - 1);
        }
    }
  auto minV = a[sortedIndexes[minimalUp]];
  (minV + 1).writeln;
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

auto biggestBit(T)(T t)
{
  debug assert(t != 0);
  int bitpos = -1;
  while(t)
    {
      t >>= 1;
      bitpos++;
    }
  return bitpos;
}

void main(string[] args)
{
  inputFile = stdin;
  debug inputFile = File(args[1]);

  auto n = next!int;
  auto a = next!int(n);
  auto numRows = n.biggestBit;
  auto maxIn = new int[][](numRows + 1, n);
  foreach(r; 0 .. numRows + 1)
    maxIn[r][] = -1;
  foreach(i; 0 .. n)
    maxIn[0][i] = i;
  auto maxInd(int i, int j)
  {
    return a[i] > a[j]? i : j;
  }
  foreach(p; 1 .. numRows + 1)
    {
      foreach(i; 0 .. n)
        {
          if ((i + (1 << (p)) - 1) >= n)
            continue;
          maxIn[p][i] = maxInd(maxIn[p - 1][i], maxIn[p - 1][i + (1 << (p - 1))]);
        }
    }
  debug writeln(maxIn);
  auto maxInRange(int s, int e)
  {
    auto len = e - s + 1;
    auto p = len.biggestBit;
    auto lenwithoutbb = len - (1 << p);
    return maxInd(maxIn[p][s], maxIn[p][s + lenwithoutbb]);
  }

  auto poolSize = new int[](n);
  void doPoolSize(int s, int e)
  {
    if (s > e)
      return;
    auto len = e - s + 1;
    auto mxi = maxInRange(s, e);
    debug writeln("in range ", s, " - ", e, " max is ", a[mxi], " with len ", len);
    assert(mxi >= s && mxi <= e);
    poolSize[mxi] = len;
    doPoolSize(s, mxi - 1);
    doPoolSize(mxi + 1, e);
  }
  doPoolSize(0, n - 1);
  debug writeln(poolSize);
  auto sortedIndexes = iota(0, n).array.sort!((i, j) => a[i] < a[j]).array;
  auto sizeCnt = new int[](n + 1);
  auto bestBySize = new int[](n + 1);
  int bestSize = 0;
  debug foreach(i, ind; sortedIndexes)
    {
      write(poolSize[ind], " ");
    }
  debug writeln;
  foreach(i, ind; sortedIndexes)
    {
      auto s = poolSize[ind];
      sizeCnt[s]++;
      debug if (s == 3) {writeln("sizeCnt ", s, " ", sizeCnt[s], " i ", i);}
      if (sizeCnt[s] * s - 1 == i)
        {
          bestBySize[s] = sizeCnt[s];
          bestSize = max(bestBySize[s], bestSize);
        }
    }
  debug writeln("bestBySize: ", bestBySize);
  int minimalUp = int.max;
  foreach(s, b; bestBySize)
    {
      if (s != 0 && b == bestSize)
        {
          minimalUp = min(minimalUp, s * b - 1);
        }
    }
  auto minV = a[sortedIndexes[minimalUp]];
  (minV + 1).writeln;
}

// INPUT

enum InputStyle
  {
    byChunk, byLine
  };
enum inputStyle = InputStyle.byLine;

File inputFile;
string popWord();
static if (inputStyle == InputStyle.byChunk)
  {
    const chunkSize = 1024 * 1024 * 8;
    const wordSize = 4096;
    char[chunkSize] chunkBuff;
    char[] currChunk;
    void renewChunk()
    {
      if (inputFile.eof)
        currChunk = null;
      else
        currChunk = inputFile.rawRead(chunkBuff);
    }
    char[wordSize] wordBuff;
    char[] word;
    string popWord()
    {
      if (currChunk.length == 0)
        renewChunk;
      assert(currChunk.length > 0);
      while (currChunk[0].isWhite)
        {

          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            renewChunk;
        }
      word = wordBuff[0 .. 0];
      while (!currChunk[0].isWhite)
        {
          word.length++;
          word[$ - 1] = currChunk[0];
          currChunk = currChunk[1 .. $];
          if (currChunk.length == 0)
            {
              renewChunk;
              if (currChunk.length == 0)
                return cast(string) word;
            }
        }
      return cast(string) word;
    }
  }
 else
   {
     DList!string _words;
     string popWord()
     {
       while (_words.empty)
         {
           foreach(w; inputFile.readln.split)
             {
               _words.insertBack(w);
             }
         }
       auto word = _words.front;
       _words.removeFront;
       return word;
     }
   }
T next(T)()
{
  return to!T(popWord);
}
auto next(T, S...)(S s)
{
  static if (S.length == 0)
    {
      return to!T(popWord);
    }
  else
    {
      auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);
      foreach(ref elem; res)
        elem = next!T(s[1 .. $]);
      return res;
    }
}

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

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = N.iota.map!(i => tuple(A[i], i)).array;
    B.sort();

    auto used = new int[](N);
    auto uf = new UnionFind(N);

    used[0] = true;
    int max_locs = 1;
    int ans = B[0][1] + 1;
    uf.cnt = 1;

    foreach (i; 1..N) {
        int v = B[i][0];
        int n = B[i][1];
        used[n] = true;
        uf.cnt += 1;
        int lens = -1;
        if (n > 0 && used[n-1]) lens = uf.unite(n, n-1);
        if (n < N-1 && used[n+1]) lens = uf.unite(n, n+1);
        if (lens > 0 && lens == uf.cnt) {
            if (uf.cnt > max_locs) {
                max_locs = uf.cnt;
                ans = v + 1;
            }
        }
    }

    ans.writeln;
}

class UnionFind {
    int N;
    int[] table;
    Tuple!(int, int)[] segs;
    int[] lens;
    int cnt;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
        segs = N.iota.map!(i => tuple(i, i)).array;
        lens = new int[](N+1);
        cnt = 0;
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    int unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return -1;
        if (table[x] > table[y]) swap(x, y);
        cnt -= 1;
        table[x] += table[y];
        lens[segs[x][1] - segs[x][0] + 1] -= 1;
        lens[segs[y][1] - segs[y][0] + 1] -= 1;
        segs[x] = tuple(min(segs[x][0], segs[y][0]), max(segs[x][1], segs[y][1]));
        lens[segs[x][1] - segs[x][0] + 1] += 1;
        table[y] = x;
        return lens[segs[x][1] - segs[x][0] + 1];
    }
}


import std.stdio, std.string;
T x(T)(T a) {
	if (a.length&1) return a;
	auto b=a[0..$/2].x, c=a[$/2..$].x;
	return b<c ? b~c : c~b;
}
void main() {writeln (readln.strip.x==readln.strip.x ? "YES" : "NO");}

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

string canonize (string a)
{
	if (a.length % 2 == 0)
	{
		string b = canonize (a[0..$ / 2]);
		string c = canonize (a[$ / 2..$]);
		return min (b, c) ~ max (b, c);
	}
	return a;
}

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		string t = readln.strip;
		writeln ((canonize (s) == canonize (t)) ? "YES" : "NO");
	}
}

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

T x (T) (T a)
{
	if (a.length & 1) return a;
	auto b = x (a[0..$ / 2]), c = x (a[$ / 2..$]);
	return min (b, c) ~ max (b, c);
}

void main ()
{
	writeln (readln.strip.x == readln.strip.x ? "YES" : "NO");
}

T x(T)(T a){if(a.length&1)return a;auto b=a[0..$/2].x,c=a[$/2..$].x;return b<c?b~c:c~b;}
void main(){import std.stdio;writeln(readln[0..$-1].x==readln[0..$-1].x?"YES":"NO");}

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

bool ok (string a, string b)
{
	if (a.length % 2 == 0)
	{
		if ((a[0..$ / 2] < a[$ / 2..$]) ==
		    (b[0..$ / 2] < b[$ / 2..$]))
		{
			return ok (a[0..$ / 2], b[0..$ / 2]) &&
			    ok (a[$ / 2..$], b[$ / 2..$]);
		}
		else
		{
			return ok (a[0..$ / 2], b[$ / 2..$]) &&
			    ok (a[$ / 2..$], b[0..$ / 2]);
		}
	}
	else
	{
		return a == b;
	}
}

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		string t = readln.strip;
		writeln (ok (s, t) ? "YES" : "NO");
	}
}


import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

const long mod = 1_000_000_007;

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	int n = read.to!int;
	long t = read.to!long;

	long[] ss, ds;
	foreach(i; 0 .. n){
		ss ~= read.to!long;
		ds ~= read.to!long;
	}

	long bestx = 10_000_000, ans = -1;
	foreach(i; 0 .. n){
		long s = ss[i], d = ds[i];
		long x;
		if(s >= t) x = s;
		else x = s + (t - s + d - 1) / d * d;

		if(x < bestx){
			bestx = x;
			ans = i + 1;
		}
	}

	ans.writeln;

}

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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto T = s[1].to!long;

    long idx = -1;
    long ans = 1L << 59;

    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        auto a = s[0].to!long;
        auto b = s[1].to!long;
        long tmp;
        if (a >= T) {
            tmp = a;
        } else {
            long m1 = T % b;
            long m2 = a % b;
            if (m1 <= m2) {
                tmp = T + m2 - m1;
            } else {
                tmp = T + b - m1 + m2;
            }
        }
        if (tmp < ans) {
            ans = tmp;
            idx = i + 1;
        }
    }

    idx.writeln;
}

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

string FMT_F = "%.10f";

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

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

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

void main()
{
	auto N = RD;
	auto T = RD;

	long best = long.max;
	long ans;
	foreach (i; 0..N)
	{
		auto s = RD;
		auto d = RD;
		auto x = s - T;
		auto y = abs(x / d);
		if (x < 0)
		{
			x += (y+1) * d;
			x %= d;
		}
		if (x < best)
		{
			best = x;
			ans = i + 1;
		}
		debug writeln(i, " ", best, " ", ans);
	}

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


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

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

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

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

    int idx = 0;
    while(k > 0 && idx < n) {
        while(a[idx] <= 0) {
            idx += 1;
        }
        if (idx >= n - 1) break;
        a[idx]--;
        a[$ - 1]++;
        k -= 1;
    }

    foreach(item; a)
        writef("%s ", item);
    "".writeln;
}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		foreach (i; 0..n-1)
		{
			auto x = min(k, a[i]);
			a[i] -= x;
			a[$-1] += x;
			k -= x;
		}
		ans[ti] = a;
	}

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

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;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto param = readln().chomp.splitter(" ").array;
        int k = to!int(param[1]);
        auto arr = readln().chomp.split(" ").map!(to!int).array;
        int e = arr.length-1;
        int b = 0;

        while(b < e && k > 0)
        {
            if(arr[b] > 0 && arr[e] < int.max)
            {
                arr[b]--;
                arr[e]++;
                k--;
            }
            else if(arr[b] <= 0)
            {
                b++;
            }
            else
            {
                e--;
            }
        }

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

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

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

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

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

    int idx = 0;
    while(k > 0 && idx < n - 1) {
        while(a[idx] <= 0) {
            idx += 1;
        }
        a[idx]--;
        a[$ - 1]++;
        k -= 1;
    }

    foreach(item; a)
        writef("%s ", item);
    "".writeln;
}
}

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

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

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

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

    int idx = 0;
    while(k > 0 && idx <= n - 1) {
        while(a[idx] <= 0) {
            idx += 1;
        }
        a[idx]--;
        a[$ - 1]++;
        k -= 1;
    }

    foreach(item; a)
        writef("%s ", item);
    "".writeln;
}
}

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

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

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

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

    int idx = 0;
    while(k-- && idx <= n - 1) {
        while(a[idx] <= 0) {
            idx += 1;
        }
        a[idx]--;
        a[$ - 1]++;
    }

    foreach(item; a)
        writef("%s ", item);
    "".writeln;
}
}

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

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

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

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

    int idx = 0;
    while(k-- && idx <= n - 1) {
        if(a[idx] <= 0) {
            idx += 1;
        }
        a[idx]--;
        a[$ - 1]++;
    }

    foreach(item; a)
        writef("%s ", item);
    "".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;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto param = readln().chomp.splitter(" ").array;
        int k = to!int(param[1]);
        auto arr = readln().chomp.split(" ").map!(to!int).array;
        int e = arr.length-1;
        int b = 0;

        while(b < e && k > 0)
        {
            if(arr[b] > 0)
            {
                arr[b]--;
                b++;
            }
            else
            {
                b++;
            }

            if(arr[e] < 10)
            {
                arr[e]++;
            }
            else
            {
                e--;
            }

            k--;
        }

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

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;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto param = readln().chomp.splitter(" ").array;
        int k = to!int(param[1]);
        auto arr = readln().chomp.split(" ").map!(to!int).array;
        int e = arr.length-1;
        int b = 0;

        while(b < e && k > 0)
        {
            if(arr[b] > 0)
            {
                arr[b]--;
                arr[e]++;
                e--;
                k--;
            }
            b++;
        }

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

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;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto param = readln().chomp.splitter(" ").array;
        int k = to!int(param[1]);
        auto arr = readln().chomp.split(" ").map!(to!int).array;
        int e = arr.length-1;
        int b = 0;

        while(b < e && k > 0)
        {
            while(b < arr.length && arr[b] == 0) b++;
            if(b == arr.length) continue;

            arr[b]--;
            arr[e]++;
            b++;
            e--;
            k--;
        }

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

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;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto param = readln().chomp.splitter(" ").array;
        int k = to!int(param[1]);
        auto arr = readln().chomp.split(" ").map!(to!int).array;
        int e = arr.length-1;
        int b = 0;

        while(b < e && k > 0)
        {
            while(b < arr.length && arr[b] <= k) b++;
            if(b == arr.length) continue;

            arr[b]--;
            arr[e]++;
            b++;
            e--;
            k--;
        }

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

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;

void main()
{
    auto n= to!long(readln().chomp);
    foreach(_; 0..n)
    {
        auto param = readln().chomp.splitter(" ").array;
        int k = to!int(param[1]);
        auto arr = readln().chomp.split(" ").map!(to!int).array;
        int e = arr.length-1;
        int b = 0;

        while(b < e && k > 0)
        {
            while(b < arr.length && arr[b] <= k) b++;
            if(b == arr.length) continue;

            arr[b]--;
            arr[e]++;
            b++;
            e--;
            k--;
        }

        writeln(arr[]);
    }
}


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; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

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

void main()
{
	auto t = RD!int;
	auto ans = new string[](t);
	foreach (ti; 0..t)
	{
		auto s = RD!string;
		if (s.length >= 2)
		{
			if (s[$-2..$] == "po")
			{
				ans[ti] = "FILIPINO";
				continue;
			}
			if (s.length >= 4)
			{
				if (s[$-4..$] == "desu" || s[$-4..$] == "masu")
				{
					ans[ti] = "JAPANESE";
					continue;
				}
				if (s.length >= 5)
				{
					if (s[$-5..$] == "mnida")
					{
						ans[ti] = "KOREAN";
						continue;
					}
				}
			}
		}
	}
	foreach (e; ans)
		writeln(e);

	stdout.flush;
	debug readln;
}

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 main() {
        IO cin;
        int t = 1;
        t = cin.read_int;
        while (t--) {
                string s = cin.read_string;
                if (endsWith(s, "po")) writeln("FILIPINO");
                else if (endsWith(s, "desu") || endsWith(s, "masu")) writeln("JAPANESE");
                else writeln("KOREAN");
        }
}


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

void main ()
{
	readln;
	int n;
	while (readf !(" %s") (n) > 0)
	{
		int res = 0;
		foreach (i; 0..n)
		{
			auto add = (i + 1 == n || i + 1 < n / 2);
			res += (2 << i) * (add ? +1 : -1);
		}
		writeln (res);
	}
}

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

string FMT_F = "%.10f";

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

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

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

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;
		long x, y;
		foreach (i; 0..n-1)
		{
			if (i < n/2-1)
			{
				x += 2^^(i+1);
			}
			else
			{
				y += 2^^(i+1);
			}
		}
		x += 2^^n;
		ans[ti] = x - y;
	}

	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 (_t; 0..T) {
        auto N = readln.chomp.to!long;
        long a = 2L^^N, b;
        foreach (i; 1..N/2) {
            a += 2L^^i;
        }
        foreach (i; N/2..N) {
            b += 2L^^i;
        }
        writeln(a - b);
    }
}


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;

void main() {
    int N, X; scanf("%d %d\n", &N, &X);
    auto A = readln.chomp.split(" ").map!(to!int).array;
    auto B = readln.chomp.split(" ").map!(to!int).array;

    A.sort;
    B.sort;

    void first() {
        auto a = A.dup,
             b = B.dup;
        int L = a.back + b.back;
        a.popBack; b.popBack;
        int bi = 0;
        int ans = 1;
        for (int ai = N - 2; ai >= 0; ai--) {
            if (a[ai] + b[bi] <= L) {
                bi++;
            } else {
                ans++;
            }
        }
        write(ans);
    }
    void second() {
        auto a = A.dup,
             b = B.dup;
        auto set = redBlackTree!(true)(b);
        int ans = 0;
        for (int ai = 0; ai < N; ai++) {
            auto r = set.upperBound(X - a[ai] - 1);
            if (r.empty) continue;
            set.removeKey(r.front);
            ans++;
        }
        write(ans);
    }
    first(); write(" "); second();
    writeln;
}

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

immutable int MX = 2 ^^ 14 - 1;

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

    auto arr = new int[][] (2);
    foreach (i; 0 .. 2) {
        arr[i] = readln.chomp.split.map!(to!int).array;
        arr[i].sort().reverse();
    }

    debug { arr[0].writeln; }

    int chk(int idx1) {
        int ans = 0, mv = n-1;
        foreach (i; 0 .. n) {
            while (mv >= 0 && arr[idx1][i] + arr[1-idx1][mv] < x) { --mv; }

            if (mv >= 0) {
                ++ans;
                --mv;
            }
        }

        return ans;
    }

    int ans = max(chk(0), chk(1));
    writeln("1 ", ans);
}


import core.bitop, std.algorithm, std.conv, std.stdio, std.string;
alias f = n => (n *= 2) - n.popcnt;
void main() {foreach (t; 0..readln.strip.to!int) readln.strip.to!long.f.writeln;}

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

string FMT_F = "%.10f";

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

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

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

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

		auto cnt = new long[](64);
		cnt[0] = 1;
		foreach (i; 1..64)
		{
			cnt[i] = cnt[i-1] * 2 + 1;
		}

		foreach (i; 0..64)
		{
			auto bit = 1L << i;
			if (n & bit)
			{
				ans[ti] += cnt[i];
			}
		}
	}

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

import core.bitop,std.conv,std.stdio,std.string;
alias f=n=>(n*=2)-n.popcnt;
void main(){foreach(t;0..readln.strip.to!int)readln.strip.to!long.f.writeln;}

import std.stdio;
import std.stdio;
import std.algorithm;
import std.range;
import std.functional;
import std.conv;
import std.string;
import std.math;
import core.bitop;

ulong diff(ulong a, ulong b) {
	ulong res = 0;
	foreach (bit; 0 .. 64) {
		if ((a & (1UL << bit)) != (b & (1UL << bit))) {
			res++;
		}
	}
	return res;
}

ulong calc(ulong a) {
	if ((a & (a - 1)) == 0) {
		return a | (a - 1);
	}
	else {
		ulong highestBit = 1UL << bsr(a);
		return calc(a - highestBit) + calc(highestBit);
	}
}

void main() {
	// ulong res = 0;
	// foreach (i; 0 .. 1000) {
	// 	res += diff(i, i + 1);
	// 	write("f(", (i + 1).to!string.padLeft(' ', 10), ") = ", res.to!string(2).padLeft('0', 10));
	// 	writeln("; ", calc(i + 1).to!string(2).padLeft('0', 10));
	// }
	int tt = readln().chomp.to!int;
	outer: foreach (t; 0 .. tt) {
		ulong n = readln().chomp.to!ulong;
		// writeln(n.to!string(2).padLeft('0', 64));
		writeln(calc(n));
	}
}


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

void main() {
    string s = readln.strip;
    int n = to!int(s.length);

    int[26] min_idx = n;

    for (int i = n-1; i >= 0; i--) {
        min_idx[s[i]-'a'] = i;
    }

    debug {
        writefln!"%s"(min_idx);
    }

    foreach (i; 0 .. n) {
        int j = s[i] - 'a';
        if (min_idx[0 .. j].any!( (a) => a < i )) {
            write("Ann\n");
        } else {
            write("Mike\n");
        }
    }
}

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

void main() {
    string s = readln.strip;
    int n = to!int(s.length);

    int[26] min_idx = n;

    for (int i = n-1; i >= 0; i--) {
        min_idx[s[i]-'a'] = i;
    }

    debug {
        writefln!"%s"(min_idx);
    }

    foreach (i; 0 .. n) {
        int j = s[i] - 'a';
        if (min_idx[0 .. j].find!( (a,b) => a < b )(i).empty) {
            writeln("Mike");
        } else {
            writeln("Ann");
        }
    }
}

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

void main() {
    string s = readln.strip;
    int n = to!int(s.length);

    int[26] min_idx = n;

    for (int i = n-1; i >= 0; i--) {
        min_idx[s[i]-'a'] = i;
    }

    debug {
        writefln!"%s"(min_idx);
    }

    foreach (i; 0 .. n) {
        int j = s[i] - 'a';
        if (min_idx[0 .. j].any!( (a) => a < i )) {
            writeln("Ann");
        } else {
            writeln("Mike");
        }
    }
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const S = readToken();

      char mn = 'z' + 1;
      foreach (c; S) {
        writeln((mn < c) ? "Ann" : "Mike");
        chmin(mn, c);
      }
    }
  } catch (EOFException e) {
  }
}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto s = RD!string;
	char best = s[0];
	writeln("Mike");
	foreach (c; s[1..$])
	{
		if (c <= best)
		{
			writeln("Mike");
		}
		else
		{
			writeln("Ann");
		}
		best = min(best, c);
	}

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


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

void main()
{
    readln;

    auto r = () => readln.chomp.split.map!(to!int).array;
    auto c = r();
    auto a = r();

    debug { c.writeln; a.writeln; }

    auto ans = 0;
    int aidx = 0;
    foreach (e; c) {
        if (e > a[aidx]) continue;

        ans += 1;
        ++aidx;

        if (aidx == a.length) break;
    }

    ans.writeln;
}

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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto C = readln.split.map!(to!int).array;
    auto A = readln.split.map!(to!int).array;
    int ans = 0;

    for (int i = 0, p = 0; i < N && p < M; ++i) {
        if (C[i] <= A[p]) {
            ans += 1;
            p += 1;
        }
    }

    ans.writeln;
}

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

  int n, m; rd(n, m);
  auto c=readln.split.to!(int[]);
  auto a=readln.split.to!(int[]);

  int cnt=0;
  for(int i=0, j=0; i<n && j<m; ){
    if(c[i]<=a[j]){
      cnt++;
      i++; j++;
    }else{
      i++;
    }
  }

  writeln(cnt);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


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

immutable int letters = 26;
immutable int mod = 10 ^^ 9 + 7;

void main () {
	int n;
	while (readf (" %s", &n) > 0) {
		readln;
		auto s = readln.strip.map !(x => x - 'a').array;

		auto next = new int [] [] (n, letters);
		foreach (let; 0..letters) {
			int pos = n;
			foreach_reverse (i; 0..n) {
				if (s[i] == let) pos = i;
				next[i][let] = pos;
			}
		}

		auto f = new long [] [] (2, n + 1);
		int b = 0;
		f[b][] = 0;
		f[b][0] = 1;
		foreach (num; 0..n)
		{
			b ^= 1;
			f[b][] = 0;
			foreach (pos; 0..n) {
				auto cur = f[!b][pos];
				auto ptr = next[pos].ptr;
				foreach (let; 0..letters) f[b][*(ptr + let)] += cur;
			}
			foreach (pos; 0..n) f[b][pos] %= mod;
		}

		int res = 0;
		foreach (pos; 0..n) res = (res + f[b][pos]) % mod;
		writeln (res);
	}
}

import core.bitop;
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int letters = 26;
immutable int mod = 10 ^^ 9 + 7;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto s = readln.strip.map !(x => x - 'a').array;

		auto next = new int [] [] (n, letters);
		foreach (let; 0..letters)
		{
			int pos = n;
			foreach_reverse (i; 0..n)
			{
				if (s[i] == let)
				{
					pos = i;
				}
				next[i][let] = pos;
			}
		}

		auto f = new long [] [] (2, n + 1);
		int b = 0;
		f[b][] = 0;
		f[b][0] = 1;
		foreach (num; 0..n)
		{
			b ^= 1;
			f[b][] = 0;
			foreach (pos; 0..n)
			{
				auto cur = f[!b][pos];
				auto ptr = next[pos].ptr;
				f[b][*(ptr +  0)] += cur;
				f[b][*(ptr +  1)] += cur;
				f[b][*(ptr +  2)] += cur;
				f[b][*(ptr +  3)] += cur;
				f[b][*(ptr +  4)] += cur;
				f[b][*(ptr +  5)] += cur;
				f[b][*(ptr +  6)] += cur;
				f[b][*(ptr +  7)] += cur;
				f[b][*(ptr +  8)] += cur;
				f[b][*(ptr +  9)] += cur;
				f[b][*(ptr + 10)] += cur;
				f[b][*(ptr + 11)] += cur;
				f[b][*(ptr + 12)] += cur;
				f[b][*(ptr + 13)] += cur;
				f[b][*(ptr + 14)] += cur;
				f[b][*(ptr + 15)] += cur;
				f[b][*(ptr + 16)] += cur;
				f[b][*(ptr + 17)] += cur;
				f[b][*(ptr + 18)] += cur;
				f[b][*(ptr + 19)] += cur;
				f[b][*(ptr + 20)] += cur;
				f[b][*(ptr + 21)] += cur;
				f[b][*(ptr + 22)] += cur;
				f[b][*(ptr + 23)] += cur;
				f[b][*(ptr + 24)] += cur;
				f[b][*(ptr + 25)] += cur;
			}
			foreach (pos; 0..n)
			{
				f[b][pos] %= mod;
			}
		}

		int res = 0;
		foreach (pos; 0..n)
		{
			res += f[b][pos];
			if (res >= mod)
			{
				res -= mod;
			}
		}
		writeln (res);
	}
}


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

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

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

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

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

int N;
long[] A;

void main(string[] args) {
	try {
	for (; ; ) {
		N = readInt;
		A = new long[N];
		foreach (i; 0 .. N) {
			A[i] = readLong;
		}

		long[] ASum = new long[N + 1];
		foreach (i; 0 .. N) {
			ASum[i + 1] = ASum[i] + A[i];
		}

		long ans;

		if (ASum[N] % 3 == 0) {
			const target = ASum[N] / 3;
			long cnt;
			foreach (i; 1 .. N) {
				if (ASum[i] == target * 2) {
					ans += cnt;
				}
				if (ASum[i] == target) {
					++cnt;
				}
			}
		}

		writeln(ans);

	}
	} catch (EOFException) {}
}

import std.stdio, std.string;

void solve(int[] s)
{
    auto sum = 0;
    foreach (val; s)
    {
        sum += val;
    }
    if (sum % 3 != 0)
    {
        writeln("0");
        return;
    }
    sum /= 3;
    auto n = cast(int)s.length;
    auto cnt = new int[n];
    auto last = 0;
    auto acc = 0;
    for (int i = n - 1; i >= 0; -- i)
    {
        cnt[i] = last;
        acc += s[i];
        if (acc == sum)
        {
            ++ cnt[i];
        }
        last = cnt[i];
    }
    long ans = 0;
    last = 0;
    acc = 0;
    foreach (i; 0 .. n)
    {
        acc += s[i];
        if (acc == sum && i + 2 < n)
        {
            ans += cnt[i + 2];
        }
    }
    writeln(ans);
}

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