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);
		iota (10 ^^ 9 - n, 10 ^^ 9).writefln !("%(%s %)");
	}
}

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

void solve(){
    long n = scan;
    for(int i = 2; i < 2 + n; ++i){
        write(i, " ");
    }
    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");

immutable multi = true;

void solve(int tc)
{
  auto n = readInt!int;
  foreach(i; 2 .. 2 + n)
    write(i, " ");
  writeln;
}

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

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

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

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

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


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

bool solve (int [] a, int n)
{
	if (!a.canFind (1))
	{
		return true;
	}
	sort (a);
	foreach (i; 1..n)
	{
		if (a[i] - a[i - 1] == 1)
		{
			return false;
		}
	}
	return true;
}

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 (solve (a, n) ? "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)); }
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 bool[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto a = RDA;
		a.sort;

		bool has1, hasD1;
		foreach (i; 0..n)
		{
			if (a[i] == 1)
				has1 = true;
			if (i != n-1)
			{
				if (a[i+1] - a[i] == 1)
					hasD1 = true;
			}
		}

		if (!(has1 && hasD1))
			ans[ti] = true;
	}

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

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

string FMT_F = "%.10f";

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

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

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

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

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

		bool has0, has1;
		foreach (i; 0..n)
		{
			if (a[i] > 2) continue;
			if (a[i] % 2)
				has1 = true;
			else
				has0 = true;
		}

		if (!(has0 && has1))
			ans[ti] = true;
	}

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


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

alias Tree = RBT!int;

void main() {
  GC.disable();

  // BEGIN HERE

  int n;
  readf(" %s", n);

  auto a = new int[n];
  auto b = new int[n];
  iota(0,n).each!(i=> readf(" %s", a[i]));
  iota(0,n).each!(i=> readf(" %s", b[i]));

  auto step = new int[n+1];
  iota(0,n).each!(i=> step[ b[i] ] = i+1);
  iota(0,n).each!(i=> step[ a[i] ] = 0);

  // can I append to the tail?
  if (step[1] > 0) {
    auto delta = n - step[1]+ 1;
    if (step[1 .. delta+1] == iota(step[1],n+1).array) {
      if (step[delta+1 ..$].enumerate.all!"a[1]<=a[0]") {
        writeln(n-delta); return;}
    }
  }

  // I can't
  auto ii = iota(0, step.length).map!(x=>to!int(x)).array;
  step[] -= ii[];
  auto ans = (step[1..$].maxElement +1) + n;

  writeln(ans);

  // END HERE

}

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

alias Tree = RBT!int;

void main() {
  GC.disable();

  // BEGIN HERE

  int n;
  readf(" %s", n);

  auto a = new int[n];
  auto b = new int[n];
  iota(0,n).each!(i=> readf(" %s", a[i]));
  iota(0,n).each!(i=> readf(" %s", b[i]));

  auto step = new int[n+1];
  iota(0,n).each!(i=> step[ b[i] ] = i+1);
  iota(0,n).each!(i=> step[ a[i] ] = 0);

  // can I append to the tail?
  if (step[1] > 0) {
    auto delta = n - step[1]+ 1;
    if (step[1 .. delta+1] == iota(step[1],n+1).array)
      if (step[delta+1 ..$].enumerate.all!"a.value<=a.index") {
        writeln(n-delta);
        return;
      }
  }

  // I can't
  writeln(step[1 ..$].enumerate.map!"a[1]-to!int(a[0])".maxElement + n);

  // END HERE

}

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 b = readln.splitter.map !(to !(int)).array;

		int res = 0;
		foreach (i; 0..n)
		{
			if (a[i] > 0)
			{
				res = max (res, n - a[i] + 1);
			}
		}

		int limit = n;
		foreach (i; 0..n)
		{
			if (b[i] == 1)
			{
				if (b[i..$].equal (iota (1, n + 1 - i)))
				{
					limit = i;
				}
			}
		}

		foreach (i; 0..limit)
		{
			if (b[i] > 0)
			{
				res = max (res, i + 1 + n - b[i] + 1);
			}
		}

		if (res > limit)
		{
			foreach (i; 0..n)
			{
				if (b[i] > 0)
				{
					res = max (res, i + 1 + n - b[i] + 1);
				}
			}
		}
		writeln (res);
	}
}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm;
import std.conv : to;
import std.range : iota, tee;
import std.algorithm.comparison;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

int solve(int[] step, int ts) {
  // return -1 -> cannot
  int s= 1;
  foreach(i;1..step.length) {
    if (step[i] == -1) continue;
    if (step[i] <= ts) {
      ts++;
    } else return -1;
  }

  return ts;
}

void main() {
  GC.disable();

  // BEGIN HERE

  int n;
  readf(" %s", n);

  auto a = new int[n];
  auto b = new int[n];
  iota(0,n).each!(i=> readf(" %s", a[i]));
  iota(0,n).each!(i=> readf(" %s", b[i]));

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

  auto step = new int[n+1];
  step[] = n;
  iota(0,n).each!(i=> step[ b[i] ] = i+1);
  iota(0,n).each!(i=> step[ a[i] ] = 0);

  // can I append to the tail?
  auto ss = step.dup;
  auto del = n - ss[1];
  bool flag = false;
  int bb = ss[1];
  foreach(i; 0..del+1) {
    if (ss[1+i] ==0) {flag=true; break;}
    if (ss[1 + i] != bb + i) { flag = true; break;}
    ss[1+i] = -1;
  }

  // writeln(iota(0,ss.length));
  // writeln(step); writeln(ss);
  if (!flag) {  // try to append
    auto ans = solve(ss, 0);
    if (ans != -1) { writeln(ans); return; }
  }

  // I can't
  auto sss = step.dup;
  sss[0] = 0;
  auto ii = iota(0, step.length).map!(x=>to!int(x)).array;
  sss[] -= ii[];
  auto ans = (sss[1..$].maxElement +1) + n;

  writeln(ans);

  // END HERE

}

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

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

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

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

int N;
int[] A, B;

int[] pos;

int solveDirect() {
  // B[N - 1] at 2 N - 1
  const d = (2 * N - 1) - B[N - 1];
  bool ok = true;
  foreach (x; 1 .. B[N - 1] + 1) {
    ok = ok && (pos[x] == d + x);
  }
  foreach (x; B[N - 1] + 1 .. N + 1) {
    ok = ok && (pos[x] <= d + x - N - 1);
  }
  return ok ? (N - B[N - 1]) : -1;
}

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

      pos = new int[N + 1];
      foreach (i; 0 .. N) {
        pos[A[i]] = i;
      }
      foreach (i; 0 .. N) {
        pos[B[i]] = N + i;
      }

      int ans = solveDirect();
      if (ans == -1) {
        int lo = -1, hi = 2 * N;
        for (; lo + 1 < hi; ) {
          const mid = (lo + hi) / 2;
          // 1 at 2 N + mid
          const d = (2 * N + mid) - 1;
          bool ok = true;
          foreach (x; 1 .. N + 1) {
            ok = ok && (pos[x] <= d + x - N - 1);
          }
          debug {
            writeln(mid, " ", d, " ", ok);
          }
          ok ? (hi = mid) : (lo = mid);
        }
        ans = hi + N;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

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 b = readln.splitter.map !(to !(int)).array;

		int res = 0;
		foreach (i; 0..n)
		{
			if (a[i] > 0)
			{
				res = max (res, n - a[i] + 1);
			}
		}

		int limit = n;
		foreach (i; 0..n)
		{
			if (b[i] == 1)
			{
				if (b[i..$].equal (iota (1, n + 1 - i)))
				{
					limit = i;
				}
			}
		}

		foreach (i; 0..limit)
		{
			if (b[i] > 0)
			{
				res = max (res, i + 1 + n - b[i] + 1);
			}
		}
		writeln (res);
	}
}

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 b = readln.splitter.map !(to !(int)).array;

		int res = 0;
		foreach (i; 0..n)
		{
			if (a[i] > 0)
			{
				res = max (res, n - a[i] + 1);
			}
		}

		int limit = n;
		foreach (i; 0..n)
		{
			if (b[i] == 1)
			{
				if (b[i..$].equal (iota (1, n + 1 - i)))
				{
					limit = i;
				}
			}
		}

		foreach (i; 0..limit)
		{
			if (b[i] > 0)
			{
				res = max (res, i + 1 + n - b[i] + 1);
			}
		}

		if (res > n - limit)
		{
			foreach (i; 0..n)
			{
				if (b[i] > 0)
				{
					res = max (res, i + 1 + n - b[i] + 1);
				}
			}
		}
		writeln (res);
	}
}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm;
import std.conv : to;
import std.range : iota, tee;
import std.algorithm.comparison;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

int solve(int[] step, int ts) {
  // return -1 -> cannot
  int s= 1;
  foreach(i;1..step.length) {
    if (step[i] == -1) continue;
    if (step[i] <= ts) {
      ts++;
    } else return -1;
  }

  return ts;
}

void main() {
  GC.disable();

  // BEGIN HERE

  int n;
  readf(" %s", n);

  auto a = new int[n];
  auto b = new int[n];
  iota(0,n).each!(i=> readf(" %s", a[i]));
  iota(0,n).each!(i=> readf(" %s", b[i]));

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

  auto step = new int[n+1];
  step[] = n;
  iota(0,n).each!(i=> step[ b[i] ] = i+1);
  iota(0,n).each!(i=> step[ a[i] ] = 0);

  // can I append to the tail?
  auto ss = step.dup;
  auto del = n - ss[1];
  bool flag = false;
  int bb = ss[1];
  foreach(i; 0..del+1) {
    if (ss[1 + i] != bb + i) { flag = true; break;}
    ss[1+i] = -1;
  }

  // writeln(iota(0,ss.length));
  // writeln(step); writeln(ss);
  if (!flag) {  // try to append
    auto ans = solve(ss, 0);
    if (ans != -1) { writeln(ans); return; }
  }

  // I can't
  auto sss = step.dup;
  sss[0] = 0;
  auto ii = iota(0, step.length).map!(x=>to!int(x)).array;
  sss[] -= ii[];
  auto ans = (sss.maxElement +1) + n;

  writeln(ans);

  // END HERE

}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm;
import std.conv : to;
import std.range : iota, tee;
import std.algorithm.comparison;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;

alias Tree = RBT!int;

int solve(int[] step, int ts) {
  // return -1 -> cannot
  int s= 1;
  foreach(i;1..step.length) {
    if (step[i] == -1) continue;
    if (step[i] <= ts) {
      ts++;
    } else return -1;
  }

  return ts;
}

void main() {
  GC.disable();

  // BEGIN HERE

  int n;
  readf(" %s", n);

  auto a = new int[n];
  auto b = new int[n];
  iota(0,n).each!(i=> readf(" %s", a[i]));
  iota(0,n).each!(i=> readf(" %s", b[i]));

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

  auto step = new int[n+1];
  step[] = n;
  iota(0,n).each!(i=> step[ b[i] ] = i+1);
  iota(0,n).each!(i=> step[ a[i] ] = 0);

  // can I append to the tail?
  auto ss = step.dup;
  auto del = n - ss[1];
  bool flag = false;
  foreach(i; 0..del+1) {
    if (ss[1 + i] != ss[1] + i) { flag = true; break;}
    ss[1+i] = -1;
  }

  // writeln(iota(0,ss.length));
  // writeln(step);
  // writeln(ss);
  if (!flag) {  // try to append
    auto ans = solve(ss, 0);
    if (ans != -1) { writeln(ans); return; }
  }

  // I can't
  auto sss = step.dup;
  sss[0] = 0;
  auto ii = iota(0, step.length).map!(x=>to!int(x)).array;
  sss[] -= ii[];
  auto ans = (sss.maxElement +1) + n;

  writeln(ans);

  // END HERE

}


import std.stdio;
import std.math;

static immutable N = 100000;

int n, q, ans;
int[N + 1] a, top, f;
int[20][N + 1] prime;

int main() {
  readf(" %d", &n);
  for (int i = 1; i <= n; ++ i) {
    readf(" %d", &a[i]);
    q = cast(int) sqrt(real(a[i]));
    for (int j = 2; j <= q; ++ j) {
      if (! (a[i] % j)) {
        prime[i][top[i] ++] = j;
        while (! (a[i] % j)) a[i] /= j;
      }
    }
    if (a[i] > 1) prime[i][top[i] ++] = a[i];
  }
  f[1] = 1;
  for (int i = 1; i <= n; ++ i) {
    int rec = 0;
    for (int j = 0; j < top[i]; ++ j)
      if (rec < f[prime[i][j]]) rec = f[prime[i][j]];
    ++ rec;
    for (int j = 0; j < top[i]; ++ j) f[prime[i][j]] = rec;
  }
  for (int i = 1; i <= N; ++ i)
    if (f[i] > ans) ans = f[i];
  writeln(ans);
  return 0;
}

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

void main() {
    immutable int MAX = 10^^5 + 1;
    bool[] table = new bool[](MAX);
    fill(table, true);
    table[0] = table[1] = false;

    int[][] P = new int[][](MAX);

    foreach (i; 2..MAX) {
        if (!table[i]) continue;
        P[i] ~= i;
        for (int j = i + i; j < MAX; j += i) {
            table[j] = false;
            P[j] ~= i;
        }
    }

    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto dp = new int[](MAX);

    foreach (i; 0..N) {
        int tmp = 0;
        foreach (j; P[A[i]]) tmp = max(tmp, dp[j] + 1);
        foreach (j; P[A[i]]) dp[j] = tmp;
    }

    int ans = dp.reduce!max;
    max(ans, 1).writeln;
}

import std.stdio;
import std.math;

static immutable N = 100000;

int n, q, ans;
int[N + 1] a, top, f;
int[N + 1][20] prime;

int main() {
  readf(" %d", &n);
  for (int i = 1; i <= n; ++ i) {
    readf(" %d", &a[i]);
    q = cast(int) sqrt(real(a[i]));
    for (int j = 2; j <= q; ++ j) {
      if (! (a[i] % j)) {
        prime[i][++ top[i]] = j;
        while (! (a[i] % j)) a[i] /= j;
      }
    }
    if (a[i] > 1) prime[i][++ top[i]] = a[i];
  }
  for (int i = 1; i <= n; ++ i) {
    int rec = 0;
    for (int j = 1; j <= top[i]; ++ j)
      if (rec < f[prime[i][j]]) rec = f[prime[i][j]];
    ++ rec;
    for (int j = 1; j <= top[i]; ++ j) f[prime[i][j]] = rec;
  }
  for (int i = 1; i <= N; ++ i)
    if (f[i] > ans) ans = f[i];
  writeln(ans);
  return 0;
}

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

void main() {
    immutable int MAX = 10^^5 + 1;
    bool[] table = new bool[](MAX);
    fill(table, true);
    table[0] = table[1] = false;

    int[][] P = new int[][](MAX);

    foreach (i; 2..MAX) {
        if (!table[i]) continue;
        P[i] ~= i;
        for (int j = i + i; j < MAX; j += i) {
            table[j] = false;
            P[j] ~= i;
        }
    }

    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto dp = new int[](MAX);

    foreach (i; 0..N) {
        int tmp = 0;
        foreach (j; P[A[i]]) tmp = max(tmp, dp[j] + 1);
        foreach (j; P[A[i]]) dp[j] = tmp;
    }

    dp.reduce!max.writeln;
}


// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;

int n, a, b;
int[] x, y;

void main() {
    scan(n, a, b);

    x = new int[](n);
    y = new int[](n);

    foreach (i ; 0 .. n) {
        scan(x[i], y[i]);
    }

    bool check(int U, int V, int u, int v) {
        return (u <= U && v <= V) || (u <= V && v <= U);
    }

    int ans;

    foreach (i ; 0 .. n) {
        foreach (j ; 0 .. n) {
            if (i == j) continue;

            if (x[i] <= a && y[i] <= b) {
                if (check(a - x[i], b, x[j], y[j]) || check(a, b - y[i], x[j], y[j])) {
                    ans = max(ans, x[i]*y[i] + x[j]*y[j]);
                }
            }

            if (x[i] <= b && y[i] <= a) {
                if (check(a - y[i], b, x[j], y[j]) || check(a, b - x[i], x[j], y[j])) {
                    ans = max(ans, x[i]*y[i] + x[j]*y[j]);
                }
            }
        }
    }

    writeln(ans);
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto H = s[1];
    auto W = s[2];
    auto X = new int[](N);
    auto Y = new int[](N);
    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        X[i] = s[0];
        Y[i] = s[1];
    }

    int x1, y1, x2, y2;
    int ans = 0;

    foreach (i; 0..N) {
        foreach (j; i+1..N) {
            foreach (rot; 0..4) {
                if (rot == 0) x1 = X[i], y1 = Y[i], x2 = X[j], y2 = Y[j];
                if (rot == 1) x1 = X[i], y1 = Y[i], x2 = Y[j], y2 = X[j];
                if (rot == 2) x1 = Y[i], y1 = X[i], x2 = X[j], y2 = Y[j];
                if (rot == 3) x1 = Y[i], y1 = X[i], x2 = Y[j], y2 = X[j];
                if (x1 + x2 <= H && max(y1, y2) <= W) ans = max(ans, X[i] * Y[i] + X[j] * Y[j]);
                if (max(x1, x2) <= H && y1 + y2 <= W) ans = max(ans, X[i] * Y[i] + X[j] * Y[j]);
            }
        }
    }

    ans.writeln;
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio, std.string, std.array, std.algorithm, std.conv;

void main() {
    auto nab = to!(int[])(split(chomp(readln())));
    int n = nab[0], a = nab[1], b = nab[2];
    int ans = 0;
    int[101] u, w;
    for (int i = 0; i < n; i++) {
        auto xy = to!(int[])(split(chomp(readln())));
        int x = xy[0], y = xy[1];
        int s = x * y;
        if (x <= a && y <= b) {
            for (int j = 1; j < 101; j++) {
                if (u[j] > 0 && j + x <= a) {
                    ans = max(ans, u[j] + s);
                }
                if (w[j] > 0 && j + y <= b) {
                    ans = max(ans, w[j] + s);
                }
            }
        }
        if (y <= a && x <= b) {
            for (int j = 1; j < 101; j++) {
                if (u[j] > 0 && j + y <= a) {
                    ans = max(ans, u[j] + s);
                }
                if (w[j] > 0 && j + x <= b) {
                    ans = max(ans, w[j] + s);
                }
            }
        }
        if (x <= a && y <= b) { u[x] = max(u[x], s); w[y] = max(w[y], s); }
        if (y <= a && x <= b) { u[y] = max(u[y], s); w[x] = max(w[x], s); }
    }
    writeln(ans);
}


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

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

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

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

int root(int[] uf, int u) {
  return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));
}
bool connect(int[] uf, int u, int v) {
  u = uf.root(u);
  v = uf.root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}

int Ask(int u) {
  writeln("? ", u + 1);
  stdout.flush;
  const v = readInt - 1;
  return v;
}

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

    int[] us = iota(N).array;
    us.sort!((u, v) => (D[u] < D[v]));

    auto uf = new int[N];
    uf[] = -1;
    auto vis = new bool[N];
    foreach_reverse (u; us) if (!vis[u]) {
      vis[u] = true;
      foreach (j; 0 .. D[u]) {
        const v = Ask(u);
        uf.connect(u, v);
        if (vis[v]) {
          break;
        }
        vis[v] = true;
      }
    }

    write("!");
    foreach (u; 0 .. N) {
      write(" ", uf.root(u) + 1);
    }
    writeln;
    stdout.flush;
  }
}

import std.algorithm;
import std.conv;
import std.math;
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 d = readln.splitter.map !(to !(int)).array;

		auto order = n.iota.array;
		order.sort !((i, j) => d[i] > d[j]);
		auto color = new int [n];

		void recolorAs (int v, int u)
		{
			auto oldColor = color[v];
			auto newColor = color[u];
			foreach (i; 0..n)
			{
				if (color[i] == oldColor)
				{
					color[i] = newColor;
				}
			}
		}

		foreach (v; order)
		{
			if (color[v] != 0)
			{
				continue;
			}
			auto cur = d[v];
			color[v] = v + 1;
			foreach (step; 0..cur)
			{
				writefln !("? %s") (v + 1);
				stdout.flush ();
				auto u = readln.strip.to !(int);
				u -= 1;
				if (color[u] == 0)
				{
					color[u] = color[v];
				}
				else
				{
					recolorAs (u, v);
					break;
				}
			}
		}

		writefln !("! %(%s %)") (color);
		stdout.flush ();
	}
}


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

string FMT_F = "%.10f";

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

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

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

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

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

		ans[ti] = 1;
		a.sort();
		foreach (i; 0..n)
		{
			if (a[i] <= i+1)
				ans[ti] = i+2;
		}
	}

	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 n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		sort (a);
		int res = 1;
		foreach (i, c; a)
		{
			if (c <= i + 1)
			{
				res = i + 2;
			}
		}
		writeln (res);
	}
}


import std.algorithm;
import std.stdio;
import std.typecons;

void main ()
{
	int n;
	while (readf (" %d", &n) > 0)
	{
		auto a = new int [n];
		foreach (i; 0..n)
		{
			readf (" %d", &a[i]);
		}
		int m;
		readf (" %d", &m);
		foreach (j; 0..m)
		{
			int x, y;
			readf (" %d %d", &x, &y);
			x--;
			y--;
			if (x - 1 >= 0)
			{
				a[x - 1] += y;
			}
			if (x + 1 < n)
			{
				a[x + 1] += a[x] - y - 1;
			}
			a[x] = 0;
		}
		writefln ("%(%d\n%)", a);
	}
}

module sigod.codeforces.p294A;

import std.conv;
import std.stdio;
import std.string;

void main()
{
	int N;
	stdin.readf("%s", &N);
	stdin.readln();

	int[] counts = read_array!int();

	int M;
	stdin.readf("%s", &M);
	stdin.readln();

	foreach (i; 0 .. M) {
		int x, y;

		stdin.readf("%s %s", &x, &y);
		stdin.readln();

		--x;

		if (x > 0) {
			counts[x - 1] += y - 1;
		}
		if (x < N - 1) {
			counts[x + 1] += counts[x] - y;
		}

		counts[x] = 0;
	}

	foreach (count; counts) {
		stdout.writeln(count);
	}
}

private
T[] read_array(T)()
{
	auto input = stdin.readln().strip().split();

	T[] result = new T[input.length];

	foreach (index, ref element; input) {
		result[index] = element.to!T();
	}

	return result;
}


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(); } bool DEBUG = 0;
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    int n = scan!int;
    long[] as = scan!long(n);

    long[] xs = new long[](600_999);
    foreach(i, a; as){
        int d = n + a.to!int - (i + 1).to!int;
        xs[d] += a;
    }

    long ans = 0;
    foreach(x; xs) ans.raiseTo(x);

    ans.writeln;
}

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

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

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

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

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

      long[long] sums;
      foreach (i; 0 .. N) {
        sums[B[i] - i] += B[i];
      }
      const ans = sums.values.maxElement;
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}

void main()
{
  long n; get(n);
  auto b = new long[cast(size_t)n]; get(b);
  long[long] mb;
  long m = long.min;
  zip(iota(0, n), b).each!((p) {mb[p[1] - p[0]] += b[cast(size_t)p[0]]; m = max(m, mb[p[1] - p[0]]);});
  ans(m);
}

import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;
import std.traits;
import std.array;
struct Input
{
  T next(T)()
  {
    import std.conv;
    return to!T(nextWord);
  }
  string nextWord()
  {
    if (_nextWords.empty)
	_nextWords.insertFront(readln().split);
    string word = _nextWords.front; _nextWords.removeFront;
    return word;
  }
  import std.container;
  DList!string _nextWords;
}
Input input;
void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]) && !is(T[i] == string))
      foreach(ref e; args[i])
    	read(e);
    else static if(isTuple!(T[i]))
      static foreach(n; 0 .. T[i].Types.length)
	read(args[i][n]);
    else
      args[i] = input.next!(typeof(args[i]))();
}
auto itup(alias k, alias F)()
{
  alias T = Parameters!F;
  foreach(i; 0 .. k)
    {
      T t; get(t);
      F(t);
    }
}
alias get = read;
void wone(T)(T t, char end)
{
  static if(isArray!T && !is(T == string))
    {
      foreach(i; 0 .. t.length - 1)
	  write(t[i], ' ');
      write(t[$ - 1], end);
    }
  else
      write(t, end);
}
void wr(T...)(T t)
{
  static foreach(i; 0 .. T.length)
    static if(i + 1 < T.length)
      wone(t[i], ' ');
    else
      wone(t[i], '\n');
}
void ans(T...)(T t)
{
  import core.stdc.stdlib;
  wr(t);
  exit(0);
}

void main()
{
  int n; get(n);
  auto b = new int[n]; get(b);
  int[int] mb;
  int m = int.min;
  zip(iota(0, n), b).each!((p) {mb[p[1] - p[0]] += b[p[0]]; m = max(m, mb[p[1] - p[0]]);});
  ans(m);
}


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

string FMT_F = "%.10f";

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

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

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

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

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

		long time;
		foreach (i; 0..n)
		{
			long d;
			if (i == 0)
				d = a[i] + tm[i];
			else
				d = a[i] - b[i-1] + tm[i];
			time += d;
			debug writeln("time:", time);
			if (i == n-1) break;
			auto w = (b[i]-a[i]+1) / 2;
			time = max(time+w, b[i]);
		}
		ans[ti] = time;
	}

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

import std.stdio, std.string, std.algorithm, std.range, std.conv;
void main()
{
    int q;
    readf!"%d\n"(q);
    foreach (_; 0 .. q)
    {
        int n;
        readf!"%d\n"(n);
        int[] a = new int[n], b = new int[n];
        foreach (i; 0 .. n)
            readf!"%d %d\n"(a[i], b[i]);
        int[] tm = readln.split.map!(to!int).array;
        int res = 0;
        foreach (i; 0 .. n)
        {
            res += a[i] - (i > 0 ? b[i - 1] : 0) + tm[i];
            if (i < n - 1)
                res = max(res + (b[i] - a[i] + 1) / 2, b[i]);
        }
        writeln(res);
    }
}


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 x, y;
		readf !(" %s %s") (x, y);
		long res = 0;
		for (int r = 1; ; r++)
		{
			int lo = r + 2;
			int hi = min (y + 1, x / r);
			if (hi < lo)
			{
				break;
			}
			res += hi - lo + 1;
		}
		writeln (res);
	}
}

import std;

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

void solve() {
    long X, Y; readf("%d %d\n", &X, &Y);
    long bs; {
        long lb = 0, ub = 1L<<30;
        while (lb + 1 < ub) {
            long mid = (lb + ub) / 2;
            (mid - 1 <= X / (mid + 1L) ? lb : ub) = mid;
        }
        bs = min(lb, Y);
    }
    long A = (1L + bs) * bs / 2L - bs;
    long B = 0;
    if (bs == Y) {
    } else {
        for (long k = 1; k <= X / (bs + 1L); k++) {
            long U = min(Y, X / k - 1L);
            long L = max(bs, X / (k + 1L) - 1L);
            B += k * max(0L, U - L);
        }
    }
    writeln(A + B);
}

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

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

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

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

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

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

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

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

void main()
{
    int T; get(T);
    while (T--) {
        long x, y; get(x, y);
        long res;
        for (long i = 1; i^^2 <= x; ++i) {
            res += max(0, min((x - i) / i, y) - 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(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 x = RD;
		auto y = RD;

		for (long i = 1; i*i < x; ++i)
		{
			auto xx = x - i;
			auto r = min(xx / i, y) - i;
			if (r > 0)
				ans[ti] += r;
		}
	}

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

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()
{
    auto t = readln.chomp.to!int;

    while (t--) {
        auto v = readln.splitter.map!(to!int).array;
        auto x = v[0], y = v[1];

        long ans = 0;
        foreach (r; 1 .. y) {
            int left = x - r;
            if (left <= 1) { break; }

            int mxk = min(left / r, y);
            if (mxk <= r) { break; }

            int cur = mxk - r;

            ans += cur;
        }

        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()
{
    auto t = readln.chomp.to!int;

    while (t--) {
        auto v = readln.splitter.map!(to!int).array;
        auto x = v[0], y = v[1];

        int ans = 0;
        foreach (r; 1 .. y) {
            int left = x - r;
            if (left <= 1) { break; }

            int mxk = min(left / r, y);
            if (mxk <= r) { break; }

            int cur = mxk - r;

            ans += cur;
        }

        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()
{
    auto t = readln.chomp.to!int;

    while (t--) {
        auto v = readln.splitter.map!(to!int).array;
        auto x = v[0], y = v[1];

        int ans = 0;
        foreach (b; 1 .. y + 1) {
            int left = x - b;
            if (left <= 1) { break; }

            int mxk = min(left / b, y);
            if (mxk - b <= 0) { break; }

            int cur = mxk - b;

            debug { writeln(b, ' ', cur); }

            ans += cur;
        }

        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()
{
    auto t = readln.chomp.to!int;

    while (t--) {
        auto v = readln.splitter.map!(to!int).array;
        auto x = v[0], y = v[1];

        int sq = sqrt(x.to!real).to!int;

        int ans = 0;
        foreach (b; 1 .. min(y, sq) + 1) {
            int left = x - b;
            if (left <= 1) { break; }

            int mxk = min(left / b, y);
            if (mxk - b <= 0) { break; }

            int cur = mxk - b;

            debug { writeln(b, ' ', cur); }

            ans += cur;
        }

        ans.writeln;
    }
}


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

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

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

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

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

int N;
int[] A, B;

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

		auto ps = new Pair!(int, int)[N];
		foreach (i; 0 .. N) {
			ps[i] = pair(A[i], B[i]);
		}
		ps.sort();
debug{
writeln("ps = ",ps);
}

		bool ans;
		int max;
		foreach (i; 0 .. N) {
			if (max > ps[i].y) {
				ans = true;
			}
			chmax(max, ps[i].y);
		}
		writeln(ans ? "Happy Alex" : "Poor Alex");

	}
	} catch (EOFException) {}
}

import std.stdio;

void main() {
	int n;
	readf("%s", &n);
	foreach(_; 0..n) {
		int ai, bi;
		readf(" %s %s ", &ai, &bi);
		if (ai != bi) {
			writeln("Happy Alex");
			return;
		}
	}
	writeln("Poor Alex");
}

import std.typecons;
import std.algorithm;

alias Note = Tuple!(uint, "a", uint, "b");

bool noteLess(const Note a, const Note b) {
	if (a.a == b.a) {
		return a.b > b.b;
	}

	return a.a < b.a;
}

bool solve(Note[] ns) {
	sort!(noteLess)(ns);
	foreach (i; 1..ns.length) {
		Note prev = ns[i - 1];
		Note cur = ns[i];
		if (prev.a < cur.a && prev.b > cur.b) {
			return true;
		}
	}
	return false;
}

unittest {
	{
		Note[] ns = [Note(1, 2), Note(2, 1)];
		assert(solve(ns));
	}

	{
		Note[] ns = [Note(2, 1), Note(1, 2)];
		assert(solve(ns));
	}

	{
		Note[] ns = [Note(1, 1)];
		assert(false == solve(ns));
	}

	{
		Note[] ns = [Note(1, 1), Note(2, 2), Note(3, 3), Note(4, 4), Note(5, 5)];
		assert(false == solve(ns));
	}

	{
		Note[] ns = [Note(4, 5), Note(2, 2), Note(3, 3), Note(1, 1), Note(5, 4)];
		assert(solve(ns));
	}
}

int main(string[] argv) {
	import std.stdio;
	uint n = 0;
	readf(" %s", &n);
	auto ns = new Note[](n);
	foreach (i; 0..n) {
		readf(" %s %s", &(ns[i].a), &(ns[i].b));
	}
	writeln(solve(ns) ? "Happy Alex" : "Poor Alex");
    return 0;
}

import std.stdio;

void main() {
    int n; readf("%d\n", &n);
    bool poor = true;
    for (int i = 0; i < n; ++i) {
        int a, b;
        readf("%d %d\n", &a, &b);
        if (poor && a != b) {
            poor = false;
        }
    }
    if (poor)
        writeln("Poor Alex");
    else
        writeln("Happy Alex");
}

import std.stdio;
import std.string;
import std.conv;
import std.regex;
import std.algorithm.iteration;
import std.algorithm.sorting;
import std.typecons;

void main()
{
  auto n = stdin.readln.strip.to!int;
  alias DicEntry = Tuple!(int, "price", int, "quality");
  DicEntry[]  prices;
  prices.length = n;

  for(int i=0; i<n; i++) {
    auto s = stdin.readln.strip.split(regex(` +`)).map!(to!int);
    prices[i].price = s[0];
    prices[i].quality = s[1];
  }
  auto s = "Poor Alex";
  prices.sort!((a,b)=>a.price < b.price);
  for(int i=0; i<n-1; i++) {
    if (prices[i].price < prices[i+1].price && prices[i].quality > prices[i+1].quality) {
        s = "Happy Alex";
        break;
    }
  }
  writeln(s);
}

// https://codeforces.com/problemset/problem/456/A

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

void main() {
    int n = readln.chomp.to!int;
    int[][] laptops;

    int a, b;
    foreach(idx; 0..n) {
        int[] laptop;
        readf("%d %d\n", &a, &b);
        laptop ~= [a,b];
        laptops ~= laptop;
    }

    bool happy = false;
    //laptops.sort();

    for(int i = 0; i < n; i++)
        if(laptops[i][0] != laptops[i][1])
            happy = true;

    /* brute force
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(laptops[i][0] < laptops[j][0] &&
                laptops[i][1] > laptops[j][1])
                happy = true;
        }
    }
   */

    if(happy)
        writeln("Happy Alex");
    else
        writeln("Poor Alex");
}

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

void main() {
    int n = readln.chomp.to!int;
    int[][] info;

    foreach (i; 0..n) {
        info ~= readln.chomp.split.map!(to!int).array;
    }

    string ans = "Poor Alex";
    info.sort;
    foreach (i; 1..n) {
        if (info[i][1] < info[i - 1][1]) {
            ans = "Happy Alex";
            break;
        }
    }

    ans.writeln;
}

import std.stdio;
import std.algorithm;

unittest{
  assert(solve([[1,2],[2,1]]) == true, "Test 1");
  assert(solve([[1,1],[2,2]]) == false, "Test 2");
  assert(solve([[2,2],[3,3],[1,1]]) == false, "Test 3");

}

bool solve(int[2][] lap){
  for(int i =1; i < lap.length; i++){
    if(!(lap[i][0] == lap[i][1])){
      return true;
    }
  }
  return false;
}

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

  int[2][] lap = new int[2][n];
  for(int i = 0; i < n; i++){
    int p,q;
    readf("%s %s\n",&p,&q);
    lap[i][0] = p;
    lap[i][1] = q;
  }

  if (solve(lap)) {
    writeln("Happy Alex");
  } else {
    writeln("Poor Alex");
  }
}

import std.stdio;

void main() {
	int n;
	readf("%s", &n);
	foreach(_; 0..n) {
		int ai, bi;
		readf(" %s %s ", &ai, &bi);
		if (ai != bi) {
			writeln("Poor Alex");
			return;
		}
	}
	writeln("Happy Alex");
}

import std.stdio;
import std.algorithm;

unittest{
  assert(solve([[1,2,0],[2,1,1]]) == true, "Test 1");
}

bool solve(int[3][] lap){
  for(int i =1; i < lap.length; i++){
    if(!(lap[i][0] == lap[i][i])){
      return true;
    }
  }
  return false;
}

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

  int[3][] lap = new int[3][n];
  for(int i = 0; i < n; i++){
    int p,q;
    readf("%s %s\n",&p,&q);
    lap[i][0] = p;
    lap[i][1] = q;
    lap[i][2] = i;
  }

  if (solve(lap)) {
    writeln("Happy Alex");
  } else {
    writeln("Poor Alex");
  }
}

import std.stdio;
import std.algorithm;

unittest{
  // assert(solve([[1,2,0],[2,1,1]]) == true, "Test 1");
}

bool solve(int[3][] lap){
  sort!((int[3] a,int[3] b){ return a[0] < b[0];})(lap);
  //writeln(lap);

  for(int i =1; i < lap.length; i++){
    for(int j = 0; j < i; j++){
      if(lap[j][1] > lap[i][1]){
        return true;
      }
    }
  }
  return false;
}

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

  int[3][] lap = new int[3][n];
  for(int i = 0; i < n; i++){
    int p,q;
    readf("%s %s\n",&p,&q);
    lap[i][0] = p;
    lap[i][1] = q;
    lap[i][2] = i;
  }

  if (solve(lap)) {
    writeln("Happy Allex");
  } else {
    writeln("Poor Allex");
  }
}

import std.stdio;
import std.algorithm;

unittest{
  assert(solve([[1,2],[2,1]]) == true, "Test 1");
}

bool solve(int[2][] lap){
  for(int i =1; i < lap.length; i++){
    for(int j = 0; j < i; j++){
      if(!(lap[i] == lap[j])){
        return true;
      }
    }
  }
  return false;
}

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

  int[2][] lap = new int[2][n];
  for(int i = 0; i < n; i++){
    int p,q;
    readf("%s %s\n",&p,&q);
    lap[i][0] = p;
    lap[i][1] = q;
  }

  if (solve(lap)) {
    writeln("Happy Allex");
  } else {
    writeln("Poor Allex");
  }
}


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

void main() {
    auto K = readln.chomp.to!int;
    writeln("3 3");
    auto IK = 0b100000000000000000 + K;
    auto IO = 0b100000000000000000;
    auto OK = K;
    auto ans =
    [[IK, IO, 0],
     [OK, IK, OK],
     [0, 0, OK]];
    foreach (a; ans)  {
        foreach (b; a) write(b, " ");
        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 k;
    readf("%s", &k);
    readln;

    auto ans = new int[][] (3, 2);

    immutable int bigBit = 2 ^^ 17;

    ans[0][0] = bigBit + k;
    ans[1][0] = bigBit;
    ans[0][1] = k;

    ans[1][1] = bigBit + k;

    ans[2][0] = 0;
    ans[2][1] = k;

    writeln(3, ' ', 2);
    foreach (i; 0 .. 3) {
        ans[i].map!(to!string).join(" ").writeln;
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto k = RD!int;
	int digit;
	auto x = k;
	while (x != 0)
	{
		x >>= 1;
		++digit;
	}

	int y = 1 << digit;
	int z = k | y;

	auto ans = new int[][](2, 3);
	ans[0][0] = z;
	ans[1][0] = y;
	ans[0][1] = k;
	ans[1][1] = z;
	ans[0][2] = 0;
	ans[1][2] = k;

	writeln("2 3");
	foreach (i; 0..2)
	{
		ans[i].map!(to!string).join(" ").writeln;
	}
	stdout.flush;
	debug readln;
}

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

void main() {
    auto K = readln.chomp.to!int;
    auto ans =
    [[0b1000000000000000000, 0b0111111111111111111, 0b0111111111111111111],
     [0b1000000000000000000, 0, K],
     [0b1000000000000000000, 0, K]];
    foreach (a; ans)  {
        foreach (b; a) write(b, " ");
        writeln;
    }
}

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

void main() {
    auto K = readln.chomp.to!int;
    writeln("3 3");
    auto ans =
    [[0b1000000000000000000, 0b0111111111111111111, 0b0111111111111111111],
     [0b1000000000000000000, 0, K],
     [0b1000000000000000000, 0b1000000000000000000, 0b1000000000000000000+K]];
    foreach (a; ans)  {
        foreach (b; a) write(b, " ");
        writeln;
    }
}

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

void main() {
    auto K = readln.chomp.to!int;
    writeln("3 3");
    auto ans =
    [[0b1000000000000000000, 0b0111111111111111111, 0b0111111111111111111],
     [0b1000000000000000000, 0, K],
     [0b1000000000000000000, 0, K]];
    foreach (a; ans)  {
        foreach (b; a) write(b, " ");
        writeln;
    }
}

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

void main() {
    auto K = readln.chomp.to!int;
    writeln("3 3");
    auto IK = 0b1000000000000000000 + K;
    auto IO = 0b1000000000000000000;
    auto OK = K;
    auto ans =
    [[IK, IO, IO],
     [OK, IO, IO],
     [OK, OK, IK]];
    foreach (a; ans)  {
        foreach (b; a) write(b, " ");
        writeln;
    }
}

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

void main() {
    auto K = readln.chomp.to!int;
    writeln("3 3");
    auto IK = 0b1000000000000000000 + K;
    auto IO = 0b1000000000000000000;
    auto OK = K;
    auto ans =
    [[IK, IO, 0],
     [OK, IO, OK],
     [0, 0, OK]];
    foreach (a; ans)  {
        foreach (b; a) write(b, " ");
        writeln;
    }
}


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

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

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

    auto place = new int[] (n+1);
    foreach (i, e; arr) { place[e] = i.to!int; }

    auto adjr = n.iota.map!(x => x+1).array;
    auto adjle = n.iota.map!(x => x-1).array;

    auto ans = new int[] (n);

    int now = 1;
    foreach_reverse (e; (n+1).iota.dropOne) {
        int idx = place[e];

        if (ans[idx] != 0) { continue; }

        debug { e.writeln; }

        ans[idx] = now;
        int idxr = adjr[idx], step = 1;
        while (step <= k && idxr < n) {
            ans[idxr] = now;
            idxr = adjr[idxr];
            ++step;
        }
        int idxle = adjle[idx];
        step = 1;
        while (step <= k && idxle >= 0) {
            ans[idxle] = now;
            idxle = adjle[idxle];
            ++step;
        }

        if (idxle >= 0) { adjr[idxle] = idxr; }
        if (idxr < n) { adjle[idxr] = idxle; }

        now = 3 - now;
    }

    ans.writefln!"%(%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, core.stdc.string;

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

    auto B = N.iota.map!(i => tuple(i, A[i])).array;
    B.sort!"a[1] > b[1]";

    auto L = N.iota.map!(i => i.to!int - 1).array;
    auto R = N.iota.map!(i => i.to!int + 1).array;

    auto ans = new int[](N);
    auto used = new bool[](N);

    for (int p = 0, t = 0; p < N; t ^= 1) {
        auto start = B[p][0];
        ans[start] = t + 1;
        used[start] = true;

        int new_l = -1, new_r = N;

        for (int j = 0, i = L[start]; j < K && i != -1; ++j, i = L[i], new_l = i) {
            ans[i] = t + 1;
            used[i] = true;
        }
        for (int j = 0, i = R[start]; j < K && i != N; ++j, i = R[i], new_r = i) {
            ans[i] = t + 1;
            used[i] = true;
        }

        if (new_l != -1) {
            R[new_l] = new_r;
        }
        if (new_r != N) {
            L[new_r] = new_l;
        }

        while (p < N && used[B[p][0]]) ++p;
    }

    ans.map!(a => a.to!string).join("").writeln;
}

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

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

const long mod = 1_000_000_007;

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

	int n = read.to!int;
	int k = read.to!int;

	Node[] nodes;
	foreach(i; 0 .. n){
		int a = read.to!int;
		nodes ~= new Node(i, a);
	}

	foreach(i; 0 .. n - 1){
		nodes[i].next = nodes[i + 1];
		nodes[i + 1].prev = nodes[i];
	}

	nodes.sort!"a.value>b.value"();

	int t = 1;
	foreach(nd; nodes){
		if(nd.isDone) continue;
		else{
			nd.setTeam(t);
			Node prev = nd.takePrev(t, k);
			Node next = nd.takeNext(t, k);
			if(prev) prev.next = next;
			if(next) next.prev = prev;
		}
		t = 3 - t;
	}

	nodes.sort!"a.id<b.id"();

	nodes.map!(nd => nd.team.to!string).array.join("").writeln;
}

class Node{
	int id;
	int value;
	int team;
	bool isDone = 0;
	Node prev, next;
	this(int id, int value){
		this.id = id;
		this.value = value;
	}
	void setTeam(int t){
		this.isDone = 1;
		this.team = t;
	}
	Node takePrev(int t, int k){
		this.setTeam(t);
		if(k == 0) return this.prev;
		else if(this.prev) return this.prev.takePrev(t, k - 1);
		else return null;
	}
	Node takeNext(int t, int k){
		this.setTeam(t);
		if(k == 0) return this.next;
		else if(this.next) return this.next.takeNext(t, k - 1);
		else return null;
	}
}

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

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

    auto B = N.iota.map!(i => tuple(i, A[i])).array;
    B.sort!"a[1] > b[1]";

    auto L = N.iota.map!(i => i.to!int - 1).array;
    auto R = N.iota.map!(i => i.to!int + 1).array;

    auto ans = new int[](N);
    auto used = new bool[](N);

    for (int p = 0, t = 0; p < N; t ^= 1) {
        auto start = B[p][0];
        ans[start] = t + 1;
        used[start] = true;

        int new_l, new_r;

        for (int j = 0, i = L[start]; j < K && i != -1; ++j, i = L[i], new_l = i) {
            ans[i] = t + 1;
            used[i] = true;
        }
        for (int j = 0, i = R[start]; j < K && i != N; ++j, i = R[i], new_r = i) {
            ans[i] = t + 1;
            used[i] = true;
        }

        if (new_l != -1) {
            R[new_l] = new_r;
        }
        if (new_r != N) {
            L[new_r] = new_l;
        }

        while (p < N && used[B[p][0]]) ++p;
    }

    ans.map!(a => a.to!string).join("").writeln;
}

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

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

const long mod = 1_000_000_007;

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

	int n = read.to!int;
	int k = read.to!int;

	Node[] nodes;
	foreach(i; 0 .. n){
		int a = read.to!int;
		nodes ~= new Node(i, a);
	}

	foreach(i; 0 .. n - 1){
		nodes[i].next = nodes[i + 1];
		nodes[i + 1].prev = nodes[i];
	}

	nodes.sort!"a.value>b.value"();

	int t = 1;
	foreach(nd; nodes){
		if(nd.isDone) continue;
		else{
			nd.setTeam(t);
			Node prev = nd.takePrev(t, k);
			Node next = nd.takeNext(t, k);
			if(prev) prev.next = next;
			if(next) next.prev = prev;
		}
		t = 3 - t;
	}

	nodes.sort!"a.id<b.id"();

	nodes.map!(nd => nd.team.to!string).array.join(" ").writeln;
}

class Node{
	int id;
	int value;
	int team;
	bool isDone = 0;
	Node prev, next;
	this(int id, int value){
		this.id = id;
		this.value = value;
	}
	void setTeam(int t){
		this.isDone = 1;
		this.team = t;
	}
	Node takePrev(int t, int k){
		this.setTeam(t);
		if(k == 0) return this.prev;
		else if(this.prev) return this.prev.takePrev(t, k - 1);
		else return null;
	}
	Node takeNext(int t, int k){
		this.setTeam(t);
		if(k == 0) return this.next;
		else if(this.next) return this.next.takeNext(t, k - 1);
		else return null;
	}
}


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

void play(){
    int n, k;
    n = rd!int, k = rd!int;
    dchar[] arr = rd!(dchar[]);
    auto g1 = redBlackTree!(true, int);
    auto g2 = redBlackTree!(true, int);
    int streak = 0, take = 0, w = 0;
    if(arr[0] == 'L') --streak;
    foreach(i; 0..n){
        if(arr[i] == 'W'){
            if(streak > 0){
                ++streak;
                if(streak % 2){
                    g1.insert(streak);
                }else{
                    g2.insert(streak);
                }
            }
            streak = 0;
            ++w;
            if(i > 0 && arr[i-1] == 'W') ++w;
        }else{
            streak += 2;
            ++take;
        }
    }
    if(!w && streak > 0 && k > 0){
        streak -= 1;
        w = 1;
        k -= 1;
    }
    if(streak > 0){
        if(streak % 2){
            g1.insert(streak);
        }else{
            g2.insert(streak);
        }
    }
    /* writeln(g1, g2); */

    ll pt = w;
    take = min(take, k);
    while(g1.length && take > 0){
        ll top = g1.front;
        if(top/2 <= take){
            pt += top;
            take -= top/2;
        }else{
            pt += take*2;
            take = 0;
        }
        g1.removeFront;
    }
    while(g2.length && take > 0){
        ll top = g2.front;
        if(top/2 <= take){
            pt += top;
            take -= top/2;
        }else{
            pt += take*2;
            take = 0;
        }
        g2.removeFront;
    }
    writeln(pt);
}

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

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
alias ll = long;
alias rbt = RedBlackTree;
alias sr = SortedRange;
alias tup = Tuple!(long, long);
static string[] inp;
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)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } 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();
        const K = readInt();
        const S = readToken();

        int ans;
        int k = K;
        chmin(k, cast(int)(S.count('L')));
        if (S.count('W') == 0) {
          ans = max(2 * k - 1, 0);
        } else {
          foreach (i; 0 .. N) {
            if (S[i] == 'W') {
              ans += (i - 1 >= 0 && S[i - 1] == 'W') ? 2 : 1;
            }
          }
          int[] ds;
          for (int i = 0, j; i < N; i = j) {
            for (j = i; j < N && S[i] == S[j]; ++j) {}
            if (S[i] == 'L' && !(i == 0 || j == N)) {
              ds ~= j - i;
            }
          }
          ds.sort;
          foreach (d; ds) {
            if (k >= d) {
              k -= d;
              ans += 2 * d + 1;
            }
          }
          ans += 2 * k;
        }
        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

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

string FMT_F = "%.10f";

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

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

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

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 k = RD!int;
		auto s = RD!string;

		auto cnt = new int[](n+1);
		int streak, lc;
		bool start;
		foreach (i; 0..n)
		{
			if (s[i] == 'W')
			{
				start = true;
				++cnt[streak];
				streak = 0;
				if (i == 0)
					++ans[ti];
				else if (s[i-1] == 'W')
					ans[ti] += 2;
				else
					++ans[ti];
			}
			else
			{
				if (start)
					++streak;
				++lc;
			}
		}
		debug writeln("ans:", ans[ti]);
		debug writeln(cnt);
		k = min(k, lc);

		foreach (i; 1..n+1)
		{
			auto c = min(k / i, cnt[i]);
			k -= i * c;
			if (c != 0)
				ans[ti] += c * (i * 2 + 1);
			debug writeln("k:", k, " ans:", ans[ti]);
		}
		if (start)
			ans[ti] += k * 2;
		else if (k >= 1)
			ans[ti] += (k-1) * 2 + 1;
	}

	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)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;
		auto s = readln.strip.map !(q{a == 'W'}).array;
		auto zeroes = s.count (0);
		auto ones = s.count (1);
		if (ones == 0)
		{
			writeln (max (0, k * 2 - 1));
			continue;
		}
		int start0 = 0;
		while (s.front == 0)
		{
			start0 += 1;
			s.popFront ();
		}
		int finish0 = 0;
		while (s.back == 0)
		{
			finish0 += 1;
			s.popBack ();
		}

		auto h = s.group.filter !(q{a[0] == 1}).count.to !(int);
		auto res = sum (s) * 2 - h;
		auto g = s.group.filter !(q{a[0] == 0}).map !(q{a[1]}).array;
		g.sort;
		while (k > 0 && !g.empty)
		{
			auto d = min (k, g.front);
			k -= d;
			res += 2 * d + (d == g.front);
			g.popFront ();
		}
		if (k > 0 && finish0 > 0)
		{
			auto d = min (k, finish0);
			k -= d;
			res += 2 * d;
		}
		if (k > 0 && start0 > 0)
		{
			auto d = min (k, start0);
			k -= d;
			res += 2 * d;
		}
		writeln (res);
	}
}

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

void play(){
    int n, k;
    n = rd!int, k = rd!int;
    dchar[] arr = rd!(dchar[]);
    auto gaps = redBlackTree!(true, tup);
    int streak = 0, take = 0, w = 0;
    if(arr[0] == 'L') --streak;
    foreach(i; 0..n){
        if(arr[i] == 'W'){
            ll val = streak + 1;
            if(streak > 0){ gaps.insert(tup(val/2, -val)); }
            streak = 0;
            ++w;
            if(i > 0 && arr[i-1] == 'W') ++w;
        }else{
            streak += 2;
            ++take;
        }
    }
    if(streak) gaps.insert(tup(streak/2, -streak));
    /* writeln(gaps); */

    ll pt = w;
    take = min(take, k);
    while(gaps.length && take > 0){
        ll top = - gaps.front[1];
        if(top/2 <= take){
            pt += top;
            take -= top/2;
        }else{
            pt += take*2;
            take = 0;
        }
        gaps.removeFront;
    }
    writeln(pt);
}

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

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
alias ll = long;
alias rbt = RedBlackTree;
alias sr = SortedRange;
alias tup = Tuple!(long, long);
static string[] inp;
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)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }

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

void play(){
    int n, k;
    n = rd!int, k = rd!int;
    dchar[] arr = rd!(dchar[]);
    auto g1 = redBlackTree!(true, int);
    auto g2 = redBlackTree!(true, int);
    int streak = 0, take = 0, w = 0;
    if(arr[0] == 'L') --streak;
    foreach(i; 0..n){
        if(arr[i] == 'W'){
            if(streak > 0){
                ++streak;
                if(streak % 2){
                    g1.insert(streak);
                }else{
                    g2.insert(streak);
                }
            }
            streak = 0;
            ++w;
            if(i > 0 && arr[i-1] == 'W') ++w;
        }else{
            streak += 2;
            ++take;
        }
    }
    if(!w && streak > 0 && k > 0){
        streak -= 1;
        w = 1;
        k -= 1;
    }
    if(streak > 0){
        if(streak % 2){
            g1.insert(streak);
        }else{
            g2.insert(streak);
        }
    }
    writeln(g1, g2);

    ll pt = w;
    take = min(take, k);
    while(g1.length && take > 0){
        ll top = g1.front;
        if(top/2 <= take){
            pt += top;
            take -= top/2;
        }else{
            pt += take*2;
            take = 0;
        }
        g1.removeFront;
    }
    while(g2.length && take > 0){
        ll top = g2.front;
        if(top/2 <= take){
            pt += top;
            take -= top/2;
        }else{
            pt += take*2;
            take = 0;
        }
        g2.removeFront;
    }
    writeln(pt);
}

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

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
alias ll = long;
alias rbt = RedBlackTree;
alias sr = SortedRange;
alias tup = Tuple!(long, long);
static string[] inp;
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)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }

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

void play(){
    int n, k;
    n = rd!int, k = rd!int;
    dchar[] arr = rd!(dchar[]);
    auto g1 = redBlackTree!(true, int);
    auto g2 = redBlackTree!(true, int);
    int streak = 0, take = 0, w = 0;
    if(arr[0] == 'L') --streak;
    foreach(i; 0..n){
        if(arr[i] == 'W'){
            if(streak > 0){
                ++streak;
                if(streak % 2){
                    g1.insert(streak);
                }else{
                    g2.insert(streak);
                }
            }
            streak = 0;
            ++w;
            if(i > 0 && arr[i-1] == 'W') ++w;
        }else{
            streak += 2;
            ++take;
        }
    }
    if(streak > 0){
        if(streak % 2){
            g1.insert(streak);
        }else{
            g2.insert(streak);
        }
    }
    /* writeln(g1, g2); */

    ll pt = w;
    take = min(take, k);
    while(g1.length && take > 0){
        ll top = g1.front;
        if(top/2 <= take){
            pt += top;
            take -= top/2;
        }else{
            pt += take*2;
            take = 0;
        }
        g1.removeFront;
    }
    while(g2.length && take > 0){
        ll top = g2.front;
        if(top/2 <= take){
            pt += top;
            take -= top/2;
        }else{
            pt += take*2;
            take = 0;
        }
        g2.removeFront;
    }
    writeln(pt);
}

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

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
alias ll = long;
alias rbt = RedBlackTree;
alias sr = SortedRange;
alias tup = Tuple!(long, long);
static string[] inp;
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)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }

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, k;
		readf !(" %s %s") (n, k);
		readln;
		auto s = readln.strip.map !(q{a == 'W'}).array;
		auto zeroes = s.count (0);
		auto ones = s.count (1);
		if (ones == 0)
		{
			writeln (max (0, k * 2 - 1));
			continue;
		}
		int start0 = 0;
		while (s.front == 0)
		{
			start0 += 1;
			s.popFront ();
		}
		int finish0 = 0;
		while (s.back == 0)
		{
			finish0 += 1;
			s.popBack ();
		}

		auto h = s.group.filter !(q{a[0] == 1}).count.to !(int);
		auto res = sum (s) * 2 - h;
		auto g = s.group.filter !(q{a[0] == 0}).map !(q{a[1]}).array;
		g.sort;
		while (k > 0 && !g.empty)
		{
			auto d = min (k, g.front);
			k -= d;
			res += 2 * d + (d == g.front);
			g.popFront ();
		}
		if (k > 0 && finish0 > 0)
		{
			auto d = min (k, finish0);
			k -= d;
			res += 2 * d;
		}
		if (k > 0 && start0 > 0)
		{
			auto d = min (k, start0);
			k -= d;
			res += 2 * d - 1 + (d == start0);
		}
		writeln (res);
	}
}

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, k;
		readf !(" %s %s") (n, k);
		readln;
		auto s = readln.strip.map !(q{a == 'W'}).array;
		auto zeroes = s.count (0);
		auto ones = s.count (1);
		if (ones == 0)
		{
			writeln (max (0, k * 2 - 1));
			continue;
		}
		int start0 = 0;
		while (s.front == 0)
		{
			start0 += 1;
			s.popFront ();
		}
		int finish0 = 0;
		while (s.back == 0)
		{
			finish0 += 1;
			s.popBack ();
		}

		auto h = s.group.filter !(q{a[0] == 1}).count.to !(int);
		auto res = sum (s) * 2 - h;
		auto g = s.group.filter !(q{a[0] == 0}).map !(q{a[1]}).array;
		g.sort;
		while (k > 0 && !g.empty)
		{
			auto d = min (k, g.front);
			k -= d;
			res += 2 * d + (d == g.front);
			g.popFront ();
		}
		if (k > 0 && finish0 > 0)
		{
			auto d = min (k, finish0);
			k -= d;
			res += 2 * d;
		}
		if (k > 0 && start0 > 0)
		{
			auto d = min (k, start0);
			k -= d;
			res += 2 * d - (d != start0);
		}
		writeln (res);
	}
}

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, k;
		readf !(" %s %s") (n, k);
		readln;
		auto s = readln.strip.map !(q{a == 'W'}).array;
		auto zeroes = s.count (0);
		auto ones = s.count (1);
		if (ones == 0)
		{
			writeln (max (0, k * 2 - 1));
			continue;
		}
		int start0 = 0;
		while (s.front == 0)
		{
			start0 += 1;
			s.popFront ();
		}
		int finish0 = 0;
		while (s.back == 0)
		{
			finish0 += 1;
			s.popBack ();
		}

		auto h = s.group.filter !(q{a[0] == 1}).count.to !(int);
		auto res = sum (s) * 2 - h;
		auto g = s.group.filter !(q{a[0] == 0}).map !(q{a[1]}).array;
		g.sort;
		while (k > 0 && !g.empty)
		{
			auto d = min (k, g.front);
			k -= d;
			res += 2 * d + (d == g.front);
			g.popFront ();
		}
		if (k > 0 && finish0 > 0)
		{
			auto d = min (k, finish0);
			k -= d;
			res += 2 * d;
		}
		if (k > 0 && start0 > 0)
		{
			auto d = min (k, start0);
			k -= d;
			res += 2 * d - (d == start0);
		}
		writeln (res);
	}
}

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, k;
		readf !(" %s %s") (n, k);
		readln;
		auto s = readln.strip.map !(q{a == 'W'}).array;
		writeln (s);
		auto zeroes = s.count (0);
		auto ones = s.count (1);
		if (ones == 0)
		{
			writeln (max (0, k * 2 - 1));
			continue;
		}
		int start0 = 0;
		while (s.front == 0)
		{
			start0 += 1;
			s.popFront ();
		}
		int finish0 = 0;
		while (s.back == 0)
		{
			finish0 += 1;
			s.popBack ();
		}

		auto h = s.group.filter !(q{a[0] == 1}).count.to !(int);
		auto res = sum (s) * 2 - h;
		auto g = s.group.filter !(q{a[0] == 0}).map !(q{a[1]}).array;
		g.sort;
		while (k > 0 && !g.empty)
		{
			auto d = min (k, g.front);
			k -= d;
			res += 2 * d + (d == g.front);
			g.popFront ();
		}
		if (k > 0 && finish0 > 0)
		{
			auto d = min (k, finish0);
			k -= d;
			res += 2 * d;
		}
		if (k > 0 && start0 > 0)
		{
			auto d = min (k, start0);
			k -= d;
			res += 2 * d;
		}
		writeln (res);
	}
}