import std.stdio;
import std.conv;
import std.string;
import std.array: Appender;
import std.datetime;
import std.algorithm;

void main()
{

	auto n = to!int(strip(readln));
	int[] r = new int[377];
	int[] c = new int[377];
	for (auto i = 0; i < n; i++)
	{
		auto str = split(strip(readln));
		foreach (num; to!int(str[1])..to!int(str[2])+1)
		{
			if (str[0] == "F")
				r[num]++;
			else
				c[num]++;
		}
	}
	int count;
	foreach (i, ele; r)
	{
		count = max(min(r[i], c[i]), count);
	}
	writeln(2 * count);
}

import std.stdio;
import std.algorithm;

void main()
{
	int n;

	scanf("%d", &n);

	bool[] used = new bool[n];
	char[] gender = new char[n];
	int[] from = new int[n];
	int[] to = new int[n];

	for (int i = 0; i < n; i++) {
		char[10] s;
		scanf("%s%d%d", s.ptr, &from[i], &to[i]);
		gender[i] = s[0];
	}

	int res = 0;

	for (int i = 1; i <= 366; i++) {
		char[2] genders = ['F', 'M'];
		int[2] found = [0, 0];
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < n; k++) {
				if (!used[k] && gender[k] == genders[j] && from[k] <= i && to[k] >= i) {
					found[j]++;
				}
			}
		}

		res = max(res, min(found[0], found[1]));
	}

	printf("%d\n", 2 * res);
}

import std.stdio;
import std.conv;
import std.string;
import std.array: Appender;
import std.datetime;
import std.algorithm;

void main()
{

	auto n = to!int(strip(readln));
	int[] r = new int[377];
	int[] c = new int[377];
	for (auto i = 0; i < n; i++)
	{
		auto str = split(strip(readln));
		foreach (num; to!int(str[1])..to!int(str[2]))
		{
			if (str[0] == "F")
				r[num]++;
			else
				c[num]++;
		}
	}
	int count;
	foreach (i, ele; r)
	{
		count = max(min(r[i], c[i]), count);
	}

	writeln(2 * count);
}

import std.stdio;
import std.conv;
import std.string;
import std.array: Appender;
import std.datetime;
import std.algorithm;

void main()
{

	auto n = to!int(strip(readln));
	int[] r = new int[377];
	int[] c = new int[377];
	for (auto i = 0; i < n; i++)
	{
		auto str = split(strip(readln));
		foreach (num; to!int(str[1])..to!int(str[2]))
		{
			if (str[0] == "F")
				r[num]++;
			else
				c[num]++;
		}
	}
	int count;
	foreach (i, ele; r)
	{
		count = max(min(r[i], c[i]), count);
	}

	writeln(count);
}

import std.stdio;
import std.conv;
import std.string;
import std.array: Appender;
import std.datetime;
import std.algorithm;

void main()
{

	auto n = to!int(strip(readln));
	int[] r = new int[377];
	int[] c = new int[377];
	for (auto i = 0; i < n; i++)
	{
		auto str = split(strip(readln));
		foreach (num; to!int(str[1])..to!int(str[2]))
		{
			if (str[0] == "F")
				r[num]++;
			else
				c[num]++;
		}
	}
	int count;
	foreach (i, ele; r)
	{
		count = min(r[i], c[i]);
	}

	writeln(count);
}


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

void theCode(){
    ll n = scan;
    auto arr = scanArray;
    ll odd = 0;
    for(int i = 0; i < 2*n; ++i){
        if(arr[i] % 2 == 1){
            ++odd;
        }
    }
    if(odd == n){
        writeln("Yes");
    }else{
        writeln("No");
    }
}

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

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

// Vicfred
// https://codeforces.com/contest/1542/problem/A
// math, implementation
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

while(t--) {
    int n = readln.chomp.to!int;
    int[] a = readln.split.map!(to!int).array;
    int even = 0;
    int odd = 0;
    foreach(item; a) {
        if(item % 2 == 0) {
            even += 1;
        } else {
            odd += 1;
        }
    }
    if(even == odd) {
        "Yes".writeln;
    } else {
        "No".writeln;
    }
}
}

// code by cutx64

module main;

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

void main() {

  int tests; readf!"%s\n"(tests);
  immutable(long) mod = 10 ^^ 9 + 7;
  while(tests--) {
    int n;
    readf!"%s\n"(n);
    auto a = readln.splitter.map!(to!int).array;
    int odd = a.count!(x => x % 2 == 1);
    writeln(["Yes", "No"][odd != n]);
  }

} // main

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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long n;
    readf!" %d "(n);
    auto a = readln.strip.split.map!(to!long).array;
    auto b = a.filter!(x => x % 2 == 0).array;
    auto c = a.filter!(x => x % 2 == 1).array;
    if (b.length == c.length) {
      writeln("Yes");
    } else {
      writeln("No");
    }
  }
}

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

		long cnt;
		foreach (e; a)
		{
			if (e % 2)
				++cnt;
		}

		ans[ti] = cnt == n;
	}

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


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

immutable int limit = 128;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip.dup;
		auto t = readln.strip;
		int [limit] num;
		foreach (ref c; s)
		{
			num[c] += 1;
		}
		auto p = limit.iota.array;
		if (t == "abc" && num['a'] && num['b'] && num['c'])
		{
			swap (p['b'], p['c']);
		}
		foreach (ref c; p)
		{
			foreach (i; 0..num[c])
			{
				write (cast (char) (c));
			}
		}
		writeln;
	}
}

immutable multi = true;

void solve(int tc)
{
  auto s = cast(byte[])readString;
  auto t = cast(byte[])readString;
  auto ca = s.count!(c => c == 'a');
  auto cb = s.count!(c => c == 'b');
  auto cc = s.count!(c => c == 'c');
  sort(s);
  if (t != "abc") return writeln(cast(string)s);
  if (ca > 0 && cb > 0 && cc > 0)
    {
      s = s[ca + cb + cc .. $];
      foreach(i; 0 .. ca) write('a');
      foreach(i; 0 .. cc) write('c');
      foreach(i; 0 .. cb) write('b');
    }
  writeln(cast(string)s);
}

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

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

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

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

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

import std;

void
printSmallest (in int[dchar] frec) {
    foreach (dchar c; frec.keys.sort)
        write(c.repeat(frec[c]));
    writeln();
}

void main () {
    int tests;
    readf("%s\n", tests);
    foreach (i; 0 .. tests) {
        string s, t;
        s = readln()[0 .. $ - 1];
        t = readln()[0 .. $ - 1];

        int[dchar] frec;

        foreach (c; s)
            ++ frec[c];

        if (t == "abc" && 'a' in frec && 'b' in frec && 'c' in frec) {
            static foreach (c; "acb") {
                write(c.repeat(frec[c]));
                frec.remove(c);
            }
        }
        printSmallest(frec);
    }
}

//""

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 string[](t);
	foreach (ti; 0..t)
	{
		auto S = RD!string;
		auto T = RD!string;

		auto cnt = new long[](26);
		foreach (c; S)
			++cnt[c-'a'];

		if (T == "abc")
		{
			if (cnt[0] == 0 || cnt[1] == 0 || cnt[2] == 0)
			{
				foreach (i; 0..26)
					foreach (_; 0..cnt[i])
						ans[ti] ~= cast(char)('a'+i);
			}
			else
			{
				foreach (_; 0..cnt[0])
					ans[ti] ~= "a";
				foreach (_; 0..cnt[2])
					ans[ti] ~= "c";
				foreach (_; 0..cnt[1])
					ans[ti] ~= "b";
				foreach (i; 3..26)
					foreach (_; 0..cnt[i])
						ans[ti] ~= cast(char)('a'+i);
			}
		}
		else
		{
			foreach (i; 0..26)
				foreach (_; 0..cnt[i])
					ans[ti] ~= cast(char)('a'+i);
		}
	}

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

immutable multi = true;

void solve(int tc)
{
  auto s = cast(byte[])readString;
  auto t = cast(byte[])readString;
  sort(s);
  if (t != "abc") return writeln(cast(string)s);
  foreach(i, si; s)
    if (s[i .. min($, i + 3)] == "abc")
      {
	swap(s[i + 1], s[i + 2]);
      }
  writeln(cast(string)s);
}

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

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

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

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

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


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

string FMT_F = "%.10f";

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

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

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

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

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

		int x = a[0];
		bool ok;
		foreach (i; 0..n)
		{
			if (a[i] != x)
			{
				ok = true;
				break;
			}
		}
		ans[ti] = ok ? 1 : n;
	}

	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;
		writeln (a.minElement == a.maxElement ? n : 1);
	}
}

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

        const ans = A.all!(a => (a == A[0])) ? N : 1;
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

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

alias type = multi;
struct TestCase
{
  mixin prettyPrinting;

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

  void solve(long tc = -1)
  {
    auto set = redBlackTree!long(a);
    if (set.length > 1)
      return writeln(1);
    return writeln(a.length);
  }
}

struct Interval
{
  long l, h;

  bool empty()
  {
    return l > h;
  }
}

Interval intersect(Interval a, Interval b)
{
  return Interval(max(a.l, b.l), min(a.h, b.h));
}

struct If
{
  string condition;
}
enum ignore = If("false");
struct Dim
{
  string dimensions;
  int levels;
  this(string dimensions)
  {
    this.dimensions = dimensions;
    levels = cast(int)dimensions.count(",") + 1;
  }
}

template getArrayLevel(W)
{
  static if (isDynamicArray!W && !is(W == string))
    enum getArrayLevel = 1 + getArrayLevel!(removeArray!(W, 1));
  else
    enum getArrayLevel = 0;
}

static foreach(fieldName; 'a' .. cast(char)('z' + 1))
  {
    static if (fieldName != 'o')
      mixin("enum d", fieldName, " = Dim(\"", fieldName, "\");");
  }

mixin template prettyPrinting()
{
  string toString()
  {
    alias structType = typeof(this);
    auto res = appender!(string)();
    res.put(structType.stringof);
    res.put("(");
    static foreach(fieldName; FieldNameTuple!structType)
      {
        res.put(text(" ", fieldName, ": ", mixin(fieldName)));
      }
    res.put(" )");
    res.put("\n");
    return res[];
  }
}

struct Graph(N)
{
  size_t size;
  this(S)(S size)
  {
    adjacencyList.length = cast(size_t) size;
    this.size = cast(size_t) size;
    this.visited = makeSlice!bool(size);
  }
  N[][] adjacencyList;
  alias ne = neighbours;
  N[] neighbours(N n)
  {
    return adjacencyList.at(n);
  }
  alias bcon = biconnect;
  void biconnect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
    adjacencyList.at(b) ~= a;
  }
  alias con = connect;
  void connect(N a, N b)
  {
    adjacencyList.at(a) ~= b;
  }
  void connect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        connect(edge[0], edge[1]);
      }
  }
  void biconnect(R)(R edges)
  {
    foreach(ref edge; edges)
      {
        biconnect(edge[0], edge[1]);
      }
  }
  alias deg = degree!long;
  auto degree(T)(N a)
  {
    return cast(T) adjacencyList.at(a).length;
  }

  auto visited = new bool[0];
  void dfs(Visitor)(long startNode)
  {
    auto visitor = Visitor.init;
    void internalDfs(long node)
    {
      visited.set(node, true);
      static if (is(typeof({visitor.n = node;})))
        visitor.n = node;
      static if (is(typeof({visitor.pre;})))
        visitor.pre;
      foreach(w; ne(node))
        if (!visited.at(w))
          {
            static if (is(typeof({visitor.w = w;})))
              visitor.w = w;
            static if (is(typeof(visitor.pren)))
              visitor.pren;
            internalDfs(w);
            static if (is(typeof(visitor.postn)))
              visitor.postn;
          }
      static if (is(typeof(visitor.post)))
        visitor.post;
    }
    internalDfs(startNode);
  }
  void dfs(long startNode)
  {
    struct DefVisitor {}
    dfs!DefVisitor(startNode);
  }
}

DList!string _words;

template removeArray(W, int times)
{
  static if (times == 0)
    alias removeArray = W;
  else static if (times == 1)
    alias removeArray = typeof(function(){W w; return w[0];}());
  else
    {
      static assert(isDynamicArray!W);
      alias removeArray = removeArray!(removeArray!(W, 1), times - 1);
    }
}

template baseType(W)
{
  static if (isDynamicArray!W && !is(W == string))
    alias baseType = baseType!(typeof((delegate() {W w; return w[0];})()));
  else
    alias baseType = W;
}

auto makeSlice(E, W, T...)(W size, T otherSizes)
{
  static if (T.length == 0)
    {
      E[] res;
      res.length = cast(size_t) size;
      return res;
    }
  else
    {
      typeof(makeSlice!E(otherSizes))[] res;
      res.length = cast(size_t) size;
      foreach(ref row; res)
        row = makeSlice!E(otherSizes);
      return res;
    }
}

void read(T...)(ref T t)
{
  void basicTypeRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  void iterableRead(W)(ref W w)
  {
    foreach(ref element; w)
      read(element);
  }
  void tupleRead(W)(ref W w)
  {
    static foreach(j; 0 .. W.length)
      read(w[j]);
  }
  void structRead(W)(ref W readStruct)
  {
    static foreach(fieldName; FieldNameTuple!W)
      {
        with(readStruct)
          {
            alias fieldSymbol = mixin(W.stringof, ".", fieldName);
            alias typeOfField = typeof(mixin(fieldName));
            static if (hasUDA!(fieldSymbol, If))
              enum condition = getUDAs!(fieldSymbol, If)[0].condition;
            else
              enum condition = "true";

            if (mixin(condition))
              {
                static if (hasUDA!(fieldSymbol, Dim))
                  {
                    static assert(isDynamicArray!(typeOfField)
                                  , text(W.stringof, ".", fieldName, " has Dim UDA but isn't a Dynamic Array."));
                    enum uda = getUDAs!(fieldSymbol, Dim)[0];
                    static assert(getArrayLevel!(typeOfField) == uda.levels,
                                  text(W.stringof, ".", fieldName, " has a Dim UDA with different number of dimensions than it's type."));
                    mixin(fieldName) = mixin(q{makeSlice!(baseType!typeOfField)(}, uda.dimensions, q{)});
                  }
                else static if (isDynamicArray!typeOfField && !is(typeOfField == string))
                  {
                    pragma(msg, "Warning: You probably want to add dimension to input ", W.stringof, ".", fieldName);
                  }
                read(mixin(fieldName));
              }
          }
      }
  }
  static foreach(i; 0 .. T.length)
    {
      static if (isBasicType!(T[i]) || is(T[i] == string))
        basicTypeRead(t[i]);
      else static if (is(typeof({foreach(ref e; t[i]){}})))
        iterableRead(t[i]);
      else static if (isTuple!(T[i]))
        tupleRead(t[i]);
      else static if (isAggregateType!(T[i]))
        structRead(t[i]);
    }
}

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

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

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

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

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

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

    }
}

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

template mem(alias F)
{
  ReturnType!F[Tuple!(Parameters!F)] table;
  ReturnType!F mem(Parameters!F args)
  {
    return table.require(tuple(args), F(args));
  }
}

string input(string names, string type = "long")
{
  return text(type, " ", names, "; read(", names, ");");
}

auto pmod(T, W)(T t, W w)
{
  return (t%w + w) % w;
}

void rep(S, F)(F f, S times)
{
  static if (is(typeof(f(i))))
    foreach(i; 0 .. times)
      f(i);
  else
    foreach(i; 0 .. times)
      f();
}

void multi()
{
  foreach(tc; 0 .. next!long)
    next!TestCase.solve(tc);
}

void single()
{
  auto tc = next!TestCase;
  tc.solve;
}

void main()
{
  type;
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		auto adj = new int [] [n];
		foreach (j; 0..m)
		{
			int u, v;
			readf !(" %s %s") (u, v);
			u -= 1;
			v -= 1;
			adj[u] ~= v;
			adj[v] ~= u;
		}

		auto vis = new bool [n];
		auto c = new int [n];
		c[] = -1;

		void recur (int v)
		{
			if (vis[v])
			{
				return;
			}
			vis[v] = true;
			if (c[v] == -1)
			{
				c[v] = 0;
				foreach (u; adj[v])
				{
					c[u] = 1;
				}
			}
			foreach (u; adj[v])
			{
				recur (u);
			}
		}

		recur (0);

		if (vis.all)
		{
			writeln ("YES");
			auto answer = n.iota.filter !(i => c[i] == 0).array;
			answer[] += 1;
			writeln (answer.length);
			writefln !("%(%s %)") (answer);
		}
		else
		{
			writeln ("NO");
		}
	}
}

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 int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		auto edges = new int[][](n);
		foreach (i; 0..m)
		{
			auto u = RD!int-1;
			auto v = RD!int-1;
			edges[u] ~= v;
			edges[v] ~= u;
		}

		int[] q = [0];
		auto state = new int[](n);
		auto used = new bool[](n);
		used[0] = true;
		while (!q.empty)
		{
			auto u = q.front; q.popFront;
			bool can = true;
			foreach (v; edges[u])
			{
				if (state[v] == 1)
				{
					can = false;
					break;
				}
			}
			if (can)
				state[u] = 1;
			else
				state[u] = 2;
			foreach (v; edges[u])
			{
				if (used[v]) continue;
				q ~= v;
				used[v] = true;
			}
		}
		foreach (i; 0..n)
		{
			if (state[i] == 0)
			{
				ans[ti].length = 0;
				break;
			}
			else if (state[i] == 1)
				ans[ti] ~= i+1;
		}
	}

	foreach (e; ans)
	{
		if (e.empty)
			writeln("NO");
		else
		{
			writeln("YES");
			writeln(e.length);
			e.map!(to!string).join(" ").writeln;
		}
	}
	stdout.flush;
	debug readln;
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		auto adj = new int [] [n];
		foreach (j; 0..m)
		{
			int u, v;
			readf !(" %s %s") (u, v);
			u -= 1;
			v -= 1;
			adj[u] ~= v;
			adj[v] ~= u;
		}

		auto c = new int [n];
		c[] = -1;

		void recur (int v, int cur)
		{
			if (c[v] >= 0)
			{
				return;
			}
			c[v] = cur;
			foreach (u; adj[v])
			{
				recur (u, !cur);
			}
		}

		recur (0, 0);
		debug {writeln (c);}

		if (c.any !(q{a == -1}))
		{
			writeln ("NO");
		}
		else
		{
			foreach (v; 0..n)
			{
				if (c[v] == 0)
				{
					foreach (u; adj[v])
					{
						if (c[u] == 0)
						{
							c[v] = 2;
						}
					}
				}
			}
			writeln ("YES");
			auto answer = n.iota.filter !(i => c[i] == 0).array;
			answer[] += 1;
			writeln (answer.length);
			writefln !("%(%s %)") (answer);
		}
	}
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		auto adj = new int [] [n];
		foreach (j; 0..m)
		{
			int u, v;
			readf !(" %s %s") (u, v);
			u -= 1;
			v -= 1;
			adj[u] ~= v;
			adj[v] ~= u;
		}

		auto c = new int [n];
		c[] = -1;

		void recur (int v, int cur)
		{
			if (c[v] >= 0)
			{
				return;
			}
			c[v] = cur;
			foreach (u; adj[v])
			{
				recur (u, !cur);
			}
			foreach (u; adj[v])
			{
				if (c[u] == 0)
				{
					c[v] = 2;
				}
			}
		}

		recur (0, 0);
		debug {writeln (c);}

		if (c.any !(q{a == -1}))
		{
			writeln ("NO");
		}
		else
		{
			writeln ("YES");
			auto answer = n.iota.filter !(i => c[i] == 0).array;
			answer[] += 1;
			writeln (answer.length);
			writefln !("%(%s %)") (answer);
		}
	}
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		auto adj = new int [] [n];
		foreach (j; 0..m)
		{
			int u, v;
			readf !(" %s %s") (u, v);
			u -= 1;
			v -= 1;
			adj[u] ~= v;
			adj[v] ~= u;
		}

		auto c = new int [n];
		c[] = -1;

		void recur (int v, int cur)
		{
			if (c[v] >= 0)
			{
				return;
			}
			c[v] = cur;
			foreach (u; adj[v])
			{
				recur (u, !cur);
			}
			foreach (u; adj[v])
			{
				if (c[v] == c[u])
				{
					c[v] = 2;
				}
			}
		}

		recur (0, 0);
		debug {writeln (c);}

		if (c.any !(q{a == -1}))
		{
			writeln ("NO");
		}
		else
		{
			writeln ("YES");
			auto answer = n.iota.filter !(i => c[i] == 0).array;
			answer[] += 1;
			writeln (answer.length);
			writefln !("%(%s %)") (answer);
		}
	}
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, m;
		readf !(" %s %s") (n, m);
		auto adj = new int [] [n];
		foreach (j; 0..m)
		{
			int u, v;
			readf !(" %s %s") (u, v);
			u -= 1;
			v -= 1;
			adj[u] ~= v;
			adj[v] ~= u;
		}

		auto c = new int [n];
		c[] = -1;

		void recur (int v, int cur)
		{
			if (c[v] >= 0)
			{
				return;
			}
			c[v] = cur;
			foreach (u; adj[v])
			{
				recur (u, !cur);
			}
			foreach (u; adj[v])
			{
				if (c[v] == c[u])
				{
					c[v] = 2;
				}
			}
		}

		recur (0, 0);

		if (c.any !(q{a == -1}))
		{
			writeln ("NO");
		}
		else
		{
			writeln ("YES");
			auto answer = n.iota.filter !(i => c[i] == 1).array;
			answer[] += 1;
			writeln (answer.length);
			writefln !("%(%s %)") (answer);
		}
	}
}

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 int[][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		auto edges = new int[][](n);
		foreach (i; 0..m)
		{
			auto u = RD!int-1;
			auto v = RD!int-1;
			edges[u] ~= v;
			edges[v] ~= u;
		}

		auto edges2 = new int[][](n);
		int[] q = [0];
		auto used = new bool[](n);
		used[0] = true;
		while (!q.empty)
		{
			auto u = q.front; q.popFront;
			foreach (v; edges[u])
			{
				if (used[v]) continue;
				edges2[u] ~= v;
				edges2[v] ~= u;
				q ~= v;
				used[v] = true;
			}
		}

		bool ok = true;
		foreach (i; 0..n)
		{
			if (!used[i])
			{
				ok = false;
				break;
			}
		}
		if (!ok) continue;

		void dfs(int pos, int last, int s)
		{
			if (s == 1)
				ans[ti] ~= pos+1;

			foreach (v; edges2[pos])
			{
				if (v == last) continue;
				dfs(v, pos, s^1);
			}
		}
		dfs(0, -1, 1);
	}

	foreach (e; ans)
	{
		if (e.empty)
			writeln("NO");
		else
		{
			writeln("YES");
			writeln(e.length);
			e.map!(to!string).join(" ").writeln;
		}
	}
	stdout.flush;
	debug readln;
}


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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto lo = new int [n];
		auto hi = new int [n];
		auto cost = new int [n];
		foreach (i; 0..n)
		{
			readf !(" %s %s %s") (lo[i], hi[i], cost[i]);
		}
		readln;

		auto f = tuple (int.max, -1);
		auto g = tuple (int.max, -1);
		auto h = tuple (int.max, int.max, -1);
		foreach (i; 0..n)
		{
			f = min (f, tuple (+lo[i], cost[i]));
			g = min (g, tuple (-hi[i], cost[i]));
			h = min (h, tuple (+lo[i], -hi[i], cost[i]));
			int res = f[1] + g[1];
			if (h[0] == f[0] && h[1] == g[0])
			{
				res = min (res, h[2]);
			}
			writeln (res);
		}
	}
}

import std.stdio;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

const bool dbg = true;
void DBG(alias x)() { static if (dbg) stderr.writefln("DBG: %s = %s", x.stringof, x); }
void MSG(in string x) { static if (dbg) stderr.writefln("MSG: %s", x); }

void solve() {
    int N = readln.chomp.to!int;
    long[] L = new long[N],
           R = new long[N],
           C = new long[N];
    long[Tuple!(long, long)] P;
    for (int i = 0; i < N; i++) {
        scanf("%lld %lld %lld\n", &L[i], &R[i], &C[i]);
    }
    long m = long.max, M = 0;
    long mc = long.max, Mc = long.max;
    for (int s = 0; s < N; s++) {
        auto key = tuple(L[s], R[s]);
        if (key in P) {
            P[key] = min(P[key], C[s]);
        } else {
            P[key] = C[s];
        }
        long ans = long.max;
        if (L[s] <= m) {
            mc = (L[s] == m ? min(mc, C[s]) : C[s]);
            m = L[s];
        }
        if (M <= R[s]) {
            Mc = (R[s] == M ? min(Mc, C[s]) : C[s]);
            M = R[s];
        }
        ans = min(ans, mc + Mc);
        if (tuple(m, M) in P) {
            ans = min(ans, P[tuple(m, M)]);
        }
        writeln(ans);
    }
}

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

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

string FMT_F = "%.10f";

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

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

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }
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 l = new long[](n);
		auto r = new long[](n);
		auto c = new long[](n);
		foreach (i; 0..n)
		{
			l[i] = RD;
			r[i] = RD;
			c[i] = RD;
		}

		int li, ri, xi;
		ans[ti] ~= c[0];
		foreach (i; 1..n)
		{
			if (l[i] == l[li])
			{
				if (c[i] < c[li])
					li = i;
			}
			else if (l[i] < l[li])
				li = i;

			if (r[i] == r[ri])
			{
				if (c[i] < c[ri])
					ri = i;
			}
			else if (r[i] > r[ri])
				ri = i;

			if (r[i] - l[i] == r[xi] - l[xi])
			{
				if (c[i] < c[xi])
					xi = i;
			}
			else if (r[i] - l[i] > r[xi] - l[xi])
				xi = i;

			debug writeln("li:", li, " ri:", ri, " xi:", xi);
			long tmp;
			if (r[xi] - l[xi] > r[ri] - l[li])
				tmp = c[xi];
			else if (r[xi] - l[xi] == r[ri] - l[li])
				tmp = min(c[xi], c[li] + c[ri]);
			else
				tmp = c[li] + c[ri];
			ans[ti] ~= tmp;
		}
	}

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

import std;

alias Segment = Tuple!(uint, "left", uint, "right", uint, "cost");

void main () {
    immutable tests = (){ uint t; readf!"%s\n"(t); return t; }();

    foreach (test_index; 0 .. tests) {
        immutable n = (){ uint n; readf!"%s\n"(n); return n; }();

        immutable Segment[] stock = (){
            Segment[] ret = new Segment[n];

            foreach (ref tup; ret)
                readf!"%s %s %s\n"(tup.expand);

            return ret.assumeUnique;
        }();

        enum cost = (size_t a, size_t b){
            if (a == b)
                return stock[a].cost;
            return stock[a].cost + stock[b].cost;
        };

        enum length = (size_t a, size_t b) {
            assert(stock[a].left <= stock[b].right);
            return stock[b].right - stock[a].left;
        };

        size_t cheapestLow, cheapestHigh;
        writeln(cost(0, 0));

        alias T = Tuple!(size_t, "smol", size_t, "big");
        T prev = T(0, 0);
        foreach (s; 1 .. n) {
            immutable now = stock[s];
            T[] options = [prev, T(s, s)];

            if (now.left <= stock[cheapestHigh].right)
                options ~= T(s, cheapestHigh);

            if (now.right >= stock[cheapestLow].left)
                options ~= T(cheapestLow, s);

            enum better = (T a, T b) {
                assert(stock[a.big].right >= stock[a.smol].left);
                assert(stock[b.big].right >= stock[b.smol].left);

                auto d1 = length(a.expand);
                auto d2 = length(b.expand);

                auto c1 = cost(a.expand);
                auto c2 = cost(b.expand);

                if (d1 != d2)
                    return d1 > d2;
                return c1 < c2;
            };

            auto ans = options.sort!((a, b) => better(a, b));

            //foreach (tup; ans)
                //writefln("[%1$s, %2$s] -> [%4$s, %5$s]", stock[tup.smol].expand, stock[tup.big].expand);

            assert(length(ans[0].expand) >= length(ans[1].expand));

            writeln(cost(ans[0].expand));

            prev = ans[0];

            if (now.left < stock[cheapestLow].left ||
                now.left == stock[cheapestLow].left && now.cost < stock[cheapestLow].cost)
                cheapestLow = s;

            if (now.right > stock[cheapestHigh].right ||
                now.right == stock[cheapestHigh].right && now.cost < stock[cheapestHigh].cost)
                cheapestHigh = s;
        }

    }
}
// ""

import std;

alias Segment = Tuple!(int, "left", int, "right", int, "cost");

void main () {
    immutable tests = (){ uint t; readf!"%s\n"(t); return t; }();

    foreach (test_index; 0 .. tests) {
        immutable n = (){ uint n; readf!"%s\n"(n); return n; }();

        immutable Segment[] inventory = (){
            Segment[] ret;
            ret.reserve(n);

            foreach (_; 0 .. n) {
                int left, right, cost;
                readf!"%s %s %s\n"(left, right, cost);
                ret ~= Segment(left, right, cost);
            }
            return ret.assumeUnique;
        }();

        enum cost = (size_t l, size_t r) {
            if (l != r)
                return inventory[l].cost + inventory[r].cost;
            else
                return inventory[l].cost;
        };

        alias T = Tuple!(size_t, "small", size_t, "big");
        auto prev = T(0, 0);

        writeln(cost(0, 0));
        foreach (s; 1 .. n) {
            T[] options = [
                T(s, prev.big),
                T(prev.small, s),
                T(s, s),
                prev
            ];

            enum better = (T a, T b) {
                auto d1 = inventory[a.big].right - inventory[a.small].left;
                auto d2 = inventory[b.big].right - inventory[b.small].left;

                auto c1 = cost(a.expand);
                auto c2 = cost(b.expand);

                if (d1 != d2)
                    return d1 > d2;
                return c1 < c2;
            };

            auto best = options.sort!((a, b) => better(a, b));

            writeln(cost(best.front.expand));
            prev = best.front;
        }

    }
}
// ""

import std;

alias Segment = Tuple!(uint, "left", uint, "right", uint, "cost");

void main () {
    immutable tests = (){ uint t; readf!"%s\n"(t); return t; }();

    foreach (test_index; 0 .. tests) {
        immutable n = (){ uint n; readf!"%s\n"(n); return n; }();

        immutable Segment[] inventory = (){
            Segment[] ret;
            ret.reserve(n);

            foreach (_; 0 .. n) {
                uint left, right, cost;
                readf!"%s %s %s\n"(left, right, cost);
                ret ~= Segment(left, right, cost);
            }
            return ret.assumeUnique;
        }();

        enum cost = (size_t l, size_t r) {
            if (l != r)
                return inventory[l].cost + inventory[r].cost;
            else
                return inventory[l].cost;
        };

        alias T = Tuple!(size_t, "small", size_t, "big");
        auto prev = T(0, 0);

        writeln(cost(0, 0));
        foreach (s; 1 .. n) {
            T now = prev;

            if (inventory[s].left < inventory[prev.small].left)
                now.small = s;

            if (inventory[s].right > inventory[prev.small].right)
                now.big = s;

            if (inventory[s].left == inventory[now.small].left && cost(s, now.big) < cost(now.expand))
                now.small = s;

            if (inventory[s].right == inventory[now.big].right && cost(s, now.small) < cost(now.expand))
                now.big = s;

            writeln(cost(now.expand));
            prev = now;
        }

    }
}
// ""

import std;

alias Segment = Tuple!(uint, "left", uint, "right", uint, "cost");

void main () {
    immutable tests = (){ uint t; readf!"%s\n"(t); return t; }();

    foreach (test_index; 0 .. tests) {
        immutable n = (){ uint n; readf!"%s\n"(n); return n; }();

        immutable Segment[] inventory = (){
            Segment[] ret;
            ret.reserve(n);

            foreach (_; 0 .. n) {
                uint left, right, cost;
                readf!"%s %s %s\n"(left, right, cost);
                ret ~= Segment(left, right, cost);
            }
            return ret.assumeUnique;
        }();

        enum cost = (size_t l, size_t r) {
            if (l != r)
                return inventory[l].cost + inventory[r].cost;
            else
                return inventory[l].cost;
        };

        size_t left = 0, right = 0;
        writeln(cost(left, right));
        size_t biggest, smallest;

        foreach (s; 1 .. n) {
            if (inventory[s].left < inventory[smallest].left)
                smallest = s;
            if (inventory[s].right > inventory[biggest].right)
                biggest = s;

            if (inventory[s].left < inventory[left].left)
                left = s;
            if (inventory[s].right > inventory[right].right)
                right = s;

            immutable v1 = inventory[s].right - inventory[s].left;
            immutable v2 = inventory[right].right - inventory[left].left;

            if (v1 > v2 ||
                v1 == v2 && cost(s, s) < cost(left, right)) {
                immutable q = inventory[s].right - inventory[smallest].left;
                immutable r = inventory[biggest].right - inventory[s].left;

                if (q > r || q == r && cost(s, smallest) < cost(s, biggest))
                    left = smallest, right = s;
                else
                    right = biggest, left = s;
            }

            writeln(cost(left, right));
        }
    }
}
// ""

import std.stdio;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

const bool dbg = true;
void DBG(alias x)() { static if (dbg) stderr.writefln("DBG: %s = %s", x.stringof, x); }
void MSG(in string x) { static if (dbg) stderr.writefln("MSG: %s", x); }

void solve() {
    int N = readln.chomp.to!int;
    long[] L = new long[N],
           R = new long[N],
           C = new long[N];
    long[Tuple!(long, long)] P;
    for (int i = 0; i < N; i++) {
        scanf("%lld %lld %lld\n", &L[i], &R[i], &C[i]);
    }
    long m = long.max, M = 0;
    long mc = long.max, Mc = long.max;
    for (int s = 0; s < N; s++) {
        P[tuple(L[s], R[s])] = C[s];
        long ans = long.max;
        if (L[s] <= m) {
            mc = (L[s] == m ? min(mc, C[s]) : C[s]);
            m = L[s];
        }
        if (M <= R[s]) {
            Mc = (R[s] == M ? min(Mc, C[s]) : C[s]);
            M = R[s];
        }
        ans = min(ans, mc + Mc);
        if (tuple(m, M) in P) {
            ans = min(ans, P[tuple(m, M)]);
        }
        writeln(ans);
    }
}

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


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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto k = RD!int;
		auto a = RD!string;
		auto b = RD!string;
		auto aa = new int[](26);
		auto bb = new int[](26);
		foreach (i; 0..n)
		{
			++aa[a[i]-'a'];
			++bb[b[i]-'a'];
		}
		auto c = new int[](26);
		foreach (i; 0..26)
		{
			c[i] = aa[i] - bb[i];
		}
		bool ok = true;
		foreach (i; 0..25)
		{
			if (c[i] < 0)
			{
				ok = false;
				break;
			}
			else if (c[i] % k)
			{
				ok = false;
				break;
			}
			else
			{
				c[i+1] += c[i];
			}
		}
		if (c[$-1] != 0)
			ok = false;
		ans[ti] = ok;
	}

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

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

// Main Logic Here
void play(){
    long[27] cmap = 0;
    auto n = rd!int;
    auto k = rd!int;
    dchar[] s1 = rd!(dchar[]);
    dchar[] s2 = rd!(dchar[]);
    foreach(dchar c; s1){ int z = to!int(c - 'a'); ++cmap[z+1]; }
    foreach(dchar c; s2){ int z = to!int(c - 'a'); --cmap[z+1]; }
    show(cmap);
    foreach(int i; 1..27){
        if(cmap[i] > 0 && cmap[i] % k == 0){
            foreach(int j; i+1..27){
                if(cmap[j] < 0 && (-cmap[j]) % k == 0){
                    ll take = min(cmap[i], -cmap[j]);
                    cmap[i] -= take;
                    cmap[j] += take;
                }
            }
        }
    }
    show(cmap);
    foreach(i; 1..27){
        if(cmap[i] != 0){
            writeln("No");
            return;
        }
    }
    writeln("Yes");
}

int main(){
    long t = 1;
    t = rd;        // Toggle for testcases!
    while(t--) play();  // Let's play!
    return 0;
}

/**********That's All Folks!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;    // Read input
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
alias ll = long;
alias tup = Tuple!(long, "x",  long, "y");
void show(A...)(A a) { debug{ foreach(t; a){ stderr.write(t, "| "); } stderr.writeln; } } // Debug
/* Add if TLE, T max(T = long)(T a, T b){ return (a > b) ? a : 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(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 string[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto s = RD!string;
		foreach (i; 0..n)
		{
			ans[ti] ~= s[$/2];
		}
	}

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

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

void main() {
    int t = readln.chomp.to!int;
    while(t--) {
        int n = readln.chomp.to!int;
        string s = readln.strip;

        char[] ans;

        foreach(_; 0..n)
            ans ~= s[n-1];

        ans.writeln;
    }
}

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

void main ()
{
	foreach (test; 0..readln.strip.to !(int))
	{
		readln;
		readln.strip.stride (2).writeln;
	}
}

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

void main() {
    int t = readln.chomp.to!int;
    while(t--) {
        int n = readln.chomp.to!int;
        string s = readln.strip;

        char[] ans;

        foreach(_; 0..n-1)
            ans ~= '1';

        ans ~= s[n-1];
        ans.writeln;
    }
}


import std.stdio;

void main()
{
  float h, l;
  readf!"%f %f\n"(h, l);

  writef!"%.6f\n"((l^^2 - h^^2) / (2*h));
}

//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(){
    double h,l;
    readf!"%f %f"(h,l);
    readln;
    writefln!"%.13f"(l^^2/(2*h)-0.5*h);
}

import std.stdio, std.math;

void main() {
    long h, l;
    readf(" %s %s", h, l);
    auto result = (cast(float)(l*l - h*h)) / (2 * h);
    writef("%.9s", result);
}

//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(){
    double h,l;
    readf!"%f %f"(h,l);
    readln;
    writefln!"%.13f"(l^^2/(2*h)-0.5);
}


import std.stdio;
import std.algorithm;

void main() {
	int n;
	int[] a;
	int temp;

	readf(" %s %s", &n, &temp);

	a ~= temp;
	int max = temp;

	int idx = 0;
	foreach (i; 1 .. n) {
		readf(" %s", &temp);
		a ~= temp;
		if (temp > max) {
			max = temp;
			idx = i;
		}
	}

	a[idx] = (a[idx] == 1) ? 2 : 1;

	writefln("%(%s %)", sort(a));
}

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; scanf("%d\n", &N);
    auto xs = readln.chomp.split(" ").map!(to!int).array;
    xs.sort;

    auto ys = new int[N];
    if (xs.all!"a == 1") {
        ys[] = 1;
        ys.back = 2;
    } else {
        ys[0] = 1;
        for (int i = 1; i < N; i++) {
            ys[i] = xs[i - 1];
        }
    }
    writefln("%(%s %)", ys);
}

import std.stdio
    , std.typecons
    , std.traits
    , std.algorithm
    , std.range
    , std.container;

void main() {
    const len = {
        uint t;
        readf("%s\n", &t);
        return t;
    }();

    uint[] data = new uint[len];

    auto mymax = tuple(0, 0);
    foreach(idx, ref i; data) {
        readf("%s ", &i);
        if(i > mymax[1]) { mymax[1] = i; mymax[0] = idx; }
    }

    if(mymax[1] != 1) {
        data[mymax[0]] = 1;
    }
    else
    {
        data[mymax[0]] = 2;
    }

    /*data.sort()
    .y!((auto ref arr){
        foreach(ref a; arr) {
            write(a, " ");
        }
    });
    */

    (auto ref arr){
        foreach(ref a; arr) {
            write(a, " ");
        }
    }
    ( data.sort() );
}

alias y(alias clos) = clos;

alias var(alias elem) = std.traits.Unqual!(typeof(elem));

auto mut(T)(auto ref T in_val) {
    std.traits.Unqual!(T) rv = in_val;
    return rv;
}

auto imut(T)(auto ref T in_val) {
    immutable immrv = in_val;
    return immrv;
}

import std.stdio;
import std.algorithm;

void main() {
	int n;
	int[] a;
	int temp;

	readf(" %s %s", &n, &temp);

	a ~= temp;
	int max = temp;

	int idx = 0;
	foreach (i; 1 .. n) {
		readf(" %s", &temp);
		a ~= temp;
		if (temp > max) {
			max = temp;
			idx = i;
		}
	}

	(a[idx] == 1) ? a[idx] = 2 : a[idx] = 1;

	writefln("%(%s %)", sort(a));
}

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; scanf("%d\n", &N);
    auto xs = readln.chomp.split(" ").map!(to!int).array;
    xs.sort;

    auto ys = new int[N];
    ys[0] = 1;
    for (int i = 1; i < N; i++) {
        ys[i] = xs[i - 1];
    }
    writefln("%(%s %)", ys);
}

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; scanf("%d\n", &N);
    auto xs = readln.chomp.split(" ").map!(to!int).array;
    xs.sort;

    auto ys = new int[N];
    if (N == 1 && xs[0] == 1) {
        writeln(2);
        return;
    }
    ys[0] = 1;
    for (int i = 1; i < N; i++) {
        ys[i] = xs[i - 1];
    }
    writefln("%(%s %)", ys);
}


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

void main()
{
    int n, a, b;
    readf ("%s %s %s", &n, &a, &b);
    readln;
    b = min (b, n);

    Tuple!(long, long) [] arr;
    foreach ( _; 0..n ) {
        auto r = readln.splitter.map! (to!long).array;
        arr ~= tuple(r[0], r[1]);
    }

    arr.sort! (q{ a[0] - a[1] > b[0] - b[1] });

    debug { writeln (arr); }

    auto valUseB = (Tuple!(long, long) e) => max (e[0], e[1]);

    auto ansNoA = arr
        .enumerate
        .map! (t => t.index < b ? valUseB (t.value) : t.value[1])
        .sum;

    if (b == 0) {
        writeln (ansNoA);
        return;
    }

    auto smallestGainOnB = valUseB (arr[b-1]) - arr[b-1][1];
    auto valUseAB = (Tuple!(long, long) e) => max (e[0] * 2^^a, e[1]);
    auto gainOnA = (ulong i, Tuple!(long, long) e) => valUseAB (e) - (i < b ? valUseB (e) : e[1] + smallestGainOnB);
    auto ans = ansNoA + arr.enumerate.map! (t => gainOnA (t.index, t.value)).maxElement;

    debug { writeln (ansNoA, ' ', arr.enumerate.map! (t => gainOnA (t.index, t.value))); }
    writeln (ans);
}

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;

immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto A = s[1];
    auto B = s[2];
    auto H = new long[](N);
    auto D = new long[](N);
    foreach (i; 0..N) {
        auto t = readln.split.map!(to!long);
        H[i] = t[0];
        D[i] = t[1];
    }

    auto S = D.sum;
    auto DD = new long[](N);
    foreach (i; 0..N) DD[i] = max(0L, H[i] - D[i]);
    DD.sort!"a > b"();
    auto DDS = DD[0..min(N, B)].sum;
    long ans = 0;

    if (A == 0) {
        writeln(S + DDS);
        return;
    }

    if (B == 0) {
        writeln(S);
        return;
    }

    foreach (i; 0..N) {
        long tmp = (H[i] << A) + S - D[i] + DDS;
        long dd = max(0L, H[i] - D[i]);
        if (B >= N || dd > DD[B]) {
            tmp = tmp - dd;
        } else {
            tmp = tmp - DD[B-1];
        }
        ans = max(ans, tmp);
    }

    ans.writeln;
}

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

void main()
{
    int n, a, b;
    readf ("%s %s %s", &n, &a, &b);
    readln;
    b = min (b, n);

    long [][] arr;
    foreach ( _; 0..n ) arr ~= readln.splitter.map! (to!long).array;

    arr.sort! (q{ a[0] - a[1] > b[0] - b[1] });

    debug { writeln (arr); }

    auto valUseB = (long[] e) => max (e[0], e[1]);

    auto ansNoA = arr
        .enumerate
        .map! (t => t.index < b ? valUseB (t.value) : t.value[1])
        .sum;

    if (b == 0) {
        writeln (ansNoA);
        return;
    }

    auto smallestGainOnB = valUseB (arr[b-1]) - arr[b-1][1];
    auto valUseAB = (long[] e) => max (e[0] * 2^^a, e[1]);
    auto gainOnA = (ulong i, long[] e) => valUseAB (e) - (i < b ? valUseB (e) : e[1] + smallestGainOnB);
    auto ans = ansNoA + arr.enumerate.map! (t => gainOnA (t.index, t.value)).maxElement;

    debug { writeln (ansNoA, ' ', arr.enumerate.map! (t => gainOnA (t.index, t.value))); }
    writeln (ans);
}

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;

immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto A = s[1];
    auto B = s[2];
    auto H = new long[](N);
    auto D = new long[](N);
    foreach (i; 0..N) {
        auto t = readln.split.map!(to!long);
        H[i] = t[0];
        D[i] = t[1];
    }

    auto S = D.sum;
    auto DD = new long[](N);
    foreach (i; 0..N) DD[i] = max(0L, H[i] - D[i]);
    DD.sort!"a > b"();
    auto DDS = DD[0..min(N, B)].sum;
    long ans = 0;

    if (A == 0) {
        writeln(S + DDS);
        return;
    }

    foreach (i; 0..N) {
        long tmp = (H[i] << A) + S - D[i] + DDS;
        long dd = max(0L, H[i] - D[i]);
        if (B >= N) {
            tmp -= dd;
        } else if (dd > DD[B]) {
            tmp = tmp - dd + DD[B];
        }
        ans = max(ans, tmp);
    }

    ans.writeln;
}

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

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

    long [][] arr;
    foreach (_; 0..n) arr ~= readln.splitter.map!(to!long).array;

    debug { writeln (arr); }

    long mult = 2 ^^ a;
    auto gainMult = (long[] x) => x[0] * mult - x[1];
    int mxind = cast(int) arr.map!(a => gainMult(a)).maxIndex;
    arr[mxind][0] *= mult;

    debug { writeln (mxind, ' ', arr[mxind][0]); }

    auto gain = (long[] x) => x[0] - x[1];
    long[] gains = arr.map!(x => gain(x)).array;
    debug { writeln (arr, ' ', gains); }
    auto ans = arr.map!(q{ a[1] }).sum(0L) +
        gains
        .sort!(q{ a > b })
        .until!(q{ a <= 0 })
        .take(b)
        .sum(0L);

    writeln (ans);
}

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

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

    long [][] arr;
    foreach (_; 0..n) arr ~= readln.splitter.map! (to!long).array;

    debug { writeln (arr); }

    auto gain = (long[] x) => x[0] * 2^^a - x[1];
    auto powerUpOrder = arr.sort! ((a, b) => gain (a) > gain (b));

    debug { writeln (powerUpOrder); }

    auto ans =
        arr.map! (q{ a[1] }).sum
        + powerUpOrder
            .take (b)
            .map! (x => gain (x))
            .until! (q{ a <= 0 })
            .sum;

    writeln (ans);
}

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

void main()
{
    int n, a, b;
    readf ("%s %s %s", &n, &a, &b);
    readln;
    b = min (b, n);

    long [][] arr;
    foreach ( _; 0..n ) arr ~= readln.splitter.map! (to!long).array;

    arr.sort! (q{ a[0] - a[1] > b[0] - b[1] });

    debug { writeln (arr); }

    auto valUseB = (long[] e) => max (e[0], e[1]);

    auto ansNoA = arr
        .enumerate
        .map! (t => t.index < b ? valUseB (t.value) : t.value[1])
        .sum;

    if (b == 0) {
        writeln (ansNoA);
        return;
    }

    auto smallestGainOnB = valUseB (arr[b-1]) - arr[b-1][1];
    auto valUseAB = (long[] e) => max (e[0] * 2^^a, e[1]);
    auto gainOnA = (ulong i, long[] e) => valUseAB (e) - valUseB (e) - (i < b ? 0 : smallestGainOnB);
    auto ans = ansNoA + arr.enumerate.map! (t => gainOnA (t.index, t.value)).maxElement;

    debug { writeln (ansNoA, ' ', arr.enumerate.map! (t => gainOnA (t.index, t.value))); }
    writeln (ans);
}

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

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

    long [][] arr;
    foreach (_; 0..n) arr ~= readln.splitter.map!(to!long).array;

    long ans = arr.map!(q{ a[1] }).sum;

    debug { writeln (arr, ' ', ans); }

    int mult = 2 ^^ a;
    auto gainMult = (long[] x) => x[0] * mult - x[1];
    int mxind = cast(int) arr.map!(a => gainMult(a)).maxIndex;
    arr[mxind][0] *= mult;

    debug { writeln (mxind, ' ', arr[mxind][0]); }

    auto gain = (long[] x) => x[0] - x[1];
    long[] gains = arr.map!(x => gain(x)).array;
    ans += gains
        .sort!(q{ a > b })
        .until!(q{ a <= 0 })
        .take(b)
        .sum;

    writeln (ans);
}

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

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

    long [][] arr;
    foreach (_; 0..n) arr ~= readln.splitter.map!(to!long).array;

    long ans = arr.map!(q{ a[1] }).sum;

    debug { writeln (arr, ' ', ans); }

    long mult = 2 ^^ a;
    auto gainMult = (long[] x) => x[0] * mult - x[1];
    int mxind = cast(int) arr.map!(a => gainMult(a)).maxIndex;
    arr[mxind][0] *= mult;

    debug { writeln (mxind, ' ', arr[mxind][0]); }

    auto gain = (long[] x) => x[0] - x[1];
    long[] gains = arr.map!(x => gain(x)).array;
    ans += gains
        .sort!(q{ a > b })
        .until!(q{ a <= 0 })
        .take(b)
        .sum;

    writeln (ans);
}


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

//	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, const T f) { if (t > f) t = f; }
void chmax(T)(ref T t, const T f) { if (t < f) t = f; }

//	Pair
struct Pair(S, T) {
	S x; T y;
	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)(S x, T y) { return Pair!(S, T)(x, y); }

//	Array
int binarySearch(T)(T[] as, 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)(T[] as, T val) { return as.binarySearch((T a) { return (a <  val); }); }
int upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }
T[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }

bool check(long n, long a, long b, long c) {
	long x = min(a, b, c);
	a -= x;
	b -= x;
	c -= x;
	long rem = n - a - b - c;
	return (rem >= 0 && rem % 3 == 0);
}

bool solve(long N, long K, long D1, long D2) {
	foreach (s; [ +1, -1 ]) foreach (t; [ +1, -1 ]) {
		if (check(K, D1 * s, 0, D2 * t) && check(N - K, D1 * -s, 0, D2 * -t)) {
			return true;
		}
	}
	return false;
}

void main(string[] args) {
	// try {
	for (int TC = readInt; TC--; ) {
		long N = readLong;
		long K = readLong;
		long D1 = readLong;
		long D2 = readLong;
		bool res = solve(N, K, D1, D2);
		writeln(res ? "yes" : "no");
	}
	// } catch (EOFException) {}
}

module main;

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

int check(long n, long k, long d1, long d2)
{
    long tmp = d1 * 2 + d2 + k;
    if (tmp < 0 || tmp % 3 != 0)
    {
        return 0;
    }
    long x = tmp / 3;
    tmp = k + d2 - d1;
    if (tmp < 0 || tmp % 3 != 0)
    {
        return 0;
    }
    long y = tmp / 3;
    tmp = k - d1 - d2 * 2;
    if (tmp < 0 || tmp % 3 != 0)
    {
        return 0;
    }
    long z = tmp / 3;
    long left = n - k;
    auto p = [x, y, z];
    sort(p);
    long need = p[2] - p[0] + p[2] - p[1];
    if (need > left)
    {
        return 0;
    }
    left -= need;
    if (left % 3 == 0)
    {
        writeln("yes");
        return 1;
    }
    return 0;
}

void solve(long n, long k, long d1, long d2)
{
    if (check(n, k, d1, d2)) return;
    if (check(n, k, -d1, d2)) return;
    if (check(n, k, d1, -d2)) return;
    if (check(n, k, -d1, -d2)) return;
    writeln("no");
}

int main(string[] args)
{
    int t;
    while (scanf("%d", &t) == 1)
    {
        foreach (i; 0 .. t)
        {
            long n, k, d1, d2;
            scanf("%lld%lld%lld%lld", &n, &k, &d1, &d2);
            solve(n, k, d1, d2);
        }
    }
    return 0;
}

module main;

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

int check(long n, long k, long d1, long d2)
{
    long tmp = d1 * 2 + d2 + k;
    if (tmp < 0 || tmp % 3 != 0)
    {
        return 0;
    }
    long x = tmp / 3;
    tmp = k + d2 - d1;
    if (tmp < 0 || tmp % 3 != 0)
    {
        return 0;
    }
    long y = tmp / 3;
    tmp = k - d1 - d2 * 2;
    if (tmp < 0 || tmp % 3 != 0)
    {
        return 0;
    }
    long z = tmp / 3;
    //writeln(x, " ", y, " ", z);
    long left = n - k;
    auto p = [x, y, z];
    sort(p);
    long need = p[2] - p[0] + p[2] - p[1];
    if (need > left)
    {
        return 0;
    }
    left -= need;
    if (left % 3 == 0)
    {
        writeln("yes");
        return 1;
    }
    return 0;
}

void solve(long n, long k, long d1, long d2)
{
    if (check(n, k, d1, d2)) return;
    if (check(n, k, -d1, d2)) return;
    if (check(n, k, d1, -d2)) return;
    if (check(n, k, -d1, -d2)) return;
    writeln("no");
}

int main(string[] args)
{
    int t;
    while (scanf("%d", &t) == 1)
    {
        foreach (i; 0 .. t)
        {
            long n, k, d1, d2;
            scanf("%d%d%d%d", &n, &k, &d1, &d2);
            solve(n, k, d1, d2);
        }
    }
    return 0;
}

module main;

import std.stdio, std.string;

void solve(long n, long k, long d1, long d2)
{
    long cnt = d1 + d1 + d2;
    long left = n - k;
    if (cnt > left)
    {
        writeln("no");
    }
    else
    {
        left -= cnt;
        if (left % 3 == 0)
        {
            writeln("yes");
        }
        else
        {
            writeln("no");
        }
    }
}

int main(string[] args)
{
    int t;
    while (scanf("%d", &t) == 1)
    {
        foreach (i; 0 .. t)
        {
            long n, k, d1, d2;
            scanf("%d%d%d%d", &n, &k, &d1, &d2);
            solve(n, k, d1, d2);
        }
    }
    return 0;
}


immutable multi = false;

void solve(int tc)
{
	int[] testArray = null;
	auto n = testArray is null? readInt!int : cast(int)testArray.length;
	auto k = testArray is null? readInt!int : 1;
	auto or = new int[](n-1);
	auto nd = new int[](n-1);
	auto ans = new int[](n);
	int query(string op, int i, int j)
	{
		if (testArray is null)
		{
			writeln(op, " ", i, " ", j);
			stdout.flush;
			return readInt!int;
		}
		else
		{
			switch(op)
			{
			case "or":
				return testArray[i-1] | testArray[j-1];
			case "and":
				return testArray[i-1] & testArray[j-1];
			default: assert(0);
			}
		}
	}
	auto or23 = query("or", 2, 3);
	foreach(i; 1 .. n)
	{
		or[i-1] = query("or", 1, i + 1);
		nd[i-1] = query("and", 1, i + 1);
	}
	auto andedOrs = or.fold!((a, b) => a & b);
	auto oredAns = nd.fold!((a, b) => a | b);
	void solveBit(int q)
	{
		if (andedOrs&(1<<q))
		{
			if (oredAns&(1<<q))
			{
				// we are sure a1 at q = 1
				ans[0] |= (1<<q);
				foreach(i; 1 .. n)
				{
					ans[i] |= nd[i-1]&(1<<q);
				}
				return;
			}
			// either 0 1 1 ... or 1 0 0 ...
			// check or23
			if (or23&(1<<q))
			{
				// 0 1 1...
				foreach(i; 1 .. n)
					ans[i] |= (1<<q);
			}
			else
			{
				// 1 0 0...
				ans[0] |= (1<<q);
			}
		}
		else
		{
			// we are sure a1 at q = 0
			foreach(i; 1 .. n)
			{
				ans[i] |= or[i-1]&(1<<q);
			}
			return;
		}
	}
	foreach(b; 0 .. 31)
		solveBit(b);
	if (testArray !is null)
	{
		writeln(testArray);
		writeln(ans);
	}
	sort(ans);
	writeln("finish ", ans[k-1]);
	stdout.flush;
}
//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

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

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

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

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

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

long query(int type, int idx1, int idx2)
{
  if (type == 0) {
    writefln("or %d %d", idx1, idx2);
    stdout.flush();
    return readln.strip.to!long;
  } else {
    writefln("and %d %d", idx1, idx2);
    stdout.flush();
    return readln.strip.to!long;
  }
}

/* 1-bit bruteforce version */

long recover_a1(long orab, long andab, long orbc, long andbc, long andac, long orac)
{
  long ans;
  long cnt;
  foreach (a ; 0 .. 2) {
    foreach (b ; 0 .. 2) {
      foreach (c ; 0 .. 2) {
        if (andbc == (b & c) && orbc == (b | c) && andab == (a & b) && orab == (a | b) && andac == (a & c) && orac == (a | c)) {
          ans = a;
          cnt++;
        }
      }
    }
  }
  assert(cnt == 1);
  return ans;
}

/*
 * We know: A | B, A & B, B | C, B & C, A | C, A & C
 * Need to recover and return a 32-bit value A.
 */

long recover_a32(long orab, long andab, long orbc, long andbc, long andac, long orac)
{
  long ans;
  foreach (b ; 0 .. 32) {
    ans |= recover_a1((orab >> b) & 1, (andab >> b) & 1, (orbc >> b) & 1, (andbc >> b) & 1, (andac >> b) & 1, (orac >> b) & 1) << b;
  }
  return ans;
}

void main()
{
  int n, k;
  readln.formattedRead!" %d %d "(n, k);
  long[] a_xor, a_or, a_and;

  foreach (i ; 0 .. n - 1) {
    int idx1 = (i + 0) % n + 1;
    int idx2 = (i + 1) % n + 1;
    long qor = query(0, idx1, idx2);
    long qand = query(1, idx1, idx2);
    a_or ~= qor;
    a_and ~= qand;
    a_xor ~= (qor - qand);
  }

  long orab = a_or[0];
  long andab = a_and[0];
  long orbc = a_or[1];
  long andbc = a_and[1];
  long orac = query(0, 1, 3);
  long andac = query(1, 1, 3);
  long a0 = recover_a32(orab, andab, orbc, andbc, andac, orac);
  long[] ans = [a0];
  foreach (i ; 1 .. n) {
    ans ~= ans[i - 1] ^ a_xor[i - 1];
  }
  ans.sort;
  writefln("finish %d", ans[k - 1]);
}

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

int ask (string op) (int a, int b)
{
	writeln (op, " ", a + 1, " ", b + 1);
	stdout.flush ();
	return readln.strip.to !(int);
}

void main ()
{
	int n, k;
	while (readf !(" %s %s") (n, k) > 0)
	{
		k -= 1;
		readln;

		int [3] [3] or;
		int [3] [3] and;
		static foreach (s; AliasSeq !("or", "and"))
		{
			foreach (i; 0..3)
			{
				foreach (j; i + 1..3)
				{
					mixin (format !(`%s[i][j] = ` ~
					    `ask !("%s") (i, j);`) (s, s));
				}
			}
		}

		bool checkBit (int [3] bits)
		{
			foreach (i; 0..3)
			{
				foreach (j; i + 1..3)
				{
					if ((bits[i] | bits[j]) !=
					    (or[i][j] & 1))
					{
						return false;
					}
					if ((bits[i] & bits[j]) !=
					    (and[i][j] & 1))
					{
						return false;
					}
				}
			}
			return true;
		}

		auto a = new int [n];

bits_loop:
		foreach (b; 0..30)
		{
			scope (exit)
			{
				static foreach (s; AliasSeq !("or", "and"))
				{
					foreach (i; 0..3)
					{
						foreach (j; i + 1..3)
						{
							mixin (format
							    !(`%s[i][j] ` ~
							    `>>= 1;`) (s));
						}
					}
				}
			}

			foreach (x; 0..2)
			{
				foreach (y; 0..2)
				{
					foreach (z; 0..2)
					{
						if (checkBit ([x, y, z]))
						{
							a[0] |= x << b;
							a[1] |= y << b;
							a[2] |= z << b;
							continue bits_loop;
						}
					}
				}
			}

			assert (false);
		}
		debug {writeln (a);}

		foreach (i; 3..n)
		{
			auto theOr = ask !("or") (0, i);
			auto theAnd = ask !("and") (0, i);
			a[i] = theAnd | (theOr & ~a[0]);
			debug {writeln (a);}
		}

		sort (a);
		writeln ("finish", " ", a[k]);
		stdout.flush ();
	}
}

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;

long query(int type, int idx1, int idx2)
{
  if (type == 0) {
    writefln("or %d %d", idx1, idx2);
    stdout.flush();
    return readln.strip.to!long;
  } else {
    writefln("and %d %d", idx1, idx2);
    stdout.flush();
    return readln.strip.to!long;
  }
}

long recover_a1(long orab, long andab, long orbc, long andbc, long andac, long orac)
{
  long ans;
  long cnt;
  foreach (a ; 0 .. 2) {
    foreach (b ; 0 .. 2) {
      foreach (c ; 0 .. 2) {
        if (andbc == (b & c) && orbc == (b | c) && andab == (a & b) && orab == (a | b) && andac == (a & c) && orac == (a | c)) {
          ans = a;
          cnt++;
        }
      }
    }
  }
  assert(cnt == 1);
  return ans;
}

long recover_a32(long orab, long andab, long orbc, long andbc, long andac, long orac)
{
  long ans;
  foreach (b ; 0 .. 32) {
    ans |= recover_a1((orab >> b) & 1, (andab >> b) & 1, (orbc >> b) & 1, (andbc >> b) & 1, (andac >> b) & 1, (orac >> b) & 1) << b;
  }
  return ans;
}

void main()
{
  int n, k;
  readln.formattedRead!" %d %d "(n, k);
  long[] a_xor, a_or, a_and;

  foreach (i ; 0 .. n - 1) {
    int idx1 = (i + 0) % n + 1;
    int idx2 = (i + 1) % n + 1;
    long qor = query(0, idx1, idx2);
    long qand = query(1, idx1, idx2);
    a_or ~= qor;
    a_and ~= qand;
    a_xor ~= (qor - qand);
  }

  long orab = a_or[0];
  long andab = a_and[0];
  long orbc = a_or[1];
  long andbc = a_and[1];
  long orac = query(0, 1, 3);
  long andac = query(1, 1, 3);
  long a0 = recover_a32(orab, andab, orbc, andbc, andac, orac);
  long[] ans = [a0];
  foreach (i ; 1 .. n) {
    ans ~= ans[i - 1] ^ a_xor[i - 1];
  }
  ans.sort;
  writefln("finish %d", ans[k - 1]);
}

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

int main(string[] args)
{
    int n, k;
    readf("%d %d\n", &n, &k);
    auto r = new int[][][](3, 3, 2);
    foreach (i; 1 .. 4) foreach (j; i + 1 .. 4)
    {
        writeln("or ", i, " ", j);
        stdout.flush;
        r[i - 1][j - 1][0] = to!int(readln.strip);
        if (i == 1 && j == 3) continue;
        writeln("and ", i, " ", j);
        stdout.flush;
        r[i - 1][j - 1][1] = to!int(readln.strip);
    }
    auto a = new int[n];
    foreach (i; 0 .. 30)
    {
        if (r[0][1][1] & (1 << i))
        {
            a[0] |= 1 << i;
            continue;
        }
        if (!(r[0][1][0] & (1 << i)) || !(r[0][2][0] & (1 << i))) continue;
        if (!(r[1][2][1] & (1 << i))) a[0] |= 1 << i;
    }
    foreach (i; 1 .. 3) foreach (j; 0 .. 30)
    {
        if (r[i - 1][i][1] & (1 << j)) a[i] |= 1 << j;
        else if ((r[i - 1][i][0] & (1 << j)) && !(a[i - 1] & (1 << j))) a[i] |= 1 << j;
    }
    foreach (i; 3 .. n)
    {
        writeln("or ", i, " ", i + 1);
        stdout.flush;
        auto ro = to!int(readln.strip);
        writeln("and ", i, " ", i + 1);
        stdout.flush;
        auto ra = to!int(readln.strip);
        foreach (j; 0 .. 30)
        {
            if (ra & (1 << j)) a[i] |= 1 << j;
            else if ((ro & (1 << j)) && !(a[i - 1] & (1 << j))) a[i] |= 1 << j;
        }
    }
    a.sort;
    writeln("finish ", a[k - 1]);
    stdout.flush;
    return 0;
}

immutable multi = false;

void solve(int tc)
{
	int[] testArray = null;
	auto n = testArray is null? readInt!int : cast(int)testArray.length;
	auto k = testArray is null? readInt!int : 1;
	auto or = new int[](n-1);
	auto nd = new int[](n-1);
	auto ans = new int[](n);
	int query(string op, int i, int j)
	{
		if (testArray is null)
		{
			writeln(op, " ", i, " ", j);
			stdout.flush;
			return readInt!int;
		}
		else
		{
			switch(op)
			{
			case "or":
				return testArray[i-1] | testArray[j-1];
			case "and":
				return testArray[i-1] & testArray[j-1];
			default: assert(0);
			}
		}
	}
	auto or23 = query("or", 2, 3);
	foreach(i; 1 .. n)
	{
		or[i-1] = query("or", 1, i + 1);
		nd[i-1] = query("and", 1, i + 1);
	}
	auto andedOrs = or.fold!((a, b) => a & b);
	auto oredAns = nd.fold!((a, b) => a | b);
	void solveBit(int q)
	{
		if (andedOrs&(1<<q))
		{
			if (oredAns&(1<<q))
			{
				// we are sure a1 at q = 1
				ans[0] |= (1<<q);
				foreach(i; 1 .. n)
				{
					ans[i] |= nd[i-1]&(1<<q);
				}
				return;
			}
			// either 0 1 1 ... or 1 0 0 ...
			// check or23
			if (or23&(1<<q))
			{
				// 0 1 1...
				foreach(i; 1 .. n)
					ans[i] |= (1<<q);
			}
			else
			{
				// 1 0 0...
				ans[0] |= (1<<q);
			}
		}
		else
		{
			// we are sure a1 at q = 0
			foreach(i; 1 .. n)
			{
				ans[i] |= or[i-1]&(1<<q);
			}
			return;
		}
	}
	foreach(b; 0 .. 21)
		solveBit(b);
	if (testArray !is null)
	{
		writeln(testArray);
		writeln(ans);
	}
	sort(ans);
	writeln("finish ", ans[k-1]);
	stdout.flush;
}
//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

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

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

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

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

immutable multi = false;

void solve(int tc)
{
	int[] testArray = null;
	auto n = testArray is null? readInt!int : cast(int)testArray.length;
	auto k = testArray is null? readInt!int : 1;
	auto or = new int[](n-1);
	auto nd = new int[](n-1);
	auto ans = new int[](n);
	int query(string op, int i, int j)
	{
		if (testArray is null)
		{
			writeln(op, " ", i, " ", j);
			stdout.flush;
			return readInt!int;
		}
		else
		{
			switch(op)
			{
			case "or":
				return testArray[i-1] | testArray[j-1];
			case "and":
				return testArray[i-1] & testArray[j-1];
			default: assert(0);
			}
		}
	}
	auto or23 = query("or", 2, 3);
	foreach(i; 1 .. n)
	{
		or[i-1] = query("or", 1, i + 1);
		nd[i-1] = query("and", 1, i + 1);
	}
	auto andedOrs = or.fold!((a, b) => a & b);
	auto oredAns = nd.fold!((a, b) => a | b);
	void solveBit(int q)
	{
		if (andedOrs&(1<<q))
		{
			if (oredAns&(1<<q))
			{
				// we are sure a1 at q = 1
				ans[0] |= (1<<q);
				foreach(i; 1 .. n)
				{
					ans[i] |= nd[i-1]&(1<<q);
				}
				return;
			}
			// either 0 1 1 ... or 1 0 0 ...
			// check or23
			if (or23&(1<<q))
			{
				// 0 1 1...
				foreach(i; 1 .. n)
					ans[i] |= (1<<q);
			}
			else
			{
				// 1 0 0...
				ans[0] |= (1<<q);
			}
		}
		else
		{
			// we are sure a1 at q = 0
			foreach(i; 1 .. n)
			{
				ans[i] |= or[i-1]&(1<<q);
			}
			return;
		}
	}
	foreach(b; 0 .. 21)
		solveBit(b);
	if (testArray !is null)
	{
		writeln(testArray);
		writeln(ans);
	}
	sort(ans);
	ans[k-1].writeln;
}
//{{{
void main()
{
	auto t = multi? readInt!int : 1;
	foreach(tc; 0 .. t) solve(tc);
}
//}}}
// input {{{
int currChar;
static this()
{
	currChar = ' ';
}

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

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

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

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

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

long query(int type, int idx1, int idx2)
{
  if (type == 0) {
    writefln("or %d %d", idx1, idx2);
    stdout.flush();
    return readln.strip.to!long;
  } else {
    writefln("and %d %d", idx1, idx2);
    stdout.flush();
    return readln.strip.to!long;
  }
}

long recover_a1(long orab, long andab, long orbc, long andbc, long andac, long orac)
{
  long ans;
  long cnt;
  foreach (a ; 0 .. 2) {
    foreach (b ; 0 .. 2) {
      foreach (c ; 0 .. 2) {
        if (andbc == (b & c) && orbc == (b | c) && andab == (a & b) && orab == (a | b) && andac == (a & c) && orac == (a | c)) {
          ans = a;
          cnt++;
        }
      }
    }
  }
  assert(cnt == 1);
  return ans;
}

long recover_a32(long orab, long andab, long orbc, long andbc, long andac, long orac)
{
  long ans;
  foreach (b ; 0 .. 32) {
    ans |= recover_a1((orab >> b) & 1, (andab >> b) & 1, (orbc >> b) & 1, (andbc >> b) & 1, (andac >> b) & 1, (orac >> b) & 1) << b;
  }
  return ans;
}

void main()
{
  int n, k;
  readln.formattedRead!" %d %d "(n, k);
  long[] a_xor, a_or, a_and;

  foreach (i ; 0 .. n - 1) {
    int idx1 = (i + 0) % n + 1;
    int idx2 = (i + 1) % n + 1;
    long qor = query(0, idx1, idx2);
    long qand = query(1, idx1, idx2);
    a_or ~= qor;
    a_and ~= qand;
    a_xor ~= (qor - qand);
  }

  long orab = a_or[0];
  long andab = a_and[0];
  long orbc = a_or[1];
  long andbc = a_and[1];
  long orac = query(0, 1, 3);
  long andac = query(1, 1, 3);
  long a0 = recover_a32(orab, andab, orbc, andbc, andac, orac);
  long[] ans = [a0];
  foreach (i ; 1 .. n) {
    ans ~= ans[i - 1] ^ a_xor[i - 1];
  }
  writeln(ans[k - 1]);
}