import std.stdio: writefln, readf;
import std.string;
import std.conv: to;
import std.array: array;
import std.algorithm: map, sort, max;

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

	int l;
	readf(" %s", &l);

	int[] a = new int[n];
	foreach (ref x; a)
		readf(" %s", &x);
	a.sort;

	double dif = max(a[0], l - a[n-1]) * 2;
	for (int i = 1; i < n; i++) {
		dif = max(dif, a[i] - a[i - 1]);
	}

	dif /= 2.0;

	writefln("%.10f", dif);
}

import std.stdio;
import std.string;
import std.conv;
import std.regex;
import std.algorithm.iteration;
import std.algorithm.searching;
import std.algorithm.sorting;
import  std.array;
import std.range;
import std.algorithm.comparison;

void main()
{
  auto nl = stdin.readln.strip.split(regex(` +`)).map!(to!int).array;
  auto n = nl[0], l=nl[1];
  auto as = stdin.readln.strip.split(regex(` +`)).map!(to!int).array;
  double a = any!(a => a==l)(as) ? 0 : l - as.maxElement;
  double b = any!(a => a==0)(as) ? 0 : as.minElement;
  as.sort();
  writef("%.9f", max( (as.length>1 ? as.slide(2).map!"a[1]-a[0]".array.maxElement.to!double / 2:0), a, b));
}

import std.stdio;
import core.stdc.stdio;
import std.algorithm;

int main(string[] argv)
{
	int n;
	int l;
	scanf("%d %d", &n, &l);
	int[] lanterns; lanterns.length = n;
	foreach (int i; 0..n)
	{
		scanf("%d", &lanterns[i]);
	}
	lanterns.sort!("a < b");
	int max = (lanterns[0] - 0) * 2;
	foreach (int i; 1..lanterns.length)
	{
		int diff = lanterns[i] - lanterns[i-1];
		if (diff > max) max = diff;
	}
	if (((l - lanterns[$-1]) * 2) > max) max = (l - lanterns[$-1]) * 2;
	printf("%.10f", (cast(float)max / 2.0f));
	return 0;
}

import std.stdio: writefln, readf;
import std.string;
import std.conv: to;
import std.array: array;
import std.algorithm: map, sort, max;

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

	int[] a = new int[n];
	foreach (ref x; a)
		readf(" %d", &x);
	a.sort;

	int dif;
	double max_dif;
   	if (a[0] > l - a[n-1]) max_dif = a[0] * 2; else max_dif = (l - a[$-1]) * 2;
	foreach (int i; 1..n) {
		dif = a[i] - a[i - 1];
		if (dif > max_dif) max_dif = dif;
	}

	writefln("%.10f", max_dif / 2.0);
}

import std.stdio: writefln, readf;
import std.string;
import std.conv: to;
import std.array: array;
import std.algorithm: map, sort, max;

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

	int[] a = new int[n];
	foreach (ref x; a)
		readf(" %d", &x);
	a.sort;

	int dif;
	double max_dif = max(a[0], l - a[n-1]) * 2;
	foreach (int i; 1..n) {
		dif = a[i] - a[i - 1];
		if (dif > max_dif) max_dif = dif;
	}

	writefln("%.10f", max_dif / 2.0);
}

import std.stdio: writefln, readln;
import std.string;
import std.conv: to;
import std.array: array;
import std.algorithm: map, sort, max;

void main() {
	int[2] line = readln.chomp.split(" ").map!(to!int).array;
	int n = line[0];
	int l = line[1];

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

	double dif = max(a[0], l - a[n-1]) * 2;
	for (int i = 1; i < n; i++) {
		dif = max(dif, a[i] - a[i - 1]);
	}

	dif /= 2.0;

	writefln("%.10f", dif);
}

import std.stdio;
import std.algorithm;

void main() { while (solve()) {} }

bool solve() {
	int n;
	if (readf(" %s", &n) != 1) return false;

	int len;
	readf(" %s", &len);
	int[] a = new int[n];
	foreach (ref x; a)
		readf(" %s", &x);
	a.sort;
	int res = 0;
	foreach (i; 1..n) {
		res = max(res, a[i] - a[i - 1]);
	}
	res = max(res, max(len - a[$ - 1], a[0]) * 2);

	writef("%s", res / 2);
	if (res % 2 != 0)
		writef(".5");
	writeln;

	return true;
}

import std.stdio: writeln, readln;
import std.string;
import std.conv: to;
import std.array: array;
import std.algorithm: map, sort, max;

void main() {
	int[2] line = readln.chomp.split(" ").map!(to!int).array;
	int n = line[0];
	int l = line[1];

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

	float dif = max(a[0], l - a[a.count - 1]);
	for (int i = 1; i < n; i++) {
		dif = max(dif, (a[i] - a[i - 1]) / 2.0);
	}

	dif.writeln;
}


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

immutable long mod = 998_244_353;

void main()
{
    int n;
    readf!" %s "(n);
    string s = readln.strip;

    long pre = 0, post = 0;
    foreach (c; s) {
        if (c == s[0]) pre++;
        else break;
    }

    foreach_reverse (c; s) {
        if (c == s[n-1]) post++;
        else break;
    }

    long ans = 1 + pre + post;

    if (s[0] == s[n-1]) {
        ans = (ans + pre * post % mod) % mod;
    }

    writeln(ans);
}

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

  int n;
  rd(n);
  auto s = readln.chomp.to!(char[]);

  auto bf = new int[](26), af = new int[](26);
  int kind = 0;
  foreach (c; s) {
    af[c - 'a']++;
    if (af[c - 'a'] == 1) {
      kind++;
    }
  }
  int ans = 0, mod = 998244353;
  for (int i = 0, j = 0; i < n; i++) { // [i, j) remove
    while (j < n && kind >= 2) {
      if ((--af[s[j++] - 'a']) == 0) {
        kind--;
      }
    }
    if (kind == 1) {
      ans += (n - j + 1);
      ans %= mod;
    }
    if ((++af[s[i] - 'a']) == 1) {
      kind++;
    }
  }
  writeln(ans);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}

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

alias Tree = RBT!int;
alias ll = long;
const ll mod = 998244353;

void main() {
  GC.disable();

  int n;
  readf(" %s\n", n);
  string s = readln.strip;

  long sb = -1;
  foreach(i; 0 .. s.length) if (s[i] != s[0]) { sb = i; break; }

  long se = -1;
  foreach_reverse(i; 0 .. s.length) if (s[i] != s[$-1]) { se = i; break; }

  long ans = 1;
  if (sb == -1) {
    ans = (s.length * (s.length+1) / 2 ) % mod;
  } else if (s[0] == s[$-1]) {
    ans = ((sb + 1L) * ( s.length - se ) ) % mod;

  } else { // two different cases?
    ans =  ( (sb + 1) +  ( s.length - se)  - 1 ) % mod;
  }

  writeln(ans);

}

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

  int n;
  rd(n);
  auto s = readln.chomp.to!(char[]);

  auto bf = new int[](26), af = new int[](26);
  int kind = 0;
  foreach (c; s) {
    af[c - 'a']++;
    if (af[c - 'a'] == 1) {
      kind++;
    }
  }
  int ans = 0;
  for (int i = 0, j = 0; i < n; i++) { // [i, j) remove
    while (j < n && kind >= 2) {
      if ((--af[s[j++] - 'a']) == 0) {
        kind--;
      }
      // writeln(j, " ", kind);
    }
    if (kind == 1) {
      ans += (n - j + 1);
    }
    // writeln("! ", i, " ", j, " ", kind, " ", ans);
    // while (i <= j && kind < 2) {
    // if ((++af[s[i++] - 'a']) == 1) {
    // kind++;
    // }
    // if (kind == 1) {
    // ans++;
    // }
    // }
    if ((++af[s[i] - 'a']) == 1) {
      kind++;
    }
    // writeln(i, " ", j, " ", kind, " ", ans);
  }
  writeln(ans);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}

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

alias Tree = RBT!int;
alias ll = long;
const ll mod = 998244353;

void main() {
  GC.disable();

  int n;
  readf(" %s\n", n);
  string s = readln.strip;

  int sb = -1;
  foreach(i; 0 .. s.length) if (s[i] != s[0]) { sb = i; break; }

  int se = -1;
  foreach_reverse(i; 0 .. s.length) if (s[i] != s[$-1]) { se = i; break; }

  long ans = 1;
  if (sb == -1) {
    ans = (s.length * (s.length+1) / 2 ) % mod;
  } else if (s[0] == s[$-1]) {
    ans = ((sb + 1) * ( s.length - se ) ) % mod;

  } else { // two different cases?
    ans =  ( (sb + 1) +  ( s.length - se)  - 1 ) % mod;
  }

  writeln(ans);

}


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

immutable string vowels = "aeiou";

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		string [] res;
main_loop:
		while (!s.empty)
		{
			foreach (i; 2..s.length)
			{
				if (!vowels.canFind (s[i - 2]) &&
				    !vowels.canFind (s[i - 1]) &&
				    !vowels.canFind (s[i - 0]) &&
				    (s[i - 2] != s[i - 1] ||
				    s[i - 1] != s[i - 0]))
				{
					res ~= s[0..i];
					s = s[i..$];
					continue main_loop;
				}
			}
			res ~= s;
			s = "";
		}
		res.join (" ").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)); }

bool isCon(char c) {
  return (" aeiou".indexOf(c) == -1);
}

bool isBad(char a, char b, char c) {
  return (isCon(a) && isCon(b) && isCon(c) && !(a == b && a == c));
}

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

      string ans;
      foreach (c; S) {
        for (; ans.length >= 2 && isBad(ans[$ - 2], ans[$ - 1], c); ) {
          ans ~= ' ';
        }
        ans ~= c;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


import std;

alias range = Tuple!(int, "l", int, "r");

void main () {
    immutable tests = to!int(readln().dropBackOne);

    foreach (test_index; 0 .. tests) {
        immutable n = to!int(readln().dropBackOne);

        immutable x = stdin
            .byLine
            .take(n)
            .map!(l => range(l.split.to!(int[2])))
            .array
            .sort!"a.r - a.l < b.r - b.l"
            .release
            .assumeUnique;

        auto notSeen = redBlackTree(iota(1, n + 1));
        auto viz     = new bool[n + 1];

        foreach (_, t; x) {
            immutable num = (){
                if (!viz[t.l])
                    return t.l;
                if (!viz[t.r])
                    return t.r;
                return notSeen.upperBound(t.l).front;
            }();

            writefln!"%s %s %s"(t.l, t.r, num);
            viz[num] = true;
            notSeen.removeKey(num);
        }

        writeln();
    }
}
// ""

import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,
       std.container, std.typecons, std.conv, std.random, std.bigint;

void read(S...)(ref S args) {
  auto input = readln.split;
  enforce(input.length == args.length);
  foreach (i, ref arg; args) {
    arg = input[i].to!(S[i]);
  }
}

auto list(T)() { return readln.split.map!(e => e.to!T).array; }

void main() {
  int T;
  read(T);
  while (T--) {
    int n;
    read(n);

    int[][] arr = new int[][n];

    foreach (i; 0 .. n) {
      arr[i] = list!int;
    }

    foreach (range; arr) {
      if (range.front == range.back) {
        writeln(range.front, ' ', range.back, ' ', range.back);
      } else if (arr.canFind([range.front + 1, range.back])) {
        writeln(range.front, ' ', range.back, ' ', range.front);
      } else if (arr.canFind([range.front, range.back - 1])) {
        writeln(range.front, ' ', range.back, ' ', range.back);
      } else {
        foreach (d; range.front + 1 .. range.back) {
          if (arr.canFind([range.front, d - 1]) && arr.canFind([d + 1, range.back])) {
            writeln(range.front, ' ', range.back, ' ', d);
          }
        }
      }
    }
  }
}

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 int[][][](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto lr = new int[][](n);
		foreach (i; 0..n)
			lr[i] = [RD!int, RD!int];

		lr.sort!("a[0] == b[0] ? a[1] > b[1] : a[0] < b[0]");
		foreach (i; 1..n)
		{
			if (lr[i-1][0] == lr[i-1][1])
				ans[ti] ~= lr[i-1] ~ lr[i-1][0];
			else
			{
				if (lr[i-1][0] != lr[i][0])
					ans[ti] ~= lr[i-1] ~ (lr[i][0]-1);
				else
					ans[ti] ~= lr[i-1] ~ (lr[i][1]+1);
			}
		}
		ans[ti] ~= lr[n-1] ~ lr[n-1][0];
	}

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

// 提出解
void solve(){
	foreach(_; 0 .. scan!int){
		int n = scan!int;
		int[][] us = new int[][](n), vs = new int[][](n);
			// us[a][]: 左端がaである右端、vs[b][]:右端がbである左端
		foreach(i; 0 .. n){
			int l = scan!int - 1, r = scan!int - 1;
			us[l] ~= r, vs[r] ~= l;
		}
		foreach(i; 0 .. n) us[i].sort!"a>b";
		foreach(i; 0 .. n) vs[i].sort!"a<b";
		foreach(i; 0 .. n) foreach(r, j; us[i]){
			if(r == us[i].length - 1) print(i + 1, j + 1, i + 1);
			else print(i + 1, j + 1, us[i][r + 1] + 1 + 1);
		}
	}
}

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
// 愚直解
void jury(){
}

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
// テストケース
void gen(){
}

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
// テンプレ
import std;
bool DEBUG = 0;
void main(string[] args){
	if(args.canFind("-debug")) DEBUG = 1;
	if(args.canFind("-gen")) gen; else if(args.canFind("-jury")) jury; else solve;
}
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){ stdout.write(t, " "), print(a); }
string unsplit(T)(T xs, string d = " "){ return xs.array.to!(string[]).join(d); }
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 mini(T)(ref T x, T y){ if(x > y) x = y; return x; }
T maxi(T)(ref T x, T y){ if(x < y) x = y; return x; }
T mid(T)(T l, T r, bool delegate(T) f){
	T m = (l + r) / 2; (f(m)? l: r) = m; return f(l)? f(r - 1)? r: mid(l, r, f): l;
}

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
// ライブラリ（基本）

class UnionFind{
	this(int n){ foreach(i; 0 .. n) R ~= i, K ~= [i]; } int[] R; int[][] K;
	void unite(int a, int b){
		int ra = R[a], rb = R[b]; if(ra == rb) return;
		if(K[ra].length < K[rb].length) unite(b, a);
		else foreach(k; K[rb]) R[k] = ra, K[ra] ~= k;
	}
	int find(int a){ return R[a]; }
	int getSize(int a){ return K[R[a]].length.to!int; }
}
class Queue(T){
	private T[] xs; private uint i, j;
	this(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }
	uint length(){ return j - i; }
	bool isEmpty(){ return j == i; }
	void enq(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }
	T deq(){ assert(i < j); return xs[i ++]; }
	T peek(){ assert(i < j); return xs[i]; }
	void flush(){ i = j; }
	alias empty = isEmpty, front = peek, popFront = deq, pop = deq, push = enq, top = peek;
	Queue opOpAssign(string op)(T x) if(op == "~"){ enq(x); return this; }
	T opIndex(uint li){ assert(i + li < j); return xs[i + li]; }
	static Queue!T opCall(T[] xs){ return new Queue!T(xs); }
	T[] array(){ return xs[i .. j]; }
	override string toString(){ return array.to!string; }
}
class Stack(T){
	private T[] xs; private uint j;
	this(T[] xs = []){ this.xs = xs; j = xs.length.to!uint; }
	uint length(){ return j; }
	bool isEmpty(){ return j == 0; }
	void push(T x){ while(j + 1 >= xs.length) xs.length = xs.length * 2 + 1; xs[j ++] = x; }
	T pop(){ assert(j > 0); return xs[-- j]; }
	T peek(){ assert(j > 0); return xs[j - 1]; }
	void clear(){ j = 0; }
	alias empty = isEmpty, front = peek, popFront = pop, top = peek;
	Stack opOpAssign(string op)(T x) if(op == "~"){ push(x); return this; }
	T opIndex(uint li){ assert(j > 0 && j - 1 >= li); return xs[j - 1 - li]; }
	static Stack!T opCall(T[] xs = []){ return new Stack!T(xs); }
	T[] array(){ return xs[0 .. j]; }
	override string toString(){ return array.to!string; }
}

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
// ライブラリ（追加）

void main() { runSolver(); }

void problem() {
  auto QN = scan!long;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto R = scan!int(N * 2).chunks(2).array;
      string[] ans;

      bool[1001] visited;
      foreach(lr; R.sort!"(a[1] - a[0]).abs < (b[1] - b[0]).abs") {
        int n;
        foreach(m; lr[0]..lr[1] + 1) {
          if (!visited[m]) {
            n = m;
            visited[m] = true;
            break;
          }
        }
        ans ~= [lr[0], lr[1], n].toAnswerString;
      }

      ans.each!writeln;
    }

    foreach(i; 0..QN) {
      if (i > 0) "".writeln;
      subSolve();
    }
  }

  outputForAtCoder(&solve);
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
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)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

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

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}

import std;

alias range = Tuple!(int, "l", int, "r");

void main () {
    immutable tests = to!int(readln().dropBackOne);

    foreach (test_index; 0 .. tests) {
        immutable n = to!int(readln().dropBackOne);

        immutable x = stdin
            .byLine
            .take(n)
            .map!(l => range(l.split.to!(int[2])))
            .array
            .sort!"a.r - a.l < b.r - b.l"
            .release
            .assumeUnique;

        auto notSeen = redBlackTree(iota(1, n + 1));
        auto viz     = new bool[n + 1];

        foreach (_, t; x) {
            assert(t.l == t.r || viz[t.l] || viz[t.r]);

            immutable num = (){
                if (!viz[t.l])
                    return t.l;
                if (!viz[t.r])
                    return t.r;
                return notSeen.upperBound(t.l).back;
            }();

            writefln!"%s %s %s"(t.l, t.r, num);
            viz[num] = true;
            notSeen.removeKey(num);
        }

        writeln();
    }
}
// ""


import std.stdio;

void read(T...)(ref T args)
{
  import std.traits;
  static foreach(i; 0 .. T.length)
    static if(isArray!(T[i]))
      foreach(ref e; args[i])
	read(e);
    else
      readf!" %s"(args[i]);
}
alias r = read;
alias w = writeln;

int main()
{
  int n;
  r(n);
  foreach(e; 0 .. n)
    {
      int c, sum;
      r(c, sum);
	{
	  int avg = sum / c;
	  int residue = sum % c;
	  if (residue > 0)
	    {
	      w(avg * avg * (c - residue) + (avg + 1) * (avg + 1) * residue);
	    }
	  else
	    {
	      w(avg * avg * c);
	    }
	}
    }

  return 0;
}

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

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

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

void main()
{
	auto n = RD!int;
	auto ans = new int[](n);
	foreach (i; 0..n)
	{
		auto c = RD!int;
		auto sum = RD!int;
		auto x = sum / c;
		auto y = sum % c;
		ans[i] += ((x+1)^^2) * y;
		ans[i] += (x^^2) * (c - y);
	}

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

import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
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 rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

void solve(){
	int n = rint;
	foreach(i; 0 .. n){
		long c = rlong, s = rlong;
		long x = s / c, d = s % c;
		long ans = (c - d) * x * x + d * (x + 1) * (x + 1);
		ans.writeln;
	}
}


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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).uniq.array;
		a = [-2, -1] ~ a;
		n = a.length;
		int res = 0;
		bool [int] seen;
		foreach (i; 2..n)
		{
			auto cur = a[i];
			if (cur == a[i - 2])
			{
				seen = null;
				seen[a[i - 1]] = true;
				seen[a[i]] = true;
			}
			else if (cur in seen)
			{
				seen = null;
				seen[a[i - 1]] = true;
				seen[a[i]] = true;
			}
			else
			{
				seen[a[i]] = true;
				res += 1;
			}
		}
		writeln (res);
	}
}

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 (; ; ) {
      int N = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }
      A = A.uniq.array;
      N = cast(int)(A.length);
      debug {
        writeln("A = ", A);
      }

      const lim = A.maxElement + 1;
      auto app = new int[lim];
      app[] = -1;
      auto dp = new int[N + 1];
      foreach (i; 0 .. N) {
        dp[i + 1] = dp[i];
        const j = app[A[i]];
        if (j != -1) {
          chmax(dp[i + 1], dp[j + 2] + 1);
          if (j - 1 >= 0 && A[j - 1] == A[j + 1]) {
            chmax(dp[i + 1], dp[j + 1] + 2);
          }
        }
        app[A[i]] = i;
      }
      writeln(N - dp[N]);

      debug {
        int brt = N;
        foreach (p; 0 .. 1 << N) {
          int cost;
          int[2] bs = [-1, -1];
          foreach (i; 0 .. N) {
            const s = (p >> i) & 1;
            if (bs[s] != A[i]) {
              ++cost;
              bs[s] = A[i];
            }
          }
          chmin(brt, cost);
        }
        writeln("brt = ", brt);
        assert(brt == N - dp[N]);
      }
    }
  } catch (EOFException e) {
  }
}

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

void main(){
    auto n = scan!int;
    auto arr = scanArray!int;
    auto seen = redBlackTree!int;
    int[] seg1, seg2;
    int[] cur;

    seg1 ~= arr[0];
    int i = 1;
    while(i < n && arr[i] == seg1.back){
        seg1 ~= arr[i];
        ++i;
    }
    if(i < n){
        seg2 ~= arr[i]; ++i;
        seen.insert([seg1.back, seg2.back]);
    }

    while(i < n){
        if(cur.length && arr[i] == cur.back){
            cur ~= arr[i];
        }else if(arr[i] in seen){
            if(arr[i] == seg2.back){
                seg2 ~= arr[i];
                foreach(el; cur){
                    if(el == arr[i]){
                        seg2 ~= el;
                    }else{
                        seg1 ~= el;
                    }
                }
            }else{
                seg1 ~= arr[i];
                foreach(el; cur){
                    if(el == arr[i]){
                        seg1 ~= el;
                    }else{
                        seg2 ~= el;
                    }
                }
            }

            // Reset seen & cur
            seen.clear;
            seen.insert([seg1.back, seg2.back]);
            cur = [];
        }else{
            cur ~= arr[i];
            seen.insert(arr[i]);
        }
        ++i;
    }
    // Post while
    seg2 ~= cur;
    cur = []; seen.clear;

    show(seg1, seg2);

    // Calc Answer
    auto res = 1;
    for(int k = 1; k < seg1.length; ++k){
        if(seg1[k] != seg1[k-1]){ ++res; }
    }
    res += (seg2.length > 0);
    for(int k = 1; k < seg2.length; ++k){
        if(seg2[k] != seg2[k-1]){ ++res; }
    }

    writeln(res);
}

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

import std.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 N; get(N);
    int[] aa; get(aa);
    auto nxt = new int[][10^^5 + 1];
    foreach (i, a; aa) nxt[a] ~= i.to!int;

    int x, y, c;
    foreach (a; aa) {
        nxt[a].popFront();
        if (a == x || a == y) continue;
        if (nxt[x].empty) {
            x = a;
        } else if (nxt[y].empty) {
            y = a;
        } else if (nxt[x].front > nxt[y].front) {
            x = a;
        } else {
            y = a;
        }
        ++c;
    }
    writeln(c);
}

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

void main(){
    auto n = scan!int;
    auto arr = scanArray!int;
    auto seen = redBlackTree!int;
    int[] seg1, seg2;
    int[] cur;

    seg1 ~= arr[0];
    int i = 1;
    while(i < n && arr[i] == seg1.back){
        seg1 ~= arr[i];
        ++i;
    }
    if(i < n){
        seg2 ~= arr[i]; ++i;
        seen.insert([seg1.back, seg2.back]);
    }

    while(i < n){
        if(cur.length && arr[i] == cur.back){
            cur ~= arr[i];
        }else if(arr[i] in seen){
            if(arr[i] == seg2.back){
                seg2 ~= arr[i];
                foreach(el; cur){
                    if(el == arr[i]){
                        seg2 ~= el;
                    }else{
                        seg1 ~= el;
                    }
                }
            }else{
                seg1 ~= arr[i];
                foreach(el; cur){
                    if(el == arr[i]){
                        seg1 ~= el;
                    }else{
                        seg2 ~= el;
                    }
                }
            }

            // Reset seen & cur
            seen.clear;
            seen.insert([seg1.back, seg2.back]);
            cur = [];
        }else{
            cur ~= arr[i];
        }
        ++i;
    }
    // Post while
    seg2 ~= cur;
    cur = []; seen.clear;

    show(seg1, seg2);

    // Calc Answer
    auto res = 1;
    for(int k = 1; k < seg1.length; ++k){
        if(seg1[k] != seg1[k-1]){ ++res; }
    }
    res += (seg2.length > 0);
    for(int k = 1; k < seg2.length; ++k){
        if(seg2[k] != seg2[k-1]){ ++res; }
    }

    writeln(res);
}

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

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

void main(){
    auto n = scan!int;
    auto arr = scanArray!int;
    auto seen = redBlackTree!int;
    int[] seg1, seg2;
    int[] cur;

    seg1 ~= arr[0];
    int i = 1;
    while(i < n && arr[i] == seg1.back){
        seg1 ~= arr[i];
        ++i;
    }
    if(i < n){
        seg2 ~= arr[i]; ++i;
        seen.insert([seg1.back, seg2.back]);
    }

    while(i < n){
        if(arr[i] in seen){
            if(arr[i] == seg2.back){
                seg1 ~= cur;
                seg2 ~= arr[i];
            }else{
                seg1 ~= arr[i];
                foreach(el; cur){
                    if(el == arr[i]){
                        seg1 ~= el;
                    }else{
                        seg2 ~= el;
                    }
                }
            }

            // Reset seen & cur
            seen.clear;
            seen.insert([seg1.back, seg2.back]);
            cur = [];
        }else{
            cur ~= arr[i];
        }
        ++i;
    }
    // Post while
    seg2 ~= cur;
    cur = []; seen.clear;

    show(seg1, seg2);

    // Calc Answer
    auto res = 1;
    for(int k = 1; k < seg1.length; ++k){
        if(seg1[k] != seg1[k-1]){ ++res; }
    }
    res += (seg2.length > 0);
    for(int k = 1; k < seg2.length; ++k){
        if(seg2[k] != seg2[k-1]){ ++res; }
    }

    writeln(res);
}

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

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

void main ()
{
	int n;
	while (readf !(" %s") (n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		int res = 0;
		int [2] [] p = [[-1, -1]];
		foreach (ref c; a)
		{
			int [2] [] [2] q;
			int next = res;
			foreach (ref prev; p)
			{
				foreach (j; 0..2)
				{
					auto good = (prev[j] != c);
					q[good] ~= [c, prev[!j]];
	                	}
			}
			foreach_reverse (j; 0..2)
			{
				if (!q[j].empty)
				{
					res = next + j;
					p = q[j];
				}
			}
			foreach (ref prev; p)
			{
				sort (prev[]);
			}
			p = p.sort.uniq.take (4).array;
		}
		writeln (res);
	}
}


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.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

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

    auto s = readln.chomp;
    auto cost = s.map!(x => 1 + (x == 'w' ? b : 0)).array;

    debug { cost.writeln; }

    if (cost[0] > T) {
        writeln(0);
        return;
    }

    n -= 1;
    T -= cost[0];
    cost = cost.dropOne;

    int go(int[] rightcost, int[] leftcost, int n, int T) {
        auto ans = 0;
        auto leftsum = leftcost.sum + a * n;
        auto leftidx = n;
        auto rightsum = 0;
        auto rightidx = 0;
        while (rightidx < n) {
            rightsum += rightcost[rightidx] + a;
            ++rightidx;
            leftsum += a;

            while (leftsum + rightsum > T && leftidx > 0) {
                leftidx -= 1;
                leftsum -= leftcost[leftidx] + a;
            }

            if (rightsum <= T) {
                ans = max(ans, rightidx);
                if (leftsum + rightsum <= T) {
                    ans = max(ans, min(n, leftidx + rightidx));
                }
            }

            debug { writeln([rightidx, rightsum, leftidx, leftsum, ans].map!(to!string).join(" ")); }
        }

        return ans;
    }

    auto costrev = cost.dup.retro().array;

    int ans = 1 + max(go(cost, costrev, n, T), go(costrev, cost, n, T));
    ans.writeln;
}

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, a, b, t;
	while (readf (" %s %s %s %s", &n, &a, &b, &t) > 0)
	{
		readln;
		auto p = readln.strip.map !(q{a == 'w'}).array;
		auto q = p.dup;
		reverse (q[1..$]);
		t -= p[0] * b;
		t--;

		long [] fun (bool [] r)
		{
			auto res = [0L];
			res.reserve (n);
			foreach (i; 1..n)
			{
				res ~= res.back + a + b * r[i] + 1;
			}
			return res;
		}

		auto gp = fun (p);
		auto gq = fun (q);

		int solve (long [] fp, long [] fq)
		{
			int res = 0;
			int j = 0;
			while (j < n && fq[j] <= t)
			{
				j++;
			}
			j--;
			res = max (res, j);

			foreach (i; 1..n)
			{
				if (t < fp[i])
				{
					break;
				}
				res = max (res, i);
				while (j > 0 && t < fp[i] + fq[j] + i * a)
				{
					j--;
				}
				res = max (res, i + j);
			}
			return res;
		}

		int res = max (solve (gp, gq), solve (gq, gp));
		res = min (res, n - 1);
		if (t >= 0)
		{
			res++;
		}
		writeln (res);
	}
}

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.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

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

    auto s = readln.chomp;
    auto cost = s.map!(x => 1 + (x == 'w' ? b : 0)).array;

    debug { cost.writeln; }

    if (cost[0] > T) {
        writeln(0);
        return;
    }

    T -= cost[0];
    cost = cost.dropOne;

    int go(int[] rightcost, int[] leftcost, int n, int T) {
        auto ans = 0;
        auto leftsum = leftcost.sum + a * n;
        auto leftidx = n;
        auto rightsum = 0;
        auto rightidx = 0;
        while (rightidx < n) {
            rightsum += rightcost[rightidx] + a;
            ++rightidx;
            leftsum += a;

            while (leftsum + rightsum > T && leftidx > 0) {
                leftidx -= 1;
                leftsum -= leftcost[leftidx] + a;
            }

            if (rightsum <= T) {
                ans = max(ans, rightidx);
                if (leftsum + rightsum <= T) {
                    ans = max(ans, min(n, leftidx + rightidx));
                }
            }

            debug { writeln([rightidx, rightsum, leftidx, leftsum, ans].map!(to!string).join(" ")); }
        }

        return ans;
    }

    auto costrev = cost.dup.retro().array;

    int ans = 1 + max(go(cost, costrev, n-1, T), go(costrev, cost, n-1, T));
    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)); }

int N, K;
debug {
  int[] A;
}

bool Ask(int x, int y) {
  bool ret;
  debug {
    int xm = N, ym = N;
    foreach (a; A) {
      chmin(xm, abs(x - a));
      chmin(ym, abs(y - a));
    }
    ret = (xm <= ym);
    writefln("Ask %s %s = %s", x, y, ret);
  } else {
    writefln("1 %s %s", x, y);
    stdout.flush;
    const res = readToken();
    ret = (res == "TAK");
  }
  return ret;
}

void Answer(int x, int y) {
  writefln("2 %s %s", x, y);
  stdout.flush;
  debug {
    assert(A.count(x) > 0);
    assert(A.count(y) > 0);
  }
}

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

  int solve(int lo, int hi, int ini = 0) {
    for (; lo + 1 < hi; ) {
      int mid = (lo + hi) / 2;
      if (ini == 1) {
        mid = (lo + lo + hi) / 3;
        ini = 0;
      }
      if (ini == 2) {
        mid = (lo + hi + hi) / 3;
        ini = 0;
      }
      if (Ask(mid, mid + 1)) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
    }
    return Ask(lo, hi) ? lo : hi;
  }

  int ans0, ans1;

  ans0 = solve(1, N);
  if (1 <= ans0 - 1) {
    const res = solve(1, ans0 - 1, 1);
    if (Ask(res, ans0)) {
      ans1 = res;
    }
  }
  if (!ans1) {
    ans1 = solve(ans0 + 1, N, 2);
  }

  Answer(ans0, ans1);
}

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 K = s[1];

    int hi = N - 1;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }
    int ans1 = hi;

    if (hi >= 2) {
        hi = hi - 1;
        lo = 0;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            writeln(1, " ", mid, " ", mid + 1);
            stdout.flush;
            if (readln.chomp == "TAK") hi = mid;
            else lo = mid;
        }

        writeln(1, " ", hi, " ", ans1);
        stdout.flush;
        if (readln.chomp == "TAK") {
            writeln(2, " ", hi, " ", ans1);
            return;
        }
    }

    hi = N + 1;
    lo = ans1 + 1;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid - 1);
        stdout.flush;
        if (readln.chomp == "TAK") lo = mid;
        else hi = mid;
    }

    writeln(2, " ", ans1, " ", lo);
}

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 K = s[1];

    int hi = N - 1;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }
    int ans1 = hi;

    if (hi >= 2) {
        hi = hi - 1;
        lo = 0;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            writeln(1, " ", mid, " ", mid + 1);
            stdout.flush;
            if (readln.chomp == "TAK") hi = mid;
            else lo = mid;
        }

        writeln(1, " ", hi, " ", ans1);
        stdout.flush;
        if (readln.chomp == "TAK") {
            writeln(2, " ", hi, " ", ans1);
            return;
        }
    }

    hi = N;
    lo = ans1;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid - 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }

    writeln(2, " ", ans1, " ", hi);
}

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 K = s[1];

    int hi = N - 1;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }
    int ans1 = hi;

    if (hi >= 2) {
        hi = hi - 1;
        lo = 0;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            writeln(1, " ", mid, " ", mid + 1);
            stdout.flush;
            if (readln.chomp == "TAK") hi = mid;
            else lo = mid;
        }

        writeln(1, " ", hi, " ", ans1);
        stdout.flush;
        if (readln.chomp == "TAK") {
            writeln(2, " ", hi, " ", ans1);
            return;
        }
    }

    hi = N + 1;
    lo = ans1 + 1;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid - 1);
        stdout.flush;
        if (readln.chomp == "TAK") lo = mid;
        else hi = mid;
    }

    writeln(2, " ", ans1, " ", hi);
}

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 K = s[1];

    int hi = N;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo)/ 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }
    int ans1 = hi;

    hi = N + 1;
    lo = 1;
    while (hi - lo > 1) {
        int mid = (hi + lo)/ 2;
        writeln(1, " ", mid, " ", mid - 1);
        stdout.flush;
        if (readln.chomp == "TAK") lo = mid;
        else hi = mid;
    }
    int ans2 = lo;

    writeln(2, " ", ans1, " ", ans2);
}

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 K = s[1];

    int hi = N - 1;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }
    int ans1 = hi;

    hi = N + 1;
    lo = 2;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid - 1);
        stdout.flush;
        if (readln.chomp == "TAK") lo = mid;
        else hi = mid;
    }
    int ans2 = lo;

    writeln(2, " ", ans1, " ", ans2);
}

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 K = s[1];

    int hi = N - 1;
    int lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }
    int ans1 = hi;

    hi = hi - 1;
    lo = 0;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid + 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }

    writeln(1, " ", hi, " ", ans1);
    stdout.flush;
    if (readln.chomp == "TAK") {
        writeln(2, " ", hi, " ", ans1);
        return;
    }

    hi = N;
    lo = ans1;
    while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        writeln(1, " ", mid, " ", mid - 1);
        stdout.flush;
        if (readln.chomp == "TAK") hi = mid;
        else lo = mid;
    }

    writeln(2, " ", ans1, " ", hi);
}

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 N, K;
debug {
  int[] A;
}

bool Ask(int x, int y) {
  bool ret;
  debug {
    int xm = N, ym = N;
    foreach (a; A) {
      chmin(xm, abs(x - a));
      chmin(ym, abs(y - a));
    }
    ret = (xm <= ym);
    writefln("Ask %s %s = %s", x, y, ret);
  } else {
    writefln("1 %s %s", x, y);
    stdout.flush;
    const res = readToken();
    ret = (res == "TAK");
  }
  return ret;
}

void Answer(int x, int y) {
  writefln("2 %s %s", x, y);
  stdout.flush;
  debug {
    assert(A.count(x) > 0);
    assert(A.count(y) > 0);
  }
}

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

  int ans0, ans1;
  {
    int lo = 1, hi = N;
    for (; lo + 1 < hi; ) {
      const mid = (lo + hi) / 2;
      (Ask(lo, hi) ? hi : lo) = mid;
    }
    ans0 = Ask(lo, hi) ? lo : hi;
  }
  if (1 <= ans0 - 1) {
    int lo = 1, hi = ans0 - 1;
    for (; lo + 1 < hi; ) {
      const mid = (lo + hi) / 2;
      (Ask(lo, hi) ? hi : lo) = mid;
    }
    const x = Ask(lo, hi) ? lo : hi;
    if (Ask(x, ans0)) {
      ans1 = x;
    }
  }
  if (!ans1) {
    int lo = ans0 + 1, hi = N;
    for (; lo + 1 < hi; ) {
      const mid = (lo + hi) / 2;
      (Ask(lo, hi) ? hi : lo) = mid;
    }
    ans1 = Ask(lo, hi) ? lo : hi;
  }

  Answer(ans0, ans1);
}

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 N, K;
debug {
  int[] A;
}

bool Ask(int x, int y) {
  bool ret;
  debug {
    int xm = N, ym = N;
    foreach (a; A) {
      chmin(xm, abs(x - a));
      chmin(ym, abs(y - a));
    }
    ret = (xm <= ym);
    writefln("Ask %s %s = %s", x, y, ret);
  } else {
    writefln("1 %s %s", x, y);
    stdout.flush;
    const res = readToken();
    ret = (res == "TAK");
  }
  return ret;
}

void Answer(int x, int y) {
  writefln("2 %s %s", x, y);
  stdout.flush;
  debug {
    assert(A.count(x) > 0);
    assert(A.count(y) > 0);
  }
}

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

  int solve(int lo, int hi, int ini = 0) {
    for (; lo + 1 < hi; ) {
      int mid = (lo + hi) / 2;
      if (ini == 1) {
        mid = (lo + lo + hi) / 3;
        ini = 0;
      }
      if (ini == 2) {
        mid = (lo + hi + hi) / 3;
        ini = 0;
      }
      if (Ask(mid, mid + 1)) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
    }
    return Ask(lo, hi) ? lo : hi;
  }

  int ans0, ans1;

  ans0 = solve(1, N);
  if (1 <= ans0 - 1) {
    ans1 = solve(1, ans0 - 1, 1);
  }
  if (!Ask(ans1, ans0)) {
    ans1 = solve(ans0 + 1, N, 2);
  }

  Answer(ans0, ans1);
}

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 N, K;
debug {
  int[] A;
}

bool Ask(int x, int y) {
  bool ret;
  debug {
    int xm = N, ym = N;
    foreach (a; A) {
      chmin(xm, abs(x - a));
      chmin(ym, abs(y - a));
    }
    ret = (xm <= ym);
    writefln("Ask %s %s = %s", x, y, ret);
  } else {
    writefln("1 %s %s", x, y);
    stdout.flush;
    const res = readToken();
    ret = (res == "TAK");
  }
  return ret;
}

void Answer(int x, int y) {
  writefln("2 %s %s", x, y);
  stdout.flush;
  debug {
    assert(A.count(x) > 0);
    assert(A.count(y) > 0);
  }
}

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

  int solve(int lo, int hi) {
    for (; lo + 1 < hi; ) {
      const mid = (lo + hi) / 2;
      (Ask(lo, hi) ? hi : lo) = mid;
    }
    return Ask(lo, hi) ? lo : hi;
  }

  int ans0, ans1;

  ans0 = solve(1, N);
  for (int e = 0; ans0 + (1 << e) <= N; ++e) {
    if (Ask(ans0 + (1 << e), ans0 + (1 << e) - 1)) {
      ans1 = solve(ans0 + (1 << e) - 1, N);
      goto found;
    }
  }
  for (int e = 0; ans0 + (1 << e) <= N; ++e) {
    if (Ask(ans0 - (1 << e), ans0 - (1 << e) + 1)) {
      ans1 = solve(1, ans0 - (1 << e) + 1);
      goto found;
    }
  }
 found:

  Answer(ans0, ans1);
}


//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 ();
  auto ans = new int[nt];
  foreach (tid; 0 .. nt) {
    const uint n = r.next!uint();
    const uint x = r.next!uint();
    auto a = r.nextA!uint (n);
    int res = int.max;
    int check (const int k) {
      if (x < k) {
        return 2;
      }
      int t = x / k;
      if (x % k) ++t;
      return t;
    }
    foreach_reverse (k; a) {
      res = min (res, check (k));
    }
    ans[tid] = res;
  }
  writefln!"%(%s\n%)"(ans);
}

import std.stdio : writeln;

struct IO {
    string readToken() {
        import std.range : empty, front, popFront, split;
        import std.stdio : readln;

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

    int readInt() {
        import std.conv : to;

        return readToken.to!int;
    }

    string[] tokens;
}

void main() {
    import std.algorithm : max, maxElement;

    IO io;
    int T = io.readInt;
    while (T--) {
        int n = io.readInt;
        int x = io.readInt;
        int[] a = new int[n];
        bool found = false;
        for (int i = 0; i < n; ++i) {
            a[i] = io.readInt;
            found |= a[i] == x;
        }
        if (found) {
            writeln(1);
        }
        else {
            int maxa = a.maxElement;
            writeln(max(2, (x + maxa - 1) / maxa));
        }
    }
}

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

string FMT_F = "%.10f";

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

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

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

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

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto x = RD;
		auto a = RDA;
		bool isOne;
		long y;
		foreach (i; 0..n)
		{
			if (a[i] == x)
				isOne = true;
			y.chmax(a[i]);
		}
		if (isOne)
			ans[ti] = 1;
		else
			ans[ti] = max(2, (x+y-1) / y);
	}

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

// https://codeforces.com/problemset/problem/1307/B
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;
    foreach(_; 0..t) {
        int n, x;
        readf("%s %s\n", &n, &x);

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

        if(a.count(x) > 0) {
            1.writeln;
            continue;
        }

        long ans = max(2, ceil(real(x)/a[$-1])).to!long;
        writefln("%s", ans);
    }
}

// https://codeforces.com/problemset/problem/1307/B
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;
    foreach(_; 0..t) {
        int n, x;
        readf("%s %s\n", &n, &x);

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

        if(a.count(x) > 0) {
            1.writeln;
            continue;
        }

        writefln("%s", max(2, ceil(real(x)/a[$-1])));
    }
}

// https://codeforces.com/problemset/problem/1307/B
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;
    foreach(_; 0..t) {
        int n, x;
        readf("%s %s\n", &n, &x);

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

        if(a.count(x) > 0) {
            1.writeln;
            continue;
        }

        writefln("%s", max(2, ceil(real(x/a[$-1]))));
    }
}

// https://codeforces.com/problemset/problem/1307/B
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;
    foreach(_; 0..t) {
        int n, x;
        readf("%s %s\n", &n, &x);

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

        if(a.count(x) > 0) {
            1.writeln;
            continue;
        }

        max(2, ceil(real(x)/a[$-1])).writeln;
    }
}

// https://codeforces.com/problemset/problem/1307/B
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    int t = readln.chomp.to!int;
    foreach(_; 0..t) {
        int n, x;
        readf("%s %s\n", &n, &x);
        int[] a = readln.split.map!(to!int).array;
        a.sort();
        writefln("%s", max(2, x/a[$-1]+1));
    }
}

//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 ();
  auto ans = new int[nt];
  foreach (tid; 0 .. nt) {
    const uint n = r.next!uint();
    const uint x = r.next!uint();
    auto a = r.nextA!uint (n);
    bool[int] h;
    foreach (i; a) h[i] = true;
    sort (a);
    int res = int.max;
    int check (const int k) {
      int t = x / k;
      if (t >= res) return t;
      const int z = x % k;
      //debug stderr.writefln ("Case %d: t = %d, x = %d", tid + 1, t, x);
      if (!z) {
      } else if (z in h) ++t;
      else {
        t += 2;
      }
      return t;
    }
    foreach_reverse (k; a) {
      res = min (res, check (k));
    }
    ans[tid] = res;
  }
  writefln!"%(%s\n%)"(ans);
}


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

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    int n;
    n = rd!int;
    ll den = n;
    ll num = 0;
    ll sum = 0, fsum = 0, rsum = 0;
    ll[] arr = rdarr;
    arr.sort;
    foreach(i; 0..arr.length){
        sum += arr[i];
        fsum += i * arr[i];
        rsum += (n - i - 1) * arr[i];
    }
    num = sum + 2 * (fsum - rsum);
    ll gcdd = gcd(num, den);
    num /= gcdd;
    den /= gcdd;
    writeln(num, " ", den);
}

void main(){
    long t = 1;
    /* t = rd; */
    while(t--) solve();
    stdout.flush;
}

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

immutable int MAX_N = 100_005;
immutable int MAX_C = 0x3F3F3F3F;
immutable int NA    = -1;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [n + 1];
		a[0] = 0;
		foreach (i; 0..n)
		{
			readf (" %s", &a[i + 1]);
		}
		a.sort !("a < b", SwapStrategy.stable);
		long num = 0;
		auto s = new long [n + 1];
		s[0] = 0;
		foreach (i; 0..n)
		{
			num += a[i + 1];
			s[i + 1] = s[i] + a[i + 1];
		}
//		num *= n - 1;
		debug {writeln (num);}
		foreach (i; 0..n)
		{
			long cur = s[n] - s[i + 1];
			cur -= a[i + 1] * cast (long) (n - i - 1);
//			cur *= (n - 1);
			cur *= 2;
			debug {writefln ("%s: %s", i, cur);}
			num += cur;
		}
		long den = n;
//		den *= n - 1;
		auto d = gcd (num, den);
		num /= d;
		den /= d;
		writeln (num, ' ', den);
	}
}

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

immutable int MAX_N = 100_005;
immutable int MAX_C = 0x3F3F3F3F;
immutable int NA    = -1;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		auto a = new int [n + 1];
		a[0] = 0;
		foreach (i; 0..n)
		{
			readf (" %s", &a[i + 1]);
		}
		long num = 0;
		auto s = new long [n + 1];
		s[0] = 0;
		foreach (i; 0..n)
		{
			num += a[i + 1];
			s[i + 1] = s[i] + a[i + 1];
		}
//		num *= n - 1;
		debug {writeln (num);}
		foreach (i; 0..n)
		{
			long cur = s[n] - s[i + 1];
			cur -= a[i + 1] * cast (long) (n - i - 1);
//			cur *= (n - 1);
			cur *= 2;
			debug {writefln ("%s: %s", i, cur);}
			num += cur;
		}
		long den = n;
//		den *= n - 1;
		auto d = gcd (num, den);
		num /= d;
		den /= d;
		writeln (num, ' ', den);
	}
}

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

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    int n;
    n = rd!int;
    ll den = n;
    ll num = 0;
    ll sum = 0, fsum = 0, rsum = 0;
    ll[] arr = rdarr;
    foreach(i; 0..arr.length){
        sum += arr[i];
        fsum += i * arr[i];
        rsum += (n - i - 1) * arr[i];
    }
    num = sum + (n - 1) * (fsum - rsum);
    ll gcdd = gcd(num, den);
    num /= gcdd;
    den /= gcdd;
    writeln(num, " ", den);
}

void main(){
    long t = 1;
    /* t = rd; */
    while(t--) solve();
    stdout.flush;
}

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

alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, long);
static string[] inp;
T rd(T = long)(){ while(!inp.length) inp = readln.chomp.split; string res = inp[0]; inp.popFront; return res.to!T; }
T[] rdarr(T = long)(T fix = 0){ auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }

void solve(){
    int n;
    n = rd!int;
    ll den = n;
    ll num = 0;
    ll sum = 0, fsum = 0, rsum = 0;
    ll[] arr = rdarr;
    foreach(i; 0..arr.length){
        sum += arr[i];
        fsum += i * arr[i];
        rsum += (n - i - 1) * arr[i];
    }
    num = sum + 2 * (fsum - rsum);
    ll gcdd = gcd(num, den);
    num /= gcdd;
    den /= gcdd;
    writeln(num, " ", den);
}

void main(){
    long t = 1;
    /* t = rd; */
    while(t--) solve();
    stdout.flush;
}


// Vicfred
// https://codeforces.com/contest/1542/problem/B
// math, greedy
import std.container;
import std.stdio;

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

while(t--) {
    long n, a, b;
    readf("%s %s %s\n", &n, &a, &b);
    if(a == 1L) {
        if((n - 1L) % b == 0L)
            "Yes".writeln;
        else
            "No".writeln;
        continue;
    }
    auto powers = new RedBlackTree!(long,"a > b");
    powers.insert(1L);
    while(powers.front <= n) {
        powers.insert(powers.front * a);
    }
    if(powers.front > n)
        powers.removeFront;
    n = n % b;
    bool found = false;
    while(!powers.empty) {
        if(powers.front % b == n)
            found = true;
        powers.removeFront;
    }
    if(found)
        "Yes".writeln;
    else
        "No".writeln;
}
}

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

string FMT_F = "%.10f";

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

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

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

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

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

		long x = 1;
		if (a == 1)
		{
			auto rem = n - x;
			ans[ti] = rem % b == 0;
		}
		else
		{
			while (x <= n)
			{
				if ((n-x) % b == 0)
				{
					ans[ti] = true;
					break;
				}
				x *= a;
			}
		}
	}

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

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;

ulong a, b;

bool is_good(ulong n)
{
  ulong val = 1;
  while (true) {
    if (val > n)
      return false;
    if ((n - val) % b == 0)
      return true;
    val *= a;
  }
}

void main()
{
  int t;
  readf!" %d "(t);
  while (t--) {
    ulong n;
    readf!" %d %d %d "(n, a, b);

    if (a == 1) {
      if ((n - 1) % b == 0)
        writeln("Yes");
      else
        writeln("No");
      continue;
    }

    if (is_good(n))
      writeln("Yes");
    else
      writeln("No");
  }
}

// code by cutx64

module main;

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

void main() {

  int tests; readf!"%s\n"(tests);
  immutable(long) mod = 10 ^^ 9 + 7;
  while(tests--) {
    long n, a, b;
    readf!"%s %s %s\n"(n, a, b);
    if (a == 1) {
      if ((n - 1) % b == 0) {
        "Yes".writeln;
      }
      else {
        "No".writeln;
      }
    }
    else {
      bool flag = false;
      for (int i = 0; (a ^^ i) <= n; ++i) {
        if ((n - (a ^^ i)) % b == 0) {
          "Yes".writeln;
          flag = true;
          break;
        }
      }
      if (!flag) "No".writeln;
    }
  }

} // main

// Vicfred
// https://codeforces.com/contest/1542/problem/B
// math, greedy
import std.container;
import std.stdio;

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

while(t--) {
    long n, a, b;
    readf("%s %s %s\n", &n, &a, &b);
    if(a == 1) {
        if((n - 1) % b == 0)
            "Yes".writeln;
        else
            "No".writeln;
        continue;
    }
    auto powers = new RedBlackTree!(long,"a > b");
    powers.insert(1L);
    while(powers.front < n) {
        powers.insert(powers.front * a);
    }
    if(powers.front >= n)
        powers.removeFront;
    n = n % b;
    bool found = false;
    while(!powers.empty) {
        if(powers.front % b == n)
            found = true;
        powers.removeFront;
    }
    if(found)
        "Yes".writeln;
    else
        "No".writeln;
}
}

// Vicfred
// https://codeforces.com/contest/1542/problem/B
// math, greedy
import std.container;
import std.stdio;

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

while(t--) {
    long n, a, b;
    readf("%s %s %s\n", &n, &a, &b);
    if(a == 1) {
        if((n - 1) % b == 0)
            "Yes".writeln;
        else
            "No".writeln;
        continue;
    }
    auto powers = new RedBlackTree!(long,"a > b");
    powers.insert(1L);
    while(powers.front < n) {
        powers.insert(powers.front * a);
    }
    powers.removeFront;
    n = n % b;
    bool found = false;
    while(!powers.empty) {
        if(powers.front % b == n)
            found = true;
        powers.removeFront;
    }
    if(found)
        "Yes".writeln;
    else
        "No".writeln;
}
}

// Vicfred
// https://codeforces.com/contest/1542/problem/B
// math, greedy
import std.container;
import std.stdio;

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

while(t--) {
    long n, a, b;
    readf("%s %s %s\n", &n, &a, &b);
    if(a == 1) {
        if((n - 1) % b == 0)
            "Yes".writeln;
        else
            "No".writeln;
        continue;
    }
    auto powers = new RedBlackTree!(long,"a > b");
    powers.insert(1L);
    while(powers.front <= n) {
        powers.insert(powers.front * a);
    }
    n = n % b;
    bool found = false;
    while(!powers.empty) {
        if(powers.front % b == n)
            found = true;
        powers.removeFront;
    }
    if(found)
        "Yes".writeln;
    else
        "No".writeln;
}
}

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;

ulong a, b;

bool is_good(ulong n)
{
  ulong val = 1;
  while (true) {
    if (val > n)
      return false;
    if ((n - val) % b == 0)
      return true;
    val *= a;
  }
}

void main()
{
  int t;
  readf!" %d "(t);
  while (t--) {
    ulong n;
    readf!" %d %d %d "(n, a, b);

    if (a == 1) {
      if (n % b == 1)
        writeln("Yes");
      else
        writeln("No");
      continue;
    }

    if (is_good(n))
      writeln("Yes");
    else
      writeln("No");
  }
}

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 a, b;

bool is_good(long n)
{
  long x = 0;

  long val = 1;
  while (true) {
    if (val > n)
      return false;
    if ((n - val) % b == 0)
      return true;
    val *= a;
  }
}

void main()
{
  int t;
  readf!" %d "(t);
  while (t--) {
    long n;
    readf!" %d %d %d "(n, a, b);

    if (a == 1) {
      if (n % b == 1)
        writeln("Yes");
      else
        writeln("No");
      continue;
    }

    if (is_good(n))
      writeln("Yes");
    else
      writeln("No");
  }
}

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 a, b;

bool is_good(long n)
{
  long x = 0;

  long val = 1;
  while (true) {
    val *= a;
    if (val > n)
      return false;
    if ((n - val) % b == 0)
      return true;
  }
}

void main()
{
  int t;
  readf!" %d "(t);
  while (t--) {
    long n;
    readf!" %d %d %d "(n, a, b);

    if (a == 1) {
      if (n % b == 1)
        writeln("Yes");
      else
        writeln("No");
      continue;
    }

    if (is_good(n))
      writeln("Yes");
    else
      writeln("No");
  }
}

// code by cutx64

module main;

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

void main() {

  int tests; readf!"%s\n"(tests);
  immutable(long) mod = 10 ^^ 9 + 7;
  while(tests--) {
    long n, a, b;
    readf!"%s %s %s\n"(n, a, b);
    if (a == 1) {
      if ((n - 1) % b == 0) {
        "Yes".writeln;
      }
      else {
        "No".writeln;
      }
    }
    else {
      bool flag = false;
      for (int i = 0; (a ^^ i) <= n; ++i) {
        if ((n - (a ^^ i)) % b == 0) {
          "Yes".writeln;
          flag = true;
        }
      }
      if (!flag) "No".writeln;
    }
  }

} // main


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;
		a.sort();
		auto b = a.dup;

		int tot;
		while (!a.empty)
		{
			if (tot+a.front != 0)
			{
				tot += a.front;
				ans[ti] ~= a.front;
				a.popFront;
			}
			else if (tot+a.back != 0)
			{
				tot += a.back;
				ans[ti] ~= a.back;
				a.popBack;
			}
			else
			{
				ans[ti].length = 0;
				break;
			}
		}
		if (ans[ti].empty)
		{
			tot = 0;
			a = b;
			debug writeln(a);
			while (!a.empty)
			{
				if (tot+a.back != 0)
				{
					tot += a.back;
					ans[ti] ~= a.back;
					a.popBack;
				}
				else if (tot+a.front != 0)
				{
					tot += a.front;
					ans[ti] ~= a.front;
					a.popFront;
				}
				else
				{
					ans[ti].length = 0;
					break;
				}
				debug writeln("ans:", ans[ti]);
			}
		}
	}

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

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;

        const ASum = A.sum;
        if (ASum == 0) {
          writeln("NO");
        } else {
          if (ASum > 0) {
            A.reverse;
          }
          writeln("YES");
          foreach (i; 0 .. N) {
            if (i > 0) write(" ");
            write(A[i]);
          }
          writeln;
        }
      }
    }
  } catch (EOFException e) {
  }
}

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

void play(){
    int n;
    n = rd!int;
    ll[] arr = rdarr;
    sort(arr);
    ll pls = 0, mins = 0;
    foreach(el; arr){
        if(el < 0){
            mins += el;
        }else{
            pls += el;
        }
    }
    if((mins + pls) == 0){
        writeln("NO");
    }else{
        writeln("YES");
        if(-mins < pls){
            reverse(arr);
        }
        arr.each!((el)=> write(el, " "));
        writeln;
    }
}

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)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		auto s = a.sum;
		if (s == 0)
		{
			writeln ("NO");
			continue;
		}
		sort (a);
		if (s > 0)
		{
			reverse (a);
		}
		writeln ("YES");
		writefln !("%(%s %)") (a);
	}
}

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;
		sort (a);
		if (sum (a) == 0)
		{
			writeln ("NO");
		}
		else
		{
			writefln !("%(%s %)") (a);
		}
	}
}

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

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		auto s = a.sum;
		if (s == 0)
		{
			writeln ("NO");
			continue;
		}
		sort (a);
		if (s > 0)
		{
			reverse (a);
		}
		writefln !("%(%s %)") (a);
	}
}


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

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

    if (m < n-1) {
        writeln("Impossible");
        return;
    }

    Tuple!(int, int)[] ans;

    outer: foreach (i; 1 .. n+1) {
        foreach (j; i+1 .. n+1) {
            if (gcd(i, j) > 1) continue;

            ans ~= tuple(i, j);

            if (ans.length == m) break outer;
        }
    }

    if (ans.length < m) {
        writeln("Impossible");
        return;
    }

    writeln("Possible");
    ans.each!(t => writeln(t[0], ' ', t[1]));
}

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

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

    if (M < N - 1) {
        writeln("Impossible");
        return;
    }

    auto X = new int[][](N+1);
    auto Y = new int[][](N+1);

    foreach (i; 2..N+1) {
        if (!X[i].empty) continue;
        for (int j = i; j <= N; j += i) {
            X[j] ~= i;
            Y[i] ~= j;
        }
    }

    int cnt = 0;
    auto ans = new Tuple!(int, int)[](M);

    foreach (i; 2..N+1) {
        ans[cnt] = tuple(1, i);
        cnt += 1;
    }

    for (int i = N - (1 - N%2); i > 2 && cnt < M; i -= 2) {
        auto tmp = new bool[](i);
        foreach (j; X[i]) foreach (k; Y[j]) if (k < i) tmp[k] = true;
        for (int j = 2; j < i && cnt < M; ++j) if (!tmp[j]) ans[cnt] = tuple(j, i), cnt++;
    }
    for (int i = N - N%2; i > 1 && cnt < M; i -= 2) {
        auto tmp = new bool[](i);
        foreach (j; X[i]) foreach (k; Y[j]) if (k < i) tmp[k] = true;
        for (int j = 2; j < i && cnt < M; ++j) if (!tmp[j]) ans[cnt] = tuple(j, i), cnt++;
    }

    if (cnt == M) {
        writeln("Possible");
        ans.each!(a => writeln(a[0], " ", a[1]));
    } else {
        writeln("Impossible");
    }
}

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

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

    if (M < N - 1) {
        writeln("Impossible");
        return;
    }

    auto X = new int[][](N+1);
    auto Y = new int[][](N+1);

    foreach (i; 2..N+1) {
        if (!X[i].empty) continue;
        for (int j = i; j <= N; j += i) {
            X[j] ~= i;
            Y[i] ~= j;
        }
    }

    int cnt = 0;
    auto ans = new Tuple!(int, int)[](M);

    foreach (i; 2..N+1) {
        ans[cnt] = tuple(1, i);
        cnt += 1;
    }

    for (int i = N - (1 - N%2); i > 2 && cnt < M; --i) {
        auto tmp = new bool[](i);
        foreach (j; X[i]) foreach (k; Y[j]) if (k < i) tmp[k] = true;
        for (int j = 2; j < i && cnt < M; ++j) if (!tmp[j]) ans[cnt] = tuple(j, i), cnt++;
    }
    for (int i = N - N%2; i > 1 && cnt < M; --i) {
        auto tmp = new bool[](i);
        foreach (j; X[i]) foreach (k; Y[j]) if (k < i) tmp[k] = true;
        for (int j = 2; j < i && cnt < M; ++j) if (!tmp[j]) ans[cnt] = tuple(j, i), cnt++;
    }

    if (cnt == M) {
        writeln("Possible");
        ans.each!(a => writeln(a[0], " ", a[1]));
    } else {
        writeln("Impossible");
    }
}