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

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		auto a = new int [n];
		foreach (ref x; a)
		{
			readf (" %s", &x);
		}

		int res = int.min;
		foreach (lo; 0..n)
		{
			foreach (hi; lo + 1..n + 1)
			{
				auto b = a[0..lo].dup;
				b ~= a[hi..n];
				sort !("a > b", SwapStrategy.stable) (b);
				auto c = a[lo..hi].dup;
				sort !("a < b", SwapStrategy.stable) (c);
				int cur = 0;
				foreach (i; 0..k)
				{
					if (!b.length ||
					    !c.length ||
					    b[0] <= c[0])
					{
						break;
					}
					cur += b[0];
					b = b[1..$];
					c = c[1..$];
                                }
                                foreach (d; c)
                                {
                                	cur += d;
                                }
                                res = max (res, cur);
			}
		}
		writeln (res);
	}
}

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

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

//	chmin/chmax
void chmin(T)(ref T t, 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; }

int N, K;
int[] A;

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

		int ans = int.min;

		foreach (i; 0 .. N) foreach (j; i + 1 .. N + 1) {
			int[] xs, ys;
			foreach (k; 0 .. N) {
				((i <= k && k < j) ? xs : ys) ~= A[k];
			}
			xs.sort!"a < b";
			ys.sort!"a > b";
			int now = xs.reduce!"a + b";
			chmax(ans, now);
			foreach (l; 0 .. K) if (l < xs.length && l < ys.length) {
				now -= xs[l];
				now += ys[l];
				chmax(ans, now);
			}
		}

		writeln(ans);

	}
	} catch (EOFException) {}
}


import std.algorithm, std.conv, std.stdio, std.string, std.typecons;
bool c (T) (T a, T b) {return b == "" || tuple (a.length, a) < tuple (b.length, b);}
void r (T) (ref T a, T b) {if (c (b, a)) a = b;}
string [3] [256] f;
void main () {
	f[0b00001111][2] = "x";
	f[0b00110011][2] = "y";
	f[0b01010101][2] = "z";
	foreach (step; 0..4)
		foreach (s; 0..256) foreach (sp; 0..3) if (f[s][sp]) {
			if (sp > 1) r (f[s ^ 255][2], "!" ~ f[s][sp]);
			r (f[s][2], "(" ~ f[s][sp] ~ ")");
			foreach (t; 0..256) foreach (tp; 0..3) if (f[t][tp]) {
				if (min (sp, tp)) r (f[s & t][1], f[s][sp] ~ "&" ~ f[t][tp]);
				r (f[s | t][0], f[s][sp] ~ "|" ~ f[t][tp]);
			}
		}
	foreach (i; 0..readln.strip.to!int) f[readln.strip.to!int (2)][].minElement!c.writeln;
}

import std.algorithm, std.conv, std.stdio, std.string;
struct Answer {
	string contents; alias contents this;
	int opCmp () (const auto ref Answer that) const {
		if ((this == "") != (that == "")) return (this == "") - (that == "");
		if (this.length != that.length) return cast (int) (this.length - that.length);
		return (this.contents > that.contents) - (this.contents < that.contents);
	}
}
Answer [3] [256] fun;
void relax (ref Answer a, Answer b) {if (a > b) a = b;}
void main () {
	fun[0b00001111][2] = "x";
	fun[0b00110011][2] = "y";
	fun[0b01010101][2] = "z";
	foreach (step; 0..4)
		foreach (s; 0..256) foreach (sp; 0..3) {
			string sc = fun[s][sp];
			if (sc == "") continue;
			if (sp >= 2) relax (fun[s ^ 255][2], Answer ("!" ~ sc));
			if (sp >= 0) relax (fun[s][2], Answer ("(" ~ sc ~ ")"));
			foreach (t; 0..256) foreach (tp; 0..3) {
				string tc = fun[t][tp];
				if (tc == "") continue;
				if (sp >= 1 && tp >= 1) relax (fun[s & t][1], Answer (sc ~ "&" ~ tc));
				if (sp >= 0 && tp >= 0) relax (fun[s | t][0], Answer (sc ~ "|" ~ tc));
			}
		}
	foreach (i; 0..readln.strip.to !(int)) fun[readln.strip.to!int (2)][].minElement.writeln;
}

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

immutable int logLogLimit = 3;
immutable int logLimit = 1 << logLogLimit;
immutable int limit = 1 << logLimit;
immutable int prios = 3;

struct Answer
{
	string contents;
	alias contents this;

	int opCmp () (const auto ref Answer that) const
	{
		if ((that == "") != (this == ""))
		{
			return (this == "") - (that == "");
		}
		if (that.length != this.length)
		{
			return cast (int) (this.length) -
			    cast (int) (that.length);
		}
		return (that.contents < this.contents) -
		    (this.contents < that.contents);
	}
}

unittest
{
	auto a = Answer ("x");
	auto b = Answer ("y");
	auto c = Answer ("!!y");
	auto d = Answer ("(x)");
	auto e = Answer ("");
	assert (a < b);
	assert (b < c);
	assert (c < d);
	assert (d < e);
}

Answer [prios] [limit] fun;

void relax (ref Answer a, Answer b)
{
	if (a > b)
	{
		a = b;
	}
}

void main ()
{
	fun[0b00001111][2] = "x";
	fun[0b00110011][2] = "y";
	fun[0b01010101][2] = "z";
	Answer [prios] [limit] funPrev;
	do
	{
		funPrev = fun;
		debug {writeln (fun);}
		foreach (s; 0..limit)
		{
			foreach (sp; 0..3)
			{
				string sc = fun[s][sp];
				if (sc == "")
				{
					continue;
				}

				if (sp >= 2)
				{
					auto r = s ^ (limit - 1);
					auto next = Answer ("!" ~ sc);
					relax (fun[r][2], next);
				}

				if (sp >= 0)
				{
					auto r = s;
					auto next = Answer ("(" ~ sc ~ ")");
					relax (fun[r][2], next);
				}

				foreach (t; 0..limit)
				{
					foreach (tp; 0..3)
					{
						string tc = fun[t][tp];
						if (tc == "")
						{
							continue;
						}

						if (sp >= 1 && tp >= 1)
						{
							auto r = s & t;
							auto next = Answer (sc ~ "&" ~ tc);
							relax (fun[r][1], next);
						}

						if (sp >= 0 && tp >= 0)
						{
							auto r = s | t;
							auto next = Answer (sc ~ "|" ~ tc);
							relax (fun[r][0], next);
						}
					}
				}
			}
		}
	}
	while (funPrev != fun);
	debug {writeln (fun);}

	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		foreach (i; 0..n)
		{
			auto x = readln.strip.to !(int) (2);
			debug {writeln (fun[x]);}
			writeln (fun[x][].minElement);
		}
	}
}

import std.algorithm, std.conv, std.stdio, std.string;
alias c = (a, b) => b == "" || (a.length != b.length ? a.length < b.length : a < b);
alias r = (ref a, b) {if (c (b, a)) a = b;};
string [3] [256] f;
void main () {
	f[15][2] = "x";	f[51][2] = "y";	f[85][2] = "z";
	foreach (t; 0..4) foreach (u; 0..256) foreach (p; 0..3) if (f[u][p]) {
			if (p > 1) r (f[u ^ 255][2], "!" ~ f[u][p]);
			r (f[u][2], "(" ~ f[u][p] ~ ")");
			foreach (v; 0..256) foreach (q; 0..3) if (f[v][q]) {
				if (min (p, q)) r (f[u & v][1], f[u][p] ~ "&" ~ f[v][q]);
				r (f[u | v][0], f[u][p] ~ "|" ~ f[v][q]);
			}
		}
	foreach (i; 0..readln.strip.to!int) f[readln.strip.to!int (2)][].minElement!c.writeln;
}

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

immutable int x = 0b00001111;
immutable int y = 0b00110011;
immutable int z = 0b01010101;
immutable int nx = 0b11110000;
immutable int ny = 0b11001100;
immutable int nz = 0b10101010;
string[] func;

int not(int a) {
    return 0b11111111 ^ a;
}

int p_and(string s) {
    return s[0] != '(' && s.canFind("|");
}

void main() {
    func = new string[](256);
    func.fill("");
    func[x] = "x";
    func[y] = "y";
    func[z] = "z";
    func[nx] = "!x";
    func[ny] = "!y";
    func[nz] = "!z";

    int[string] d;
    d["x"] = x;
    d["y"] = y;
    d["z"] = z;
    d["!x"] = nx;
    d["!y"] = ny;
    d["!z"] = nz;

    int cnt = 6;
    for (int i = 3; cnt < 256; ++i) {
        foreach (str; d.keys) {
            auto term = d[str];
            int len = str.length.to!int;

            if (len!= 1 && len == i-3) {
                int next = not(term);
                string next_str = "!(" ~ str ~ ")";
                if (func[next] == "" || func[next].length > i) {
                    func[next] = next_str;
                } else if (func[next].length == i && func[next] > next_str) {
                    func[next] = next_str;
                }
            }

            foreach (str2; d.keys) {
                if (str == str2) continue;
                if (str.length + str2.length + 1 != i) continue;
                int next = term | d[str2];
                string next_str1 = str ~ "|" ~ str2;
                string next_str2 = str2 ~ "|" ~ str;
                string next_str = min(next_str1, next_str2);
                if (func[next] == "" || func[next].length > i) {
                    func[next] = next_str;
                } else if (func[next].length == i && func[next] > next_str) {
                    func[next] = next_str;
                }
            }

            string str1 = str;
            if (p_and(str)) str1 = "(" ~ str ~ ")";

            foreach (str2; d.keys) {
                string str3 = str2;
                if (str == str2) continue;
                if (p_and(str2)) str3 = "(" ~ str2 ~ ")";
                if (str1.length + str3.length + 1 != i) continue;

                int next = term & d[str2];
                string next_str1 = str1 ~ "&" ~ str3;
                string next_str2 = str3 ~ "&" ~ str1;
                string next_str = min(next_str1, next_str2);
                if (func[next] == "" || func[next].length > i) {
                    func[next] = next_str;
                } else if (func[next].length == i && func[next] > next_str) {
                    func[next] = next_str;
                }
            }

        }

        foreach (j; 0..256) {
            if (func[j].length == i && func[j] != "") {
                cnt += 1;
                d[func[j]] = j;
            }
        }
    }

    string[string] hoge;
    foreach (i; 0..256) {
        hoge[format("%08b", i)] = func[i];
    }

    auto N = readln.chomp.to!int;
    foreach (i; 0..N) {
        auto s = readln.chomp;
        writeln(hoge[s]);
    }
}

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;

immutable int x = 0b00001111;
immutable int y = 0b00110011;
immutable int z = 0b01010101;
immutable int nx = 0b11110000;
immutable int ny = 0b11001100;
immutable int nz = 0b10101010;
string[] func;

int not(int a) {
    return 0b11111111 ^ a;
}

int p_and(string s) {
    return s[0] != '(' && s.canFind("|");
}

void main() {
    func = new string[](256);
    func.fill("");
    func[x] = "x";
    func[y] = "y";
    func[z] = "z";
    func[nx] = "!x";
    func[ny] = "!y";
    func[nz] = "!z";

    int[string] d;
    d["x"] = x;
    d["y"] = y;
    d["z"] = z;
    d["!x"] = nx;
    d["!y"] = ny;
    d["!z"] = nz;

    int cnt = 6;
    for (int i = 3; cnt < 256; ++i) {
        foreach (str; d.keys) {
            auto term = d[str];
            int len = str.length.to!int;

            if (len!= 1 && len == i-3) {
                int next = not(term);
                string next_str = "!(" ~ str ~ ")";
                if (func[next] == "" || func[next].length > i) {
                    func[next] = next_str;
                } else if (func[next].length == i && func[next] > next_str) {
                    func[next] = next_str;
                }
            }

            foreach (str2; d.keys) {
                if (str == str2) continue;
                if (str.length + str2.length + 1 != i) continue;
                int next = term | d[str2];
                string next_str1 = str ~ "|" ~ str2;
                string next_str2 = str2 ~ "|" ~ str;
                string next_str = min(next_str1, next_str2);
                if (func[next] == "" || func[next].length > i) {
                    func[next] = next_str;
                } else if (func[next].length == i && func[next] > next_str) {
                    func[next] = next_str;
                }
            }

            string str1 = str;
            if (p_and(str)) str1 = "(" ~ str ~ ")";

            foreach (str2; d.keys) {
                string str3 = str2;
                if (str == str2) continue;
                if (p_and(str2)) str3 = "(" ~ str2 ~ ")";
                if (str1.length + str3.length + 1 != i) continue;

                int next = term & d[str2];
                string next_str1 = str1 ~ "&" ~ str3;
                string next_str2 = str3 ~ "&" ~ str1;
                string next_str = min(next_str1, next_str2);
                if (next_str == "!x&") writeln(str1, " ", str3, " ", str, " ", str2);
                if (func[next] == "" || func[next].length > i) {
                    func[next] = next_str;
                } else if (func[next].length == i && func[next] > next_str) {
                    func[next] = next_str;
                }
            }

        }

        foreach (j; 0..256) {
            if (func[j].length == i && func[j] != "") {
                cnt += 1;
                d[func[j]] = j;
            }
        }
    }

    string[string] hoge;
    foreach (i; 0..256) {
        hoge[format("%08b", i)] = func[i];
    }

    auto N = readln.chomp.to!int;
    foreach (i; 0..N) {
        auto s = readln.chomp;
        writeln(hoge[s]);
    }
}

import std.algorithm, std.conv, std.stdio, std.string;
struct Answer {
	string contents; alias contents this;
	int opCmp () (const auto ref Answer that) const {
		if ((this == "") != (that == "")) return (this == "") - (that == "");
		if (this.length != that.length) return cast (int) (this.length - that.length);
		return (this.contents > that.contents) - (this.contents < that.contents);
	}
}
Answer [3] [256] fun;
void relax (ref Answer a, Answer b) {if (a > b) a = b;}
void main () {
	fun[0b00001111][2] = "x";
	fun[0b00110011][2] = "y";
	fun[0b01010101][2] = "z";
	foreach (step; 0..3)
		foreach (s; 0..256) foreach (sp; 0..3) {
			string sc = fun[s][sp];
			if (sc == "") continue;
			if (sp >= 2) relax (fun[s ^ 255][2], Answer ("!" ~ sc));
			if (sp >= 0) relax (fun[s][2], Answer ("(" ~ sc ~ ")"));
			foreach (t; 0..256) foreach (tp; 0..3) {
				string tc = fun[t][tp];
				if (tc == "") continue;
				if (sp >= 1 && tp >= 1) relax (fun[s & t][1], Answer (sc ~ "&" ~ tc));
				if (sp >= 0 && tp >= 0) relax (fun[s | t][1], Answer (sc ~ "|" ~ tc));
			}
		}
	foreach (i; 0..readln.strip.to !(int)) fun[readln.strip.to!int (2)][].minElement.writeln;
}


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

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

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

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

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const N = readInt();
        auto A = new int[N];
        foreach (i; 0 .. N) {
          A[i] = readInt();
        }

        foreach (i; 0 .. N) {
          if (i > 0) write(" ");
          write((-1)^^(i & 1) * abs(A[i]));
        }
        writeln;
      }
    }
  } catch (EOFException e) {
  }
}

import std.algorithm;
import std.conv;
import std.math;
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 !(long)).array;
		foreach (i, ref c; a)
		{
			c = abs (c);
			if (i % 2 == 0)
			{
				c = -c;
			}
		}
		writefln !("%(%s %)") (a);
	}
}

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;

		ans[ti].length = n;
		foreach (i; 0..n)
		{
			if (i % 2)
				ans[ti][i] = abs(a[i]);
			else
				ans[ti][i] = -abs(a[i]);
		}
	}

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

import std.algorithm;
import std.conv;
import std.math;
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;
		foreach (i, ref c; a)
		{
			c = abs (c);
			if (i > 0 && (i % 4 < 2) == (a[i] >= a[i - 1]))
			{
				c = -c;
			}
		}
		writefln !("%(%s %)") (a);
	}
}


immutable multi = true;

int[10] tenPow;
static this()
{
  tenPow[0] = 1;
  foreach(i; 1 .. 10)
    tenPow[i] = 10 * tenPow[i-1];
}

void solve(int tc)
{
  auto x1 = readInt!int,
    p1 = readInt!int,
    x2 = readInt!int,
    p2 = readInt!int;

  int getPot(int x)
  {
    int ans = 0;
    while (x)
      {
	ans++;
	x /= 10;
      }
    return ans;
  }
  int pot1 = getPot(x1) + p1, pot2 = getPot(x2) + p2;
  if (pot1 > pot2) return writeln(">");
  if (pot2 > pot1) return writeln("<");
  auto mnp = min(p1, p2);
  p1 -= mnp;
  p2 -= mnp;
  x1 *= tenPow[p1];
  x2 *= tenPow[p2];
  if (x1 < x2) return writeln("<");
  if (x1 > x2) return writeln(">");
  return writeln("=");
}

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

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

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

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

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

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

void solve(){
    double x1 = scan!double;
    long p1 = scan;
    double x2 = scan!double;
    long p2 = scan;
    while(x1 >= 10){
       x1 /= 10;
       ++p1;
    }
    while(x2 >= 10){
       x2 /= 10;
       ++p2;
    }
    if(p1 > p2 || (p1 == p2 && x1 > x2)){
        writeln(">");
    }else if(p2 > p1 || (p1 == p2 && x1 < x2)){
        writeln("<");
    }else{
        writeln("=");
    }
}

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

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

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

long numdigits(long x)
{
  long ans;
  while (x > 0) {
    ans++;
    x /= 10;
  }
  return ans;
}

string cmp(T)(T x1, T x2)
{
  if (x1 == x2)
    return "=";
  else if (x1 < x2)
    return "<";
  else
    return ">";
}

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    long x1, p1, x2, p2;
    readf!" %d %d %d %d "(x1, p1, x2, p2);
    p1 += numdigits(x1);
    p2 += numdigits(x2);
    if (p1 == p2) {
      string s1 = x1.to!string;
      string s2 = x2.to!string;
      while (s1.length < s2.length)
        s1 ~= "0";
      while (s2.length < s1.length)
        s2 ~= "0";
      writeln(cmp(s1, s2));
    } else if (p1 < p2) {
      writeln("<");
    } else {
      writeln(">");
    }
  }
}


import std.stdio;
void main()
{
    int n;
    readf(" %s", &n);

    for(int i = 0; i < n; i++){
        long a, b, c;
        readf(" %s %s %s", &a, &b, &c);
        long total = (a + b + c) / 2;
        writeln(total);
    }
}

import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric;
import std.typecons, std.functional, std.traits;
import std.algorithm, std.container;
import core.stdc.stdlib, core.bitop;

void main()
{
    auto N = scanElem;
    foreach(i;0..N)
    {
        auto list = [scanElem, scanElem, scanElem];
        sort(list);
        auto a = list[0];
        auto b = list[1];
        auto diff = list[1] - list[0];
        if(diff>list[2]){
            writeln(diff-list[2]/2+a);
        }else{
            writeln((list[2]-diff)/2+b);
        }
    }
}

bool isInf(long v) pure
{
    return v>=INF;
}
enum INF = long.max/5;
enum MOD=10^^9+7L;

struct ModInt(alias Mod = MOD)
if(isIntegral!(typeof(Mod)) && isPrime(Mod))
{
    long value;

    this(ModInt!Mod v)
    {
        value = v.value;
    }
    this(long v)
    {
        value = (v%Mod+Mod)%Mod;
    }

    private static ModInt!Mod inv(ModInt!Mod v) pure
    {
        ModInt res=1;
        long p = Mod-2;
        while(p!=0)
        {
            if(p&1)res *= v;
            v *= v;
            p >>= 1;
        }
        return res;
    }

    ModInt!Mod opBinaryRight(string op, T)(T v) const
    if((op=="+"||op=="-"||op=="*")&&isIntegral!T)
    {
        return ModInt!Mod(mixin("v"~op~"value"));
    }
    ModInt!Mod opBinary(string op, T)(T v) const
    if((op=="+"||op=="-"||op=="*")&&(is(T==ModInt!Mod)||isIntegral!T))
    {
        return ModInt!Mod(mixin("value"~op~"v"));
    }

    ModInt!Mod opBinaryRight(string op, T)(T v) const
    if((op=="/")&&isIntegral!T)
    {
        return v * inv(this);
    }
    ModInt!Mod opBinary(string op, T)(T v) const
    if((op=="/")&&(is(T==ModInt!Mod)||isIntegral!T))
    {
        return this * inv(ModInt(v));
    }

    void opAssign(T)(T v)
    if(isIntegral!T)
    {
        this = ModInt!Mod(v);
    }

    void opOpAssign(string op, T)(T v)
    {
        this = mixin("this"~op~"v");
    }

    bool opEquals(T)(const T v) const
    if(is(T==ModInt!Mod)||isIntegral!T)
    {
        return value == ModInt(v).value;
    }

    long opCast() const {
        return value;
    }

    string toString() const {
        return value.to!string;
    }
}
@safe pure unittest
{
    assert(is(ModInt!()));
    assert(is(ModInt!17));
    assert(!is(ModInt!0));
    assert(!is(ModInt!10));

    assert(is(ModInt!()==ModInt!(MOD)));
}
@safe pure unittest
{
    alias MInt = ModInt!13;
    assert(MInt.inv(MInt(4))==10);
    assert(MInt.inv(MInt(6))==11);
    assert(MInt.inv(MInt(12))==12);
}
@safe pure unittest
{
    alias MInt = ModInt!13;
    MInt value;
    value = MInt(14) + MInt(18);
    assert(value==6);
    value = 14 - MInt(28);
    assert(value==12);
    value = MInt(17) * -19;
    assert(value==2);

    value = MInt(7) / 4;
    assert(value==5);
    value = 8 / MInt(4);
    assert(value==2);
    value = 9;
    value /= 4;
    assert(value==12);

    value = 29-MInt(16);
    assert(value==0);
    value = MInt(13)*5;
    assert(value==0);
    value = 0;
    assert(value==0);

    value = 3;
    value += MInt(11);
    assert(value==1);
    value -= 7;
    assert(value==7);
    value *= MInt(4);
    assert(value==2);
    value = 23;
    assert(value == cast(long)value);
}
@safe pure unittest
{
    ModInt!() value;
    value = MOD-1;
    assert(value==MOD-1);
    value = MOD;
    assert(value==0);
}

struct Grid(T){
    private T[] grid;
    size_t width, height;
    private size_t stride;

    private this(T[] g, size_t w, size_t h, size_t s)
    {
        grid = g;
        width = w;
        height = h;
        stride = s;
    }

    this(size_t w, size_t h)
    {
        this(new T[w*h], w, h, w);
    }

    void setRow(InputRange)(size_t y, InputRange range)
    if(isInputRange!InputRange && is(typeof(grid.front=range.front)))
    {
        foreach(x; 0..width)
        {
            assert(!range.empty);
            this[x, y] = range.front;
            range.popFront;
        }
    }

    void setCol(InputRange)(size_t x, InputRange range)
    if(isInputRange!InputRange && is(typeof(T.init=range.front)))
    {
        foreach(y; 0..height)
        {
            assert(!range.empty);
            this[x, y] = range.front;
            range.popFront;
        }
    }

    Grid!T copy(){
        if(width == stride){
            return Grid!T(grid.dup, width, height, stride);
        }

        auto res = Grid!T(width, height);
        foreach(y;0..height)
        foreach(x;0..width)
        {
            res[x, y] = this[x, y];
        }
        return res;
    }

    ref T opIndex(size_t x, size_t y)
    {
        return grid[x+stride*y];
    }
    ref T opIndex(E)(E e)
        if(
            isIntegral!(typeof(e.x)) &&
            isIntegral!(typeof(e.y)))
    {
        return this[e.x, e.y];
    }

    Grid!T opIndex(size_t[2] r1, size_t[2] r2)
    {
        auto startOffset = r1[0] + r2[0]*stride;
        auto endOffset = r1[1] + (r2[1] - 1)*stride;

        auto resGrid = grid[startOffset .. endOffset];
        auto resStride = stride;
        auto resWidth = r1[1] - r1[0];
        auto resHeight = r2[1] - r2[0];
        return Grid!T(resGrid, resWidth, resHeight, resStride);
    }

    Grid!T opIndex(size_t[2] r1, size_t j) { return opIndex(r1, [j, j+1]); }
    Grid!T opIndex(size_t i, size_t[2] r2) { return opIndex([i, i+1], r2); }

    size_t[2] opSlice(size_t dim)(size_t start, size_t end)
    if (dim == 0 || dim == 1)
    // in { assert(start >= 0 && end <= this.opDollar!dim); }
    body{
        return [start, end];
    }

    size_t opDollar(size_t dim : 0)() const { return width; }
    size_t opDollar(size_t dim : 1)() const { return height; }

    string toString() {
        string res = "\n";
        foreach(y; 0..height)
        {
            foreach(x; 0..width)
            {
                string joinStr = this[x, y].to!string ~ " ";
                static if(is(T==long))
                {
                    if(this[x,y]>=INF)
                    {
                        joinStr = "* ";
                    }
                }
                res ~= joinStr;
            }
            res ~= '\n';
        }
        return res;
    }
}

struct Data2{
    long x,y;
    alias a=x, b=y;
    ref long opIndex(size_t i)
    {
        assert(i==0||i==1);
        return i==0?x:y;
    }
}
struct Data3{
    long x,y,z;
    alias a=x, b=y, c=z;
    ref long opIndex(size_t i)
    {
        assert(i==0||i==1||i==2);
        return i==0?x:(i==1?y:z);
    }
}

long lcm(long a, long b) pure
{
    return a * b / gcd(a, b);
}

class UnionFind{
    UnionFind parent = null;

    void merge(UnionFind a)
    {
        if(same(a)) return;
        a.root.parent = this.root;
    }
    UnionFind root()
    {
        if(parent is null)return this;
        return parent = parent.root;
    }
    bool same(UnionFind a)
    {
        return this.root == a.root;
    }
}

enum TermColor{
    Blue,
    Red,
    Purple,
    Gray,
    Green,
    Brown,
    Default,
}

string termStr(TermColor c) pure
{
    switch(c)
    {
        case TermColor.Blue:   return "\033[38;2;122;158;194m";
        case TermColor.Red:    return "\033[38;2;204;130;66m";
        case TermColor.Purple: return "\033[38;2;158;123;176m";
        case TermColor.Gray:   return "\033[38;2;106;135;89m";
        case TermColor.Green:  return "\033[38;2;165;194;97m";
        case TermColor.Brown:  return "\033[38;2;204;130;66m";
        default: return "\033[0m";
    }
}

void print(TermColor C = TermColor.Gray, T...)(T t)
{
    debug stderr.write(C.termStr, t, TermColor.Default.termStr);
}
void printf(TermColor C = TermColor.Gray, T...)(T t)
{
    debug stderr.write(C.termStr);
    debug stderr.writef(t);
    debug stderr.write(TermColor.Default.termStr);
}
void println(TermColor C = TermColor.Gray, T...)(T t)
{
    debug stderr.writeln(C.termStr, t, TermColor.Default.termStr);
}
void printfln(TermColor C = TermColor.Gray, T...)(T t)
{
    debug stderr.write(C.termStr);
    debug stderr.writefln(t);
    debug stderr.write(TermColor.Default.termStr);
}

// debug{
//     void write(T...)(T t)
//     {
//         stdout.write(TermColor.Blue.termStr, t, TermColor.Default.termStr);
//     }
//     void writeln(T...)(T t)
//     {
//         stdout.writeln(TermColor.Blue.termStr, t, TermColor.Default.termStr);
//     }
//     void writefln(T...)(T t)
//     {
//         stdout.writefln(TermColor.Blue.termStr, t, TermColor.Default.termStr);
//     }
// }

T[] scanArray(T = long)()
{
    return readln.split.to!(T[]);
}

char scanChar()
{
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(char)c;
}
T scanElem(T = long)()
{
    char[] res;
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        res ~= cast(char) c;
        c = getchar;
    }
    return res.strip.to!T;
}

alias scanString = scanElem!string;

template fold(fun...) if (fun.length >= 1)
{
    auto fold(R, S...)(R r, S seed)
    {
        static if (S.length < 2)
        {
            return reduce!fun(seed, r);
        }
        else
        {
            import std.typecons : tuple;

            return reduce!fun(tuple(seed), r);
        }
    }
}

struct Factor
{
    long n;
    long c;
}

//素因数分解
Factor[] factors(long n) pure
{
    Factor[] res;
    for (long i = 2; i ^^ 2 <= n; i++)
    {
        if (n % i != 0)
            continue;

        long c;
        while (n % i == 0)
        {
            n = n / i;
            c++;
        }
        res ~= Factor(i, c);
    }
    if (n != 1)
        res ~= Factor(n, 1);

    return res;
}
//約数をすべて列挙
long[] divisors(long n) pure
{
    long[] list;
    void func(Factor[] fs, long n)
    {
        if(fs.empty){
            list ~= n;
            return;
        }

        foreach(c; 0..fs[0].c+1)
        {
            func(fs[1..$], n * (fs[0].n ^^ c));
        }
    }

    func(factors(n), 1);
    sort(list);
    return list;
}
//nまでの素数のリスト
long[] primes(size_t n) pure
{
    if(n<2)return [];
    auto table = new long[n+1];
    long[] res;
    for(size_t i = 2;i<=n;i++)
    {
        if(table[i]==-1) continue;
        for(size_t a = i;a<table.length;a+=i)
        {
            table[a] = -1;
        }
        res ~= i;
    }
    return res;
}
//素数判定
bool isPrime(long n) pure
{
    if (n <= 1)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;
    for (long i = 3; i ^^ 2 <= n; i += 2)
        if (n % i == 0)
            return false;
    return true;
}

import std.stdio;
import std.algorithm;
import std.math;

long calc(long a, long b, long c) {
   auto delta = abs(a-b);
   if (c < delta) {
       return min(a, b) + c;
   } else {
       return max(a, b) + (c - delta) / 2;
   }
}

void main() {
    int n;
    readf("%s", n);
    for (auto i = 0; i < n; i++) {
        long a, b, c;
        readf(" %s %s %s", a, b, c);
        auto result = fold!(max)([
                calc(a, b, c),
                calc(a, c, b),
                calc(b, c, a)
        ]);
        writeln(result);
    }
}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto q = RD!int;
	auto ans = new long[](q);
	foreach (i; 0..q)
	{
		auto a = RDA;
		a.sort();
		long x, y, z;
		x = a[0];
		y = a[1];
		z = a[2];

		long d = y - x;
		long x2 = min(z, d);
		x += x2;
		z -= x2;
		x += z / 2;
		ans[i] = x;
	}

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

module main;

import std.stdio;

void main(string[] args){
    long n, input, sum;
    scanf("%lld", &n);
    while (n--) {
        sum = 0;
        for (int i = 0; i < 3; i++ ) {
            scanf("%lld", &input);
            sum += input;
        }
        printf("%lld\n", sum / 2);
    }
}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto q = RD!int;
	auto ans = new long[](q);
	foreach (i; 0..q)
	{
		auto a = RDA;
		a.sort();
		auto b = abs(a[0] - a[1]);
		auto c = abs(a[1] - a[2]);
		long x, y, z;
		if (b < c)
		{
			x = a[0];
			y = a[1];
			z = a[2];
		}
		else
		{
			x = a[1];
			y = a[2];
			z = a[0];
		}
		auto d = y - x;
		auto x2 = min(z, d);
		x += x2;
		z -= x2;
		x += z / 2;
		ans[i] = x;
	}

	foreach (e; ans)
	{
		writeln(e);
	}
	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 s = readln.strip.map !(q{a == '1'}).array;
		auto n = s.length.to !(int);
		auto total = s.sum;
		auto cur = 0;
		size_t res = n;
		foreach (i; 0..n)
		{
			res = min (res, cur + (n - i) - (total - cur));
			res = min (res, i - cur + (total - cur));
			cur += s[i];
		}
		writeln (res);
	}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		ans[ti] = long.max;
		foreach (i; 0..s.length)
		{
			long cnt1;
			foreach (j; 0..i)
			{
				if (s[j] == '0')
					++cnt1;
			}
			long cnt2;
			foreach (j; i..s.length)
			{
				if (s[j] == '0')
					++cnt2;
			}
			debug writeln(cnt1, ":", cnt2);
			ans[ti].chmin(min(cnt1, i-cnt1) + min(cnt2, s.length-i-cnt2));
		}
	}

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


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

void main(string[] args)
{
  auto n = next!int;
  auto k = next!int;
  auto adj = new int[][](n, n);
  foreach(ref row; adj) row[] = 1;
  foreach(permutation; 0 .. k)
    {
      auto currentPermutation = next!int(n);
      currentPermutation[] -= 1;
      foreach(i; 0 .. n)
	{
	  auto ci = currentPermutation[i];
	  foreach(j; i .. n)
	    {
	      auto cj = currentPermutation[j];
	      adj[ci][cj] &= 1;
	      adj[cj][ci] &= 0;
	    }
	}
    }
  int longestSequenceFrom(int v)
  {
    int longestContinuation = 0;
    foreach(w; 0 .. n)
      if (adj[v][w])
	{
	  longestContinuation =
	    max(longestContinuation,
		memoize!longestSequenceFrom(w));
	}
    return 1 + longestContinuation;
  }
  iota(0, n).map!(memoize!longestSequenceFrom).fold!max.writeln;
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  string toString()
  {
    return to!string(_rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (isArray!(typeof(ti)))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}

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

int saiki(int num, int k, int[] dp, int[][] pos)
{
    if (dp[num] != -1)
    {
        return dp[num];
    }
    auto n = cast(int)dp.length - 1;
    dp[num] = 0;
    auto p = new int[k];
    foreach (i; 0 .. k)
    {
        p[i] = pos[i][num];
    }
    foreach (i; 1 .. n + 1)
    {
        if (i != num)
        {
            int j;
            for (j = 0; j < k; ++ j)
            {
                if (pos[j][i] < pos[j][num])
                {
                    break;
                }
            }
            if (j == k)
            {
                auto ret = saiki(i, k, dp, pos);
                dp[num] = max(dp[num], ret + 1);
            }
        }
    }
    return dp[num];
}

void solve(int[][] p)
{
    auto k = cast(int)p.length;
    auto n = cast(int)p[0].length;
    auto pos = new int[][](k, n + 1);
    foreach (i; 0 .. k)
    {
        pos[i][0] = -1;
        foreach (j; 0 .. n)
        {
            pos[i][p[i][j]] = j;
        }
    }
    auto dp = new int[n + 1];
    fill(dp, -1);
    auto ans = saiki(0, k, dp, pos);
    writeln(ans);
}

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

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

int saiki(int num, int k, int[] dp, int[][] pos)
{
    if (dp[num] != -1)
    {
        return dp[num];
    }
    auto n = cast(int)dp.length - 1;
    dp[num] = 0;
    foreach (i; 1 .. n + 1)
    {
        if (i != num)
        {
            int j;
            for (j = 0; j < k; ++ j)
            {
                if (pos[j][i] < pos[j][num])
                {
                    break;
                }
            }
            if (j == k)
            {
                auto ret = saiki(i, k, dp, pos);
                dp[num] = max(dp[num], ret + 1);
            }
        }
    }
    return dp[num];
}

void solve(int[][] p)
{
    auto k = cast(int)p.length;
    auto n = cast(int)p[0].length;
    auto pos = new int[][](k, n + 1);
    foreach (i; 0 .. k)
    {
        pos[i][0] = -1;
        foreach (j; 0 .. n)
        {
            pos[i][p[i][j]] = j;
        }
    }
    auto dp = new int[n + 1];
    fill(dp, -1);
    auto ans = saiki(0, k, dp, pos);
    writeln(ans);
}

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

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

int saiki(int num, int n, int k, int[] dp, int[][] pos)
{
    if (dp[num] != -1)
    {
        return dp[num];
    }
    dp[num] = 0;
    foreach (i; 1 .. n + 1)
    {
        if (i != num)
        {
            int j;
            for (j = 0; j < k; ++ j)
            {
                if (pos[j][i] < pos[j][num])
                {
                    break;
                }
            }
            if (j == k)
            {
                auto ret = saiki(i, n, k, dp, pos);
                dp[num] = max(dp[num], ret + 1);
            }
        }
    }
    return dp[num];
}

void solve(int[][] p)
{
    auto k = cast(int)p.length;
    auto n = cast(int)p[0].length;
    auto pos = new int[][](k, n + 1);
    foreach (i; 0 .. k)
    {
        pos[i][0] = -1;
        foreach (j; 0 .. n)
        {
            pos[i][p[i][j]] = j;
        }
    }
    auto dp = new int[n + 1];
    fill(dp, -1);
    auto ans = saiki(0, n, k, dp, pos);
    writeln(ans);
}

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


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

ll dist(ll x, ll y){
    return x*x + y*y;
}

// Main Logic Here
void play(){
    ll d, k;
    d = rd; k = rd;
    ll up = 0;
    ll down = 0;
    bool side = 0;
    while(1){
        ll dis1 = dist(up+k, down);
        ll dis2 = dist(up, down+k);
        if(dis1 < dis2){
            up += k;
        }else{
            down += k;
        }
        if(min(dis1, dis2) > d*d){
            if(side){
                writeln("Ashish");
                return;
            }else{
                writeln("Utkarsh");
                return;
            }
        }
        side = !side;
    }
}

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(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long y) { y.modpow(mod - 2); x.modm(y); }

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

void main()
{
	auto t = RD!int;
	auto ans = new bool[](t);
	foreach (ti; 0..t)
	{
		auto d = RD;
		auto k = RD;

		bool f(long x)
		{
			return ((x*k)^^2)*2 <= d^^2;
		}
		auto r = binarySearch!(f)(0, d/k+1);
		debug writeln("r:", r);
		if (r == 0)
			ans[ti] = true;
		else if ((r*k)^^2 + ((r+1)*k)^^2 <= d^^2)
		{
			ans[ti] = true;
		}
	}

	foreach (e; ans)
	{
		writeln(e ? "Ashish" : "Utkarsh");
	}
	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;
		bool ok = (n % 2 == 0);
		if (ok)
		{
			sort (a);
			int [] c;
			foreach (i; 0..n / 2)
			{
				c ~= a[i];
				c ~= a[i + $ / 2];
			}
			a = c;
			auto b = a.cycle;
			ok &= n.iota.all !(i =>
			    (b[i] < b[i + 1] && b[i + 1] > b[i + 2]) ||
			    (b[i] > b[i + 1] && b[i + 1] < b[i + 2]));
		}
		if (ok)
		{
			writeln ("YES");
			writefln !("%(%s %)") (a);
		}
		else
		{
			writeln ("NO");
		}
	}
}

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

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

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

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

void main() {
  try {
    for (; ; ) {
      const numCases = readInt;
      foreach (caseId; 0 .. numCases) {
        const N = readInt;
        auto A = new int[N];
        foreach (i; 0 .. N) {
          A[i] = readInt;
        }
        A.sort;

        int[] ans;
        if (N % 2 == 0) {
          foreach (i; 0 .. N / 2) {
            ans ~= A[i];
            ans ~= A[i + N / 2];
          }
          debug {
            writeln(ans);
          }
          bool ok = true;
          foreach (i; 0 .. N) {
            const a0 = ans[i];
            const a1 = ans[(i + 1 == N) ? 0 : (i + 1)];
            ok = ok && ((i % 2 == 0) ? (a0 < a1) : (a0 > a1));
          }
          if (!ok) {
            ans = null;
          }
        }

        if (ans) {
          writeln("YES");
          foreach (i; 0 .. N) {
            if (i) write(" ");
            write(ans[i]);
          }
          writeln;
        } else {
          writeln("NO");
        }
      }
    }
  } catch (EOFException e) {
  }
}


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

string FMT_F = "%.10f";

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

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

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

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

		long cnt0, cnt1;
		foreach (c; s)
		{
			if (c == '0')
				++cnt0;
			else
				++cnt1;
		}

		ans[ti] = min(cnt0, cnt1) % 2 == 1;
	}

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

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		auto balance = abs (s.count ('0').to !(int) -
		    s.count ('1').to !(int));
		auto moves = (s.length - balance) / 2;
		writeln ((moves & 1) ? "DA" : "NET");
	}
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		auto balance = abs (s.count ('0') - s.count ('1'));
		auto moves = (s.length - balance) / 2;
		writeln ((moves & 1) ? "DA" : "NET");
	}
}


// Vicfred
// https://codeforces.com/contest/1401/problem/C
// math
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

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

        b.sort;

        long m = b[0];

        bool flag = true;
        for(int i = 0; i < n; i++)
            if(a[i] != b[i] && a[i]%m != 0)
                flag = false;

        if(flag)
            "YES".writeln;
        else
            "NO".writeln;
    }

}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		auto m = a.minElement;
		auto p = a.filter !(x => x % m == 0).array;
		sort (p);
		foreach (ref c; a)
		{
			if (c % m == 0)
			{
				c = p.front;
				p.popFront ();
			}
		}
		writeln (a.isSorted ? "YES" : "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(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;
		long x = long.max;
		foreach (i; 0..n)
			x.chmin(a[i]);

		long[] arr0, arr1;
		auto zero = new bool[](n);
		foreach (i; 0..n)
		{
			if (a[i] % x)
			{
				arr1 ~= a[i];
			}
			else
			{
				arr0 ~= a[i];
				zero[i] = true;
			}
		}
		arr0.sort();
		long last;
		bool ok = true;
		foreach (i; 0..n)
		{
			long y;
			if (zero[i])
			{
				y = arr0.front; arr0.popFront;
			}
			else
			{
				y = arr1.front; arr1.popFront;
			}
			if (y < last)
			{
				ok = false;
				break;
			}
			last = y;
		}
		ans[ti] = ok;
	}

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

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

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

void main() {
        IO cin;
        int t = 1;
        t = cin.readInt;
        while (t--) {
                int n = cin.readInt;
                int[] arr = new int[n];
                foreach (ref i; arr) i = cin.readInt;
                bool flag = false;
                if (isSorted(arr)) writeln("YES");
                else {
                        int[] arr2 = arr.dup;
                        sort(arr);
                        for (int i = 0; i < n; i++) {
                                if (arr[i] != arr2[i]) {
                                        if (gcd(arr[i], arr2[i]) && arr2[i] % arr[0] != 0) {
                                                flag = true;
                                                break;
                                        }
                                }
                        }
                        if (flag) writeln("NO");
                        else writeln("YES");
                }
        }
}

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;
		long x = long.max;
		foreach (i; 0..n)
			x.chmin(a[i]);

		long[] arr;
		foreach (i; 0..n)
		{
			if (a[i] % x)
			{
				arr ~= a[i];
			}
		}
		if (arr.empty)
		{
			ans[ti] = true;
			continue;
		}

		bool ok = true;
		foreach (i; 0..arr.length-1)
		{
			if (arr[i+1] < arr[i])
			{
				ok = false;
			}
		}
		ans[ti] = ok;
	}

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


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

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

    int[][] ktable = new int[][](n, n);

    int p = 1;
    foreach (i; 0..n) {
        foreach (j; 0..(k - 1)) {
            ktable[i][j] = p;
            p++;
        }
    }

    int answer = 0;
    foreach (i; 0..n) {
        foreach (j; (k - 1)..n) {
            ktable[i][j] = p;
            if (j == (k - 1)) {
                answer += p;
            }
            p++;
        }
    }

    answer.writeln;
    foreach (row; ktable)
        row.map!(to!string).join(" ").writeln;
}

import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm;
void main(){
    auto nk = readln.chomp.split.map!(to!int);
    int n = nk[0];
    int k = nk[1];

    int l = 1;
    int r = n*n - n*(n-k+1) + 1;

    int sum = 0;
    for(int x = r; x <= n*n; x += n-k+1){
        sum += x;
    }

    writeln(sum);

    foreach(x; 0..n){
        foreach(i; 0..(k-1)){
            write(l);
            l++;
            write(" ");
        }
        foreach(i; k..(n+1)){
            write(r);
            r++;
            if(i!=n)write(" ");
        }
        writeln();
    }
}

import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm;
void main(){
    auto nk = readln.chomp.split.map!(to!int);
    int n = nk[0];
    int k = nk[1];

    int l = 1;
    int r = n*n - n*(n-k+1) + 1;

    int sum = 0;
    for(int x = r; x < n*n; x += n-k+1){
        sum += x;
    }

    writeln(sum);

    foreach(x; 0..n){
        foreach(i; 0..(k-1)){
            write(l);
            l++;
            write(" ");
        }
        foreach(i; k..(n+1)){
            write(r);
            r++;
            if(i!=n)write(" ");
        }
        writeln();
    }
}


// Cheese-Cracker: cheese-cracker.github.io
import std.stdio, std.conv, std.functional, std.string, std.algorithm, std.array, std.container, std.range, std.typecons, std.bigint, std.numeric, std.math, std.random;

alias ll = long;
int inz(long t){ return to!int(t); }
static string[] tempstr;
T rd(T = long)() { while(!tempstr.length) tempstr = readln.chomp.split; string res = tempstr[0]; tempstr.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

ll getcnt(ll x, ll[] cnts){
    ll mod = to!ll(cnts.length) - 1;
    ll tim = (x / mod) * cnts[inz(mod)];
    tim += cnts[inz(x % mod)];
    return tim;
}

void play(){
    ll a, b;
    a = rd!int; b = rd!int;
    int q = rd!int;
    int lcmab = a * b / gcd(a, b);
    auto tills = new ll[](lcmab+1);
    ll cnt = 0;
    foreach(i; 1..lcmab+1){
        if((i % a) % b != (i % b) % a){
            ++cnt;
        }
        tills[i] = cnt;
    }
    foreach(i; 0..q){
        ll x, y;
        x = rd; y = rd;
        ll cntx = getcnt(x-1, tills);
        ll cnty = getcnt(y, tills);
        write(cnty - cntx, " ");
    }
    writeln;
}

int main(){
    ll t = 1;
    t = rd;        // Toggle!
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

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)
	{
		int a, b, q;
		readf !(" %s %s %s") (a, b, q);
		auto total = a * b;
		int [] s;
		s ~= 0;
		foreach (i; 1..total + 1)
		{
			s ~= s.back + ((i % a) % b != (i % b) % a);
		}

		long go (long limit)
		{
			return limit / total * s[total] +
			    s[cast (int) (limit % total)];
		}

		long [] answer;
		foreach (w; 0..q)
		{
			long l, r;
			readf !(" %s %s") (l, r);
			answer ~= go (r) - go (l - 1);
		}
		writefln !("%(%s %)") (answer);
	}
}

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

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

void main() {
  auto r = new InputReader ();
  immutable nt = r.next!uint ();
  foreach (tid; 0 .. nt) {
    const int a = r.next!int;
    const int b = r.next!int;
    const int q = r.next!int;
    const int m = a * b;
    auto x = new int[m];
    foreach (i; 0 .. m) {
      if (((i % a) % b) != ((i % b) % a)) x[i] = 1;
    }
    auto y = x.cumulativeFold!"a+b".array;
    int s = y.back;
    long cntLess (long t) {
      long u1 = t / m;
      int u2 = (t % m).to!int;
      long res = u1 * s;
      if (u2 > 0) res += y[u2-1];
      return res;
    }
    auto res = new long[q];
    foreach (qid; 0 .. q) {
      long L = r.next!long;
      long R = r.next!long;
      res[qid] = cntLess (R + 1) - cntLess (L);
    }
    writefln!("%(%s %)")(res);
  }
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto abq = readln.split.to!(int[]);
        long A = abq[0];
        long B = abq[1];
        if (A > B) swap(A, B);

        long solve(long n) {
            if (n < B) return n;

            auto lcm = A * B / gcd(A, B);
            long r = min(n, B-1) + (n / lcm - 1) * B;
            auto m = n / lcm * lcm;
            r += min(m + B, n+1) - m;
            return r;
        }

        auto Q = abq[2];
        long[] res;
        foreach (_q; 0..Q) {
            auto lr = readln.split.to!(long[]);
            auto l = lr[0];
            auto r = lr[1];
            res ~= r - l + 1 - solve(r) + solve(l-1);
        }
        writeln(res.to!(string[]).join(" "));
    }
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto abq = readln.split.to!(int[]);
        long A = abq[0];
        long B = abq[1];
        if (A > B) swap(A, B);

        long solve(long n) {
            if (n <= B) return n;

            auto lcm = A * B / gcd(A, B);
            long r = min(n, B-1) + (n / lcm - 1) * B;
            auto m = n / lcm * lcm;
            r += min(m + B, n) - m;
            return r;
        }

        auto Q = abq[2];
        long[] res;
        foreach (_q; 0..Q) {
            auto lr = readln.split.to!(long[]);
            auto l = lr[0];
            auto r = lr[1];
            res ~= r - l + 1 - solve(r) + solve(l-1);
        }
        writeln(res.to!(string[]).join(" "));
    }
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto abq = readln.split.to!(int[]);
        long A = abq[0];
        long B = abq[1];
        if (A > B) swap(A, B);

        long solve(long n) {
            if (n <= B) return n+1;

            auto lcm = A * B / gcd(A, B);
            long r = min(n, B) + (n / lcm - 1) * B;
            auto m = n / lcm * lcm;
            r += min(m + B, n+1) - m;
            return r;
        }

        auto Q = abq[2];
        long[] res;
        foreach (_q; 0..Q) {
            auto lr = readln.split.to!(long[]);
            auto l = lr[0];
            auto r = lr[1];
            res ~= r - l + 1 - solve(r) + solve(l-1);
        }
        writeln(res.to!(string[]).join(" "));
    }
}


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

void solve(){

	int n = read.to!int;
	long[] as;
	foreach(i; 0 .. n) as ~= read.to!long;

	string ans;
	int i = 0, j = n - 1;
	long x = -1;
	while(i <= j){
		if(as[i] < as[j]){
			if(x < as[i]) x = as[i], ans ~= "L", i += 1;
			else if(x < as[j]) x = as[j], ans ~= "R", j -= 1;
			else break;
		}
		else if(as[j] < as[i]){
			if(x < as[j]) x = as[j], ans ~= "R", j -= 1;
			else if(x < as[i]) x = as[i], ans ~= "L", i += 1;
			else break;
		}
		else{
			if(x >= as[i]) break;
			int c1 = i;
			while(c1 < j && as[c1] < as[c1 + 1]) c1 += 1;
			int c2 = j;
			while(i < c2 && as[c2] < as[c2 - 1]) c2 -= 1;
			if(c1 - i < j - c2) x = as[j], ans ~= "R", j -= 1;
			else x = as[i], ans ~= "L", i += 1;
		}
	}

	ans.length.writeln;
	ans.writeln;
}

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

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

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

    void gole(int p, int lm, int lst, ref dchar[] ans) {
        while (p <= lm && a[p] > lst) {
            ans ~= 'L';
            lst = a[p];
            ++p;
        }

        debug { writeln(ans.length); }
    }
    void gor(int p, int lm, int lst, ref dchar[] ans) {
        while (p >= lm && a[p] > lst) {
            ans ~= 'R';
            lst = a[p];
            --p;
        }

        debug { writeln(ans.length); }
    }
    int lst = 0;
    int le = 0, r = n-1;
    dchar[] ans;
    while (le <= r) {
        int leok = lst < a[le];
        int rok = lst < a[r];
        if (!leok && !rok) {
            break;
        }
        if (!leok) {
            gor(r, le, lst, ans);
            break;
        }
        if (!rok) {
            gole(le, r, lst, ans);
            break;
        }

        if (a[le] < a[r]) {
            ans ~= 'L';
            lst = a[le];
            ++le;
        } else if (a[r] < a[le]) {
            ans ~= 'R';
            lst = a[r];
            --r;
        } else {
            dchar[] ansle;
            dchar[] ansr;
            gole(le, r, lst, ansle);
            gor(r, le, lst, ansr);

            if (ansle.length > ansr.length) { ans ~= ansle; }
            else { ans ~= ansr; }
            break;
        }
    }

    ans.length.writeln;
    ans.writeln;
}

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

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto p = a.length - a.findAdjacent !(q{a >= b}).length;
		auto q = a.length - a.retro.findAdjacent !(q{a >= b}).length;
		auto lo = a.take (min (p + 1, n)).array;
		auto hi = a.retro.take (min (q + 1, n)).array;
		debug {writeln (lo, " ", hi);}

		string res;
		while (true)
		{
			if (lo.empty)
			{
				res ~= 'R'.repeat (hi.length).text;
				break;
			}

			if (hi.empty)
			{
				res ~= 'L'.repeat (lo.length).text;
				break;
			}

			if (lo.front < hi.front)
			{
				res ~= 'L';
				lo.popFront ();
			}
			else if (lo.front > hi.front)
			{
				res ~= 'R';
				hi.popFront ();
			}
			else if (lo.length < hi.length)
			{
				res ~= 'R'.repeat (hi.length).text;
				break;
			}
			else
			{
				res ~= 'L'.repeat (lo.length).text;
				break;
			}
		}

		res.length = min (res.length, n);
		writeln (res.length);
		writeln (res);
	}
}

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto N = RD!uint;
	auto a = RDR.ARR;

	auto cnt_l = new long[](N+1);
	{
		long last;
		foreach_reverse (i; 0..N)
		{
			if (a[i] < last)
				cnt_l[i] = cnt_l[i+1] + 1;

			last = a[i];
		}
	}
	auto cnt_r = new long[](N+1);
	{
		long last;
		foreach (i; 0..N)
		{
			if (a[i] < last)
				cnt_r[i+1] = cnt_r[i] + 1;

			last = a[i];
		}
	}

	debug writeln(cnt_l);
	debug writeln(cnt_r);

	string ans;
	long last;
	uint l, r = cast(uint)(a.length);

	void popL()
	{
		last = a.front;
		a.popFront;
		ans ~= "L";
		++l;
	}
	void popR()
	{
		last = a.back;
		a.popBack;
		ans ~= "R";
		--r;
	}

	while (!a.empty)
	{
		if (a.front > last && a.front == a.back)
		{
			debug writeln(cnt_l[l], " ", cnt_r[r]);
			if (cnt_l[l] >= cnt_r[r])
			{
				popL();
			}
			else
			{
				popR;
			}
		}
		else if (a.front > last && a.front < a.back)
		{
			popL();
		}
		else if (a.back > last && a.back < a.front)
		{
			popR();
		}
		else if (a.front > last)
		{
			popL();
		}
		else if (a.back > last)
		{
			popR();
		}
		else
		{
			break;
		}
	}

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

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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto N = RD;
	auto a = RDR.ARR;

	string ans;
	long last;
	while (!a.empty)
	{
		if (a.front > last && a.front == a.back)
		{
			uint l, r = cast(uint)(a.length - 1);
			while (abs(l - r) >= 0)
			{
				if (abs(l - r) <= 1)
				{
					if (a[l] <= a[r])
					{
						last = a.front;
						a.popFront;
						ans ~= "L";
						break;
					}
					else
					{
						last = a.back;
						a.popBack;
						ans ~= "R";
						break;
					}
				}
				else if (a[l] == a[r])
				{
					++l;
					--r;
				}
				else if (a[l] <= a[r])
				{
					last = a.front;
					a.popFront;
					ans ~= "L";
					break;
				}
				else
				{
					last = a.back;
					a.popBack;
					ans ~= "R";
					break;
				}
			}
		}
		else if (a.front > last && a.front < a.back)
		{
			last = a.front;
			a.popFront;
			ans ~= "L";
		}
		else if (a.back > last && a.back < a.front)
		{
			last = a.back;
			a.popBack;
			ans ~= "R";
		}
		else if (a.front > last)
		{
			last = a.front;
			a.popFront;
			ans ~= "L";
		}
		else if (a.back > last)
		{
			last = a.back;
			a.popBack;
			ans ~= "R";
		}
		else
		{
			break;
		}
	}

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


import std.stdio;

void main() {
    auto pline = new ulong[](2*100_000);

    long n, t, c;

    readf("%s %s %s\n", &n, &t, &c);

    for(int i; i < n; ++i) {
        readf("%s ", &pline[i]);
    }

    int acc;

    auto tline = new long[](1);
    tline[0] = 0;

    for(int i; i < n; ++i) {
        if(pline[i] > t)
            tline ~= i + 1;
        //writeln(tline[$ - 1]);
    }
    tline ~= n + 1;

    for( int i = 1; i < tline.length; ++i ) {
        if( tline[i] - tline[i - 1] - 1 >= c ) {
            acc += (tline[i] - tline[i - 1]) - c;
        }
    }

    writeln(acc);
}

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

int n, c, t;

void main() {
  scanf("%d%d%d\n", &n, &t, &c);
  auto a = readln.split.map!(to!int).array;
  size_t p = 0;
  int r = 0;
  foreach (i, v; a) {
    if (v > t) {
      p = i + 1;
    }
    if (i - p + 1 >= c) {
      r++;
    }
  }
  writeln(r);
}

import std.stdio;

void main() {
	auto pline = new ulong[](2*100_000);

	long n, t, c;

	readf("%s %s %s\n", &n, &t, &c);

	for(int i; i < n; ++i) {
		readf("%s ", &pline[i]);
	}

	int acc;

	auto tline = new ulong[](1);
	tline[0] = 0;

	for(int i; i < n; ++i) {
		if(pline[i] > t)
			tline ~= i;
	}
	tline ~= n + 1;
	//writeln("last n: ", tline[$ - 1]);
	for( int i = 1; i < tline.length; ++i ) {
		if( tline[i] - tline[i - 1] - 1 >= c ) {
			//writeln(acc);
			acc += (tline[i] - tline[i - 1]) - c;
		}
	}

	writeln(acc);
}

import std.stdio;

void main() {
    auto pline = new ulong[](2*100_000);

    long n, t, c;

    readf("%s %s %s\n", &n, &t, &c);

    for(int i; i < n; ++i) {
        readf("%s ", &pline[i]);
    }

    int acc;

    auto tline = new long[](1);
    tline[0] = 0;

    for(int i; i < n; ++i) {
        if(pline[i] > t)
            tline ~= i;
    }
    tline ~= n + 1;

    for( int i = 1; i < tline.length; ++i ) {
        if( tline[i] - tline[i - 1] - 1 >= c ) {
            acc += (tline[i] - tline[i - 1]) - c;
        }
    }

    writeln(acc);
}