import std.stdio;

long power(long a, long b, long mod) {
  if (b && ! (a % mod)) return 0;
  long ret = 1;
  while (b) {
    if (b & 1) (ret *= a) %= mod;
    (a *= a) %= mod, b >>= 1;
  }
  return ret;
}

long inv(long a, long p) {
  return power(a, p - 2, p);
}

int main() {
  int T; readf(" %d", &T);
  while (T--) {
    long k, l, r, p, q, ans;
    readf(" %d %d %d %d", &k, &l, &r, &p), q = p - 1;
    if (p == 2) {
      if (k & 1) writeln(0); else writeln(1);
      continue;
    }
    ans = (power(k, power(2, l, q) + q, p) + q) % p;
    if (! ans) ans = power(2, r - l + 1, p);
    else ans = (power(k, power(2, r + 1, q) + q, p) + q) * inv(ans, p) % p;
    if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;
    writeln(ans);
  }
  return 0;
}

import std.stdio;

long power(long a, long b, long mod) {
  if (b && ! (a % mod)) return 0;
  long ret = 1;
  while (b) {
    if (b & 1) (ret *= a) %= mod;
    (a *= a) %= mod, b >>= 1;
  }
  return ret;
}

long inv(long a, long p) {
  return power(a, p - 2, p);
}

int main() {
  int T; readf(" %d", &T);
  while (T--) {
    long k, l, r, p, ans;
    readf(" %d %d %d %d", &k, &l, &r, &p);
    if (p == 2) {
      if (k & 1) writeln(0); else writeln(1);
      continue;
    }
    ans = (power(k, power(2, l, p - 1) + p - 1, p) + p - 1) % p;
    if (! ans) ans = power(2, r - l + 1, p);
    else ans = (power(k, power(2, r + 1, p - 1) + p - 1, p) + p - 1) * inv(ans, p) % p;
    if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;
    writeln(ans);
  }
  return 0;
}

import std.stdio;

int T;

long power(long a, long b, long mod) {
  if (b && ! (a % mod)) return 0;
  long ret = 1;
  while (b) {
    if (b & 1) (ret *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return ret;
}

long inv(long a, long p) {
  return power(a, p - 2, p);
}

int main() {
  readf(" %d", &T);
  while (T--) {
    long k, l, r, p, ans;
    readf(" %d %d %d %d", &k, &l, &r, &p);
    if (p == 2) {
      if (k & 1) writeln(0);
      else writeln(1);
      continue;
    }
    ans = (power(k, power(2, l, p - 1) + p - 1, p) + p - 1) % p;
    if (! ans) ans = power(2, r - l + 1, p);
    else ans = (power(k, power(2, r + 1, p - 1) + p - 1, p) + p - 1) % p * inv(ans, p) % p;
    if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;
    writeln(ans);
  }
  return 0;
}

import std.stdio;

int T;

long power(long a, long b, long mod) {
  long ret = 1;
  while (b) {
    if (b & 1) (ret *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return ret;
}

long inv(long a, long p) {
  return power(a, p - 2, p);
}

int main() {
  readf(" %d", &T);
  while (T--) {
    long k, l, r, p, ans;
    readf(" %d %d %d %d", &k, &l, &r, &p);
    if (p == 2) {
      if (k & 1) writeln(0);
      else writeln(1);
      continue;
    }
    ans = power(k, power(2, l, p - 1), p) - 1;
    if (! ans) ans = power(2, r - l + 1, p);
    else ans = (power(k, power(2, r + 1, p - 1), p) - 1) * inv(ans, p);
    if (k & 1) ans *= power((p >> 1) + 1, r - l, p);
    writeln(ans);
  }
  return 0;
}

import std.stdio;

int T;

long power(long a, long b, long mod) {
  long ret = 1;
  while (b) {
    if (b & 1) (ret *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return ret;
}

long inv(long a, long p) {
  return power(a, p - 2, p);
}

int main() {
  readf(" %d", &T);
  while (T--) {
    long k, l, r, p, ans;
    readf(" %d %d %d %d", &k, &l, &r, &p);
    if (p == 2) {
      if (k & 1) writeln(0);
      else writeln(1);
      continue;
    }
    ans = power(k, power(2, l, p), p) - 1;
    if (! ans) ans = power(2, r - l + 1, p);
    else ans = (power(k, power(2, r + 1, p), p) - 1) * inv(ans, p);
    writeln(ans);
  }
  return 0;
}

import std.stdio;

long power(long a, long b, long mod) {
  if (b && ! (a % mod)) return 0;
  long ret = 1;
  while (b) {
    if (b & 1) (ret *= a) %= mod;
    (a *= a) %= mod, b >>= 1;
  }
  return ret;
}

long inv(long a, long p) {
  return power(a, p - 2, p);
}

int main() {
  int T; readf(" %d", &T);
  while (T--) {
    long k, l, r, p, ans;
    readf(" %d %d %d %d", &k, &l, &r, &p);
    if (p == 2) {
      if (k & 1) writeln(0); else writeln(1);
      continue;
    }
    ans = power(k, power(2, l, p - 1) + p - 1, p) + p - 1;
    if (! ans) ans = power(2, r - l + 1, p);
    else ans = (power(k, power(2, r + 1, p - 1) + p - 1, p) + p - 1) * inv(ans, p) % p;
    if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;
    writeln(ans);
  }
  return 0;
}

import std.stdio;

int T;

long power(long a, long b, long mod) {
  long ret = 1;
  while (b) {
    if (b & 1) (ret *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return ret;
}

long inv(long a, long p) {
  return power(a, p - 2, p);
}

int main() {
  readf(" %d", &T);
  while (T--) {
    long k, l, r, p, ans;
    readf(" %d %d %d %d", &k, &l, &r, &p);
    if (p == 2) {
      if (k & 1) writeln(0);
      else writeln(1);
      continue;
    }
    ans = power(k, power(2, l, p), p) - 1;
    if (! ans) ans = power(2, r - l + 1, p);
    else ans = (power(k, power(2, r + 1, p), p) - 1) * inv(ans, p);
    if (k & 1) ans *= power((p >> 1) + 1, r - l, p);
    writeln(ans);
  }
  return 0;
}

import std.stdio;

int T;

long power(long a, long b, long mod) {
  if (! a) return 0;
  long ret = 1;
  while (b) {
    if (b & 1) (ret *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return ret;
}

long inv(long a, long p) {
  return power(a, p - 2, p);
}

int main() {
  readf(" %d", &T);
  while (T--) {
    long k, l, r, p, ans;
    readf(" %d %d %d %d", &k, &l, &r, &p);
    if (p == 2) {
      if (k & 1) writeln(0);
      else writeln(1);
      continue;
    }
    k %= p;
    ans = power(k, power(2, l, p - 1), p) + p - 1;
    if (! ans) ans = power(2, r - l + 1, p);
    else ans = (power(k, power(2, r + 1, p - 1), p) + p - 1) * inv(ans, p) % p;
    if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;
    writeln(ans);
  }
  return 0;
}

import std.stdio;

int T;

long power(long a, long b, long mod) {
  if (! (a % mod)) return 0;
  long ret = 1;
  while (b) {
    if (b & 1) (ret *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return ret;
}

long inv(long a, long p) {
  return power(a, p - 2, p);
}

int main() {
  readf(" %d", &T);
  while (T--) {
    long k, l, r, p, ans;
    readf(" %d %d %d %d", &k, &l, &r, &p);
    if (p == 2) {
      if (k & 1) writeln(0);
      else writeln(1);
      continue;
    }
    ans = (power(k, power(2, l, p - 1), p) + p - 1) % p;
    if (! ans) ans = power(2, r - l + 1, p);
    else ans = (power(k, power(2, r + 1, p - 1), p) + p - 1) % p * inv(ans, p) % p;
    if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;
    writeln(ans);
  }
  return 0;
}

import std.stdio;

int T;

long power(long a, long b, long mod) {
  if (! a) return 0;
  long ret = 1;
  while (b) {
    if (b & 1) (ret *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return ret;
}

long inv(long a, long p) {
  return power(a, p - 2, p);
}

int main() {
  readf(" %d", &T);
  while (T--) {
    long k, l, r, p, ans;
    readf(" %d %d %d %d", &k, &l, &r, &p);
    if (p == 2) {
      if (k & 1) writeln(0);
      else writeln(1);
      continue;
    }
    k %= p;
    ans = (power(k, power(2, l, p - 1), p) + p - 1) % p;
    if (! ans) ans = power(2, r - l + 1, p);
    else ans = (power(k, power(2, r + 1, p - 1), p) + p - 1) % p * inv(ans, p) % p;
    if (k & 1) (ans *= power((p >> 1) + 1, r - l, p)) %= p;
    writeln(ans);
  }
  return 0;
}


import std.stdio,std.range,std.algorithm,std.regex,std.conv,std.string;
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
void main()
{
	int t;
	while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			auto aut=arread!string;
			int m;
			input(&m);
			auto a=new int[m], g=new int[][m],mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln.strip;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].split(regex("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.split(regex("[ ?.,:!]+"));;
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int[105][105] dp, table;
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

import std.stdio,std.range,std.algorithm,std.regex,std.conv,std.string;
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
void main()
{
	int t;
	while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			auto aut=arread!string;
			int m;
			input(&m);
			auto a=new int[m], g=new int[][m],mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln.strip;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].splitter(ctRegex!("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.splitter(ctRegex!("[ ?.,:!]+"));;
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int[105][105] dp, table;
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

import std.stdio,std.range,std.algorithm,std.string,std.regex,std.conv;
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
void main()
{
	int t;
	loop:while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			readln;
			auto aut=arread!string;
			int m;
			input(&m);
			readln;
			auto a=new int[m];
			auto g=new int[][m];
			auto mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln.strip;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].strip.split(regex("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.strip.split(regex("[ ?.,:!]+"));
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int[105][105] dp, table;
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
alias mp=make_pair;
alias bins=binary_search;
alias orsq=orient_square;
immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	X binpow(X,Y)(X base,Y exp)
		if(is(typeof(exp&1)))
	{
		if(exp<0)return X(0);
		X res=X(1);
		while(exp>0)
		{
			if(exp&1)res*=base;
			base*=base;
			exp>>=1;
		}
		return res;
	}
	auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
		if(is(typeof(exp&1)))
	{
		if(mm==0) return binpow(base,exp);
		if(exp<0)return X(0);
		auto res=X(1)%mm;
		while(exp>0)
		{
			if(exp&1)res=(res*base)%mm;
			base*=base;
			base%=mm;
			exp>>=1;
		}
		return res;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
	V foldr(R,V,T)(R range,T arg,V nach)
		if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))
	{
		for(;!range.empty;range.popFront()) nach=arg(nach,range.front);
		return nach;
	}
	size_t countr(R,T)(R range,T fun)
		if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))
	{
		size_t nach;
		for(;!range.empty;range.popFront()) nach+=fun(range.front);
		return nach;
	}
	T orient_square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
	{
		auto n=figure.front,t=figure.front;
		figure.popFront();
		T ans=0;
		for(;!figure.empty;figure.popFront())
		{
			ans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);
			t=figure.front;
		}
		return ans+(n.fi-t.fi)*(n.se+t.se);
	}
	real square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
	{
		return abs(orient_square(figure))/2.000000000000000;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n,in size_t m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))
	{
		fi=p.fi;
		se=p.se;
	}
	pair!(X,Y) opAssign(A,B)(pair!(A,B) val)
	{
		return this=pair!(X,Y)(val);
	}
	int opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe
		if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
struct Tree(T,alias arg="a+b")
{
	private alias fun=binaryFun!arg;
	private static const size_t n=size_t.max>>1;
	private T[size_t] t;
	this(this){t=t.dup;}
	this(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))
	{
		foreach(pos,i;range) upd(pos,i);
	}
	this(R,alias f)(Tree!(R,f) q) if(is(R:T))
	{
		foreach(i,j;q.t)
		{
			t[i]=j;
		}
	}
	Tree!(T,arg) opAssign(R)(R val)
	{
		return this=Tree!(T,arg)(val);
	}
	private void upd(in size_t v,in size_t vl,in size_t vr,in size_t i,in T x)
	{
		if (vr - vl == 1){t[v] = x;return;}
		size_t vm = (vl + vr) >> 1;
		if(i < vm) upd(2*v, vl, vm, i, x);
		else upd(2*v+1, vm, vr, i, x);
		if(v*2+1 !in t)t[v]=t[v*2];
		else if (v*2 !in t)t[v]=t[v*2+1];
		else t[v]=fun(t[v*2],t[v*2+1]);
	}
	void upd(in size_t i,in T x)
	{
		assert(i>=0 && i<n);
		upd(1,0,n,i,x);
	}
	private T cel(in size_t v,in size_t vl,in size_t vr,in size_t l,in size_t r)
	{
		if(vl==l && r==vr) return t[v];
		size_t vm=(vl+vr) >> 1;
		if(r<=vm) return cel(2*v,vl,vm,l,r);
		else if(l>=vm) return cel(2*v+1,vm,vr,l,r);
		else return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));
	}
	T cel(in size_t l,in size_t r){
		assert(l<=r && l>=0 && r<n);
		return cel(1,0,n,l,r);
	}
};
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int t;
	loop:while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			readln;
			auto aut=arread!string;
			int m;
			input(&m);
			readln;
			auto a=new int[m];
			auto g=new int[][m];
			auto mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln.strip;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].splitter(regex("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.splitter(regex("[ ?.,:!]+"));
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int dp[105][105];
			int table[105][105];
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

module main;
import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.variant;
import core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
import std.stdio;
//import core.stdc.stdio;
alias RedBlackTree Rbt;
alias redBlackTree rbt;
alias BigInt big;
alias pair!(int,int) pii;
alias pair!(long,long) pll;
alias BoyerMooreFinder strfind;
alias mp=make_pair;
alias bins=binary_search;
alias orsq=orient_square;
immutable int mod=1000000007;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b)
	{
		return a/gcd(a,b)*b;
	}
	X binpow(X,Y)(X base,Y exp)
		if(is(typeof(exp&1)))
	{
		if(exp<0)return X(0);
		X res=X(1);
		while(exp>0)
		{
			if(exp&1)res*=base;
			base*=base;
			exp>>=1;
		}
		return res;
	}
	auto binpow(X,Y,Z)(X base,Y exp,in Z mm)
		if(is(typeof(exp&1)))
	{
		if(mm==0) return binpow(base,exp);
		if(exp<0)return X(0);
		auto res=X(1)%mm;
		while(exp>0)
		{
			if(exp&1)res=(res*base)%mm;
			base*=base;
			base%=mm;
			exp>>=1;
		}
		return res;
	}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	size_t lowb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(g<a[m])r=m;
			else l=m;
		}
		return (g<a[l])?l:r;
	}
	size_t binf(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (g==a[l])?l:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
		if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
	V foldr(R,V,T)(R range,T arg,V nach)
		if(isFunction!T && isInputRange!R && is(typeof(arg(nach,R.front))==V))
	{
		for(;!range.empty;range.popFront()) nach=arg(nach,range.front);
		return nach;
	}
	size_t countr(R,T)(R range,T fun)
		if(isFunction!T && isInputRange!R && is(typeof(fun(R.front))==bool))
	{
		size_t nach;
		for(;!range.empty;range.popFront()) nach+=fun(range.front);
		return nach;
	}
	T orient_square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
	{
		auto n=figure.front,t=figure.front;
		figure.popFront();
		T ans=0;
		for(;!figure.empty;figure.popFront())
		{
			ans+=(figure.front.fi-t.fi)*(figure.front.se+t.se);
			t=figure.front;
		}
		return ans+(n.fi-t.fi)*(n.se+t.se);
	}
	real square(T)(pair!(T,T)[] figure...)
		if(is(typeof(figure.front*figure.front)==T))
	{
		return abs(orient_square(figure))/2.000000000000000;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n,in size_t m)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
struct pair(X,Y)
{
	X first;
	Y second;
	alias first fi;
	alias second se;
	this(X a_,Y b_){
		fi=a_;
		se=b_;
	}
	this(this){fi=fi;se=se;}
	this(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))
	{
		fi=p.fi;
		se=p.se;
	}
	pair!(X,Y) opAssign(A,B)(pair!(A,B) val)
	{
		return this=pair!(X,Y)(val);
	}
	int opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe
		if(is(typeof(s_.fi<fi)==bool) && is(typeof(s_.se<se)==bool))
	{
		int cmp=0-(fi<s_.fi)+(fi>s_.fi);
		if(cmp!=0)return cmp;
		else return (0-(se<s_.se)+(se>s_.se));
	}
};
pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe
{
	pair!(X,Y) pp;
	pp.fi=x_;
	pp.se=y_;
	return pp;
}
nothrow void inf(in char* name) {freopen(name,"r",core.stdc.stdio.stdin);}
nothrow void ouf(in char* name) {freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
struct Tree(T,alias arg="a+b")
{
	private alias fun=binaryFun!arg;
	private static const size_t n=size_t.max>>1;
	private T[size_t] t;
	this(this){t=t.dup;}
	this(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))
	{
		foreach(pos,i;range) upd(pos,i);
	}
	this(R,alias f)(Tree!(R,f) q) if(is(R:T))
	{
		foreach(i,j;q.t)
		{
			t[i]=j;
		}
	}
	Tree!(T,arg) opAssign(R)(R val)
	{
		return this=Tree!(T,arg)(val);
	}
	private void upd(in size_t v,in size_t vl,in size_t vr,in size_t i,in T x)
	{
		if (vr - vl == 1){t[v] = x;return;}
		size_t vm = (vl + vr) >> 1;
		if(i < vm) upd(2*v, vl, vm, i, x);
		else upd(2*v+1, vm, vr, i, x);
		if(v*2+1 !in t)t[v]=t[v*2];
		else if (v*2 !in t)t[v]=t[v*2+1];
		else t[v]=fun(t[v*2],t[v*2+1]);
	}
	void upd(in size_t i,in T x)
	{
		assert(i>=0 && i<n);
		upd(1,0,n,i,x);
	}
	private T cel(in size_t v,in size_t vl,in size_t vr,in size_t l,in size_t r)
	{
		if(vl==l && r==vr) return t[v];
		size_t vm=(vl+vr) >> 1;
		if(r<=vm) return cel(2*v,vl,vm,l,r);
		else if(l>=vm) return cel(2*v+1,vm,vr,l,r);
		else return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));
	}
	T cel(in size_t l,in size_t r){
		assert(l<=r && l>=0 && r<n);
		return cel(1,0,n,l,r);
	}
};
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil
//---------------------------------------------------------------program beginning-----------------------------------------------------------------

void main()
{
	int t;
	loop:while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			readln;
			auto aut=arread!string;
			int m;
			input(&m);
			readln;
			auto a=new int[m];
			auto g=new int[][m];
			auto mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln.strip;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].strip.split(regex("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.strip.split(regex("[ ?.,:!]+"));
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int dp[105][105];
			int table[105][105];
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

import std.stdio,std.range,std.algorithm,std.string,std.regex,std.conv;
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length), ptrs)==ptrs.length;}
@property auto arread(T)(){return readln.split.map!(to!(T)).array;}
void main()
{
	int t;
	while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			readln;
			auto aut=arread!string;
			int m;
			input(&m);
			readln;
			auto a=new int[m], g=new int[][m],mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln.strip;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].split(regex("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.split(regex("[ ?.,:!]+"));
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int[105][105] dp, table;
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

import std.stdio,std.range,std.algorithm,std.regex,std.conv;
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
void main()
{
	int t;
	while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			auto aut=arread!string;
			int m;
			input(&m);
			auto a=new int[m], g=new int[][m],mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].splitter(ctRegex!("[ ?.,:!\n]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.splitter(ctRegex!("[ ?.,:!\n]+"));;
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int[105][105] dp, table;
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}

import std.stdio,std.range,std.algorithm,std.regex,std.conv;
bool input(T...)(T ptrs) if (ptrs.length > 0)
{return readf(replicate(" %s", ptrs.length)~'\n', ptrs)==ptrs.length;}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
void main()
{
	int t;
	while(input(&t))
	{
		foreach(gg;0..t)
		{
			int n;
			input(&n);
			auto aut=arread!string;
			int m;
			input(&m);
			auto a=new int[m], g=new int[][m],mes=new string[m];
			foreach(i;0..m)
			{
				auto s=readln;
				mes[i]=s;
				if(s[0]=='?')
				{
					a[i]=-1;
					auto f=s[2..$].splitter(ctRegex!("[ ?.,:!]+"));
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
				else
				{
					auto f=s.split(regex("[ ?.,:!]+"));
					a[i]=aut.countUntil(f.front);
					f.popFront;
					foreach(j;f)
					{
						int k=countUntil(aut,j);
						if(k!=-1)g[i]~=k;
					}
				}
			}
			int[105][105] dp, table;
			foreach(ref i;table)i[]=-1;
			int go(int p,int prev)
			{
				if(p==m)return true;
				int ans=table[p][prev];
				if(ans!=-1)return ans;
				ans=0;
				foreach(i;0..n)
				{
					if((p!=0 && prev==i) || (a[p]!=-1 && a[p]!=i) || g[p].count(i)>0)continue;
					if(go(p+1,i))
					{
						ans=true;
						dp[p][prev]=i;
						break;
					}
				}
				return table[p][prev]=ans;
			}
			auto o=go(0,0);
			if(!o){writeln("Impossible");continue;}
			int cur=0;
			foreach(i;0..m)
			{
				int x=dp[i][cur];
				a[i]=cur=x;
			}
			foreach(i;0..m)
			{
				if(mes[i][0]=='?')writeln(aut[a[i]],mes[i][1..$]);
				else writeln(mes[i]);
			}
		}
	}
}


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

alias Point = Tuple!(long, long);

long distance(Point a, Point b)
{
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}

long distance3(Point start, Point a, Point b)
{
//  writeln(start);
  long tmp1 = distance(start, a) + distance(a, b);
  long tmp2 = distance(start, b) + distance(b, a);
//  long tmp3 = distance(start, a) + distance(start, b);
//  writeln(tmp1);
//  writeln(tmp2);
//  writeln(tmp3);
//  return min(tmp1, tmp2, tmp3);
  return min(tmp1, tmp2);
}

void main()
{
  long t;
  readf!" %d "(t);

  while (t--) {
    long n, m, i, j;
    readf!" %d %d %d %d "(n, m, i, j);
    i -= 1;
    j -= 1;
    auto start = Point(i, j);
    Point c0 = Point(0, 0);
    Point c1 = Point(0, m - 1);
    Point c2 = Point(n - 1, 0);
    Point c3 = Point(n - 1, m - 1);

    Point c4 = Point(i, 0);
    Point c5 = Point(i, m - 1);

//    auto x = [c0, c1, c2, c3];
//    writeln(x.permutations);
    long max = -1;
    Point p1, p2;
    foreach (x ; [c0, c1, c2, c3].permutations) {
      long dist = distance3(start, x[0], x[1]);
      if (dist > max) {
        max = dist;
        p1 = x[0];
        p2 = x[1];
      }
    }
    writefln("%d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);
//    writefln("%d %d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1, max);
  }
//  writeln(distance3(Point(1000000000 - 1, 50 - 1), Point(50 - 1, 1 - 1), Point(1 - 1, 1000000000 - 1)));
//  writeln(distance3(Point(1000000000 - 1, 50 - 1), Point(50 - 1, 1 - 1), Point(1 - 1, 1000000000 - 1)));
}

// Vicfred
// https://codeforces.com/contest/1537/problem/B
//
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

while(t--) {
    long n, m, i, j;
    readf("%s %s %s %s\n", &n, &m, &i, &j);
    if(m - j > j - 1) {
        writefln("%s %s %s %s", n, 1, 1, m);
    } else {
        writefln("%s %s %s %s", n, m, 1, 1);
    }
}
}

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

alias Point = Tuple!(long, long);

long distance(Point a, Point b)
{
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}

long distance3(Point start, Point a, Point b)
{
//  writeln(start);
  long tmp1 = distance(start, a) + distance(a, b);
  long tmp2 = distance(start, b) + distance(b, a);
  long tmp3 = distance(start, a) + distance(start, b);
//  writeln(tmp1);
//  writeln(tmp2);
//  writeln(tmp3);
  return min(tmp1, tmp2, tmp3);
}

void main()
{
  long t;
  readf!" %d "(t);

  while (t--) {
    long n, m, i, j;
    readf!" %d %d %d %d "(n, m, i, j);
    i -= 1;
    j -= 1;
    auto start = Point(i, j);
    Point c0 = Point(0, 0);
    Point c1 = Point(0, m - 1);
    Point c2 = Point(n - 1, 0);
    Point c3 = Point(n - 1, m - 1);

    Point c4 = Point(i, 0);
    Point c5 = Point(i, m - 1);

//    auto x = [c0, c1, c2, c3];
//    writeln(x.permutations);
    long max = -1;
    Point p1, p2;
    foreach (x ; [c0, c1, c2, c3, c0, c1, c2, c3].permutations) {
      long dist = distance3(start, x[0], x[1]);
      if (dist > max) {
        max = dist;
        p1 = x[0];
        p2 = x[1];
      }
    }
    writefln("%d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);
//    writefln("%d %d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1, max);
  }
//  writeln(distance3(Point(1000000000 - 1, 50 - 1), Point(50 - 1, 1 - 1), Point(1 - 1, 1000000000 - 1)));
}

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

alias Point = Tuple!(long, long);

long distance(Point a, Point b)
{
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}

long distance3(Point start, Point a, Point b)
{
  writeln(start);
  long tmp1 = distance(start, a) + distance(a, b);
  long tmp2 = distance(start, b) + distance(b, a);
  long tmp3 = distance(start, a) + distance(start, b);
  writeln(tmp1);
  writeln(tmp2);
  writeln(tmp3);
  return min(tmp1, tmp2, tmp3);
}

void main()
{
  long t;
  readf!" %d "(t);

  while (t--) {
    long n, m, i, j;
    readf!" %d %d %d %d "(n, m, i, j);
    i -= 1;
    j -= 1;
    auto start = Point(i, j);
    Point c0 = Point(0, 0);
    Point c1 = Point(0, m - 1);
    Point c2 = Point(n - 1, 0);
    Point c3 = Point(n - 1, m - 1);

    Point c4 = Point(i, 0);
    Point c5 = Point(i, m - 1);

//    auto x = [c0, c1, c2, c3];
//    writeln(x.permutations);
    long max = -1;
    Point p1, p2;
    foreach (x ; [c0, c1, c2, c3, c0, c1, c2, c3].permutations) {
      long tmp1 = distance(start, x[0]) + distance(x[0], x[1]);
      long tmp2 = distance(start, x[1]) + distance(x[1], x[0]);
      long tmp3 = distance(start, x[0]) + distance(start, x[1]);
      if (min(tmp1, tmp2, tmp3) > max) {
        max = min(tmp1, tmp2, tmp3);
        p1 = x[0];
        p2 = x[1];
      }
    }
    writefln("%d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);
//    writefln("%d %d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1, max);
  }
//  writeln(distance3(Point(1000000000 - 1, 50 - 1), Point(50 - 1, 1 - 1), Point(1 - 1, 1000000000 - 1)));
}

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

alias Point = Tuple!(int, int);

int distance(Point a, Point b)
{
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}

void main()
{
  int t;
  readf!" %d "(t);

  while (t--) {
    int n, m, i, j;
    readf!" %d %d %d %d "(n, m, i, j);
    i -= 1;
    j -= 1;
    auto start = Point(i, j);
    Point c0 = Point(0, 0);
    Point c1 = Point(0, m - 1);
    Point c2 = Point(n - 1, 0);
    Point c3 = Point(n - 1, m - 1);
//    auto x = [c0, c1, c2, c3];
//    writeln(x.permutations);
    int max = -1;
    Point p1, p2;
    foreach (x ; [c0, c1, c2, c3, c0, c1, c2, c3].permutations) {
      int tmp1 = distance(start, x[0]) + distance(x[0], x[1]);
      int tmp2 = distance(start, x[1]) + distance(x[1], x[0]);
      int tmp3 = distance(start, x[0]) + distance(start, x[1]);
      if (min(tmp1, tmp2, tmp3) > max) {
        max = min(tmp1, tmp2, tmp3);
        p1 = x[0];
        p2 = x[1];
      }
    }
    writefln("%d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);
  }
}

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

alias Point = Tuple!(int, int);

int distance(Point a, Point b)
{
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}

void main()
{
  int t;
  readf!" %d "(t);

  while (t--) {
    int n, m, i, j;
    readf!" %d %d %d %d "(n, m, i, j);
    i -= 1;
    j -= 1;
    auto start = Point(i, j);
    Point c0 = Point(0, 0);
    Point c1 = Point(0, m - 1);
    Point c2 = Point(n - 1, 0);
    Point c3 = Point(n - 1, m - 1);
//    auto x = [c0, c1, c2, c3];
//    writeln(x.permutations);
    int max = -1;
    Point p1, p2;
    foreach (x ; [c0, c1, c2, c3, c0, c1, c2, c3].permutations) {
      int tmp1 = distance(start, x[0]) + distance(x[0], x[1]);
      int tmp2 = distance(start, x[1]) + distance(x[0], x[1]);
      if (min(tmp1, tmp2) > max) {
        max = min(tmp1, tmp2);
        p1 = x[0];
        p2 = x[1];
      }
    }
    writefln("%d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);
  }
}

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

alias Point = Tuple!(int, int);

int distance(Point a, Point b)
{
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}

void main()
{
  int t;
  readf!" %d "(t);

  while (t--) {
    int n, m, i, j;
    readf!" %d %d %d %d "(n, m, i, j);
    auto start = Point(i, j);
    Point c0 = Point(0, 0);
    Point c1 = Point(0, m - 1);
    Point c2 = Point(n - 1, 0);
    Point c3 = Point(n - 1, m - 1);
//    auto x = [c0, c1, c2, c3];
//    writeln(x.permutations);
    int max = -1;
    Point p1, p2;
    foreach (x ; [c0, c1, c2, c3].permutations) {
      int tmp1 = distance(start, x[0]) + distance(x[0], x[1]);
      int tmp2 = distance(start, x[1]) + distance(x[0], x[1]);
      if (min(tmp1, tmp2) > max) {
        max = min(tmp1, tmp2);
        p1 = x[0];
        p2 = x[1];
      }
    }
    writefln("%d %d %d %d", p1[0] + 1, p1[1] + 1, p2[0] + 1, p2[1] + 1);
  }
}

// Vicfred
// https://codeforces.com/contest/1537/problem/B
//
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

while(t--) {
    long n, m, i, j;
    readf("%s %s %s %s\n", &n, &m, &i, &j);
    if(n - i < i - 1) {
        writefln("%s %s %s %s", n, n, 1, 1);
    } else {
        writefln("%s %s %s %s", 1, n, n, 1);
    }
}
}


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

DList!string _words;

void read(T...)(ref T t)
{
  void singleRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  static foreach(i; 0 .. T.length)
    {
      static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))
        {
          foreach(ref element; t[i])
            read(element);
        }
      else static if (isAggregateType!(T[i]))
        {
          static foreach(fieldName; FieldNameTuple!(T[i]))
            {
              static if (hasUDA!(mixin(text(T[i].stringof, ".", fieldName)), string))
                {
                  with(t[i])
                    {
                      mixin(q{t[i].}, fieldName, q{.length}) =
                        cast(size_t) mixin(getUDAs!(mixin(text(T[i].stringof, ".", fieldName)), string)[0]);
                    }
                }
              read(mixin(text(q{t[i].}, fieldName)));
            }
        }
      else
        {
          singleRead(t[i]);
        }
    }
}

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

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

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

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

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

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

    }
}

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

E[] makeSlice(E, S)(S size, lazy E value)
{
  auto a = new E[size.ind];
  foreach(ref ai; a)
    ai = value();
  return a;
}

E[] makeSlice(E, S)(S size = 0)
{
  return new E[size.ind];
}

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

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

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

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

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

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

alias type = multi;
struct TestCase
{
  long n;
  @("n") long[] a;

  void solve(long i = -1)
  {
    sort(a);
    if (iota(0, n - 1).all!(i => a.at(i + 1) - a.at(i) <= 1))
      writeln("YES");
    else
      writeln("NO");
  }
}

void main()
{
  type;
}

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;
		a.sort();

		bool ok = true;
		foreach (i; 1..n)
		{
			if (a[i] - a[i-1] > 1)
			{
				ok = false;
				break;
			}
		}
		ans[ti] = ok;
	}

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

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

DList!string _words;

void read(T...)(ref T t)
{
  void singleRead(W)(ref W w)
  {
    import std.stdio: readln;
    while(_words.empty)
      {
        import std.array: split;
        foreach(word; readln.split)
          {
            _words.insertBack(word);
          }
      }
    import std.conv: to;
    string word = _words.front;
    _words.removeFront;
    w = to!W(word);
  }
  static foreach(i; 0 .. T.length)
    {
      static if (is(typeof({foreach(ref e; t[i]){}})) && !is(T[i] == string))
        {
          foreach(ref element; t[i])
            read(element);
        }
      else static if (isAggregateType!(T[i]))
        {
          static foreach(fieldName; FieldNameTuple!(T[i]))
            {
              static if (hasUDA!(mixin(text(T[i].stringof, ".", fieldName)), string))
                {
                  with(t[i])
                    {
                      mixin(q{t[i].}, fieldName, q{.length}) =
                        cast(size_t) mixin(getUDAs!(mixin(text(T[i].stringof, ".", fieldName)), string)[0]);
                    }
                }
              read(mixin(text(q{t[i].}, fieldName)));
            }
        }
      else
        {
          singleRead(t[i]);
        }
    }
}

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

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

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

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

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

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

    }
}

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

E[] makeSlice(E, S)(S size, lazy E value)
{
  auto a = new E[size.ind];
  foreach(ref ai; a)
    ai = value();
  return a;
}

E[] makeSlice(E, S)(S size = 0)
{
  return new E[size.ind];
}

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

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

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

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

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

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

alias type = multi;
struct TestCase
{
  long n;
  @("n") long[] a;

  void solve(long i = -1)
  {
    auto m = a.fold!min(long.max);
    if (a.any!(ai => ai != m && ai != m + 1))
      writeln("NO");
    else
      writeln("YES");
  }
}

void main()
{
  type;
}


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

int main(string[] args)
{
    auto n = to!int(readln.strip);
    auto p = new int[n];
    auto q = new int[n];
    auto prev = new int[n];
    fill(prev, -1);
    foreach (i; 0 .. n)
    {
        q[i] = 2;
        foreach (j; 0 .. n) if (j != i) q[j] = 1;
        writeln("? ", join(map!(to!string)(q), " "));
        stdout.flush;
        auto ridx = to!int(readln.strip);
        if (ridx != 0 && ridx != i + 1) prev[ridx - 1] = i;
        q[i] = 1;
        foreach (j; 0 .. n) if (j != i) q[j] = 2;
        writeln("? ", join(map!(to!string)(q), " "));
        stdout.flush;
        ridx = to!int(readln.strip);
        if (ridx != 0 && ridx != i + 1) prev[i] = ridx - 1;
    }
    auto f = new bool[n];
    foreach (i; 0 .. n) if (prev[i] != -1) f[prev[i]] = true;
    auto idx = -1;
    foreach (i; 0 .. n) if (!f[i])
    {
        idx = i;
        break;
    }
    p[idx] = n;
    foreach (i; 0 .. n - 1)
    {
        p[prev[idx]] = p[idx] - 1;
        idx = prev[idx];
    }
    writeln("! ", join(map!(to!string)(p), " "));
    stdout.flush;
    return 0;
}

immutable multi = false;

void solve(int tc)
{
	int n = readInt!int;
	auto next = new int[](n+1);
	auto prev = new int[](n+1);
	int zero = 0;
	void get(int i)
	{
		int answer = void;
		write ("? ");
		foreach(j; 1 .. n+1)
		{
			write (int(i == j)+1, " ");
		}
		writeln;
		stdout.flush;
		answer = readInt!int;
		if (answer == 0)
		{
			next[i] = 0;
		}
		else
		{
			if (answer < i)
			{
				next[i] = answer;
				prev[answer] = i;
			}
			else
			{
				assert(answer == i);
			}
		}

		write ("? ");
		foreach(j; 1 .. n+1)
		{
			write (int(i != j)+1, " ");
		}
		writeln;
		stdout.flush;
		answer = readInt!int;
		if (answer == 0)
		{
			prev[i] = 0;
			zero = i;
		}
		else
		{
			if (answer < i)
			{
				prev[i] = answer;
				next[answer] = i;
			}
			else
			{
				assert(answer == i);
			}
		}
	}
	foreach(i; 1 .. n + 1) get(i);
	assert (zero != 0);
	auto p = new int[](n+1);
	int v = 1;
	int i = zero;
	while (i)
	{
		p[i] = v++;
		i = next[i];
	}
	write("! ");
	foreach(j; 1 .. n + 1) write (p[j], " ");
	writeln;
	stdout.flush;
}

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

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

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

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

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

immutable multi = false;

void solve(int tc)
{
	int n = readInt!int;
	auto next = new int[](n+1);
	auto prev = new int[](n+1);
	int zero = 0;
	void get(int i)
	{
		int answer = void;
		write ("? ");
		foreach(j; 1 .. n+1)
		{
			write (int(i == j), " ");
		}
		writeln;
		stdout.flush;
		answer = readInt!int;
		if (answer == 0)
		{
			next[i] = 0;
		}
		else
		{
			if (answer < i)
			{
				next[i] = answer;
				prev[answer] = i;
			}
			else
			{
				assert(answer == i);
			}
		}

		write ("? ");
		foreach(j; 1 .. n+1)
		{
			write (int(i != j), " ");
		}
		writeln;
		stdout.flush;
		answer = readInt!int;
		if (answer == 0)
		{
			prev[i] = 0;
			zero = i;
		}
		else
		{
			if (answer < i)
			{
				prev[i] = answer;
				next[answer] = i;
			}
			else
			{
				assert(answer == i);
			}
		}
	}
	foreach(i; 1 .. n + 1) get(i);
	assert (zero != 0);
	auto p = new int[](n+1);
	int v = 1;
	int i = zero;
	while (i)
	{
		p[i] = v++;
		i = next[i];
	}
	write("! ");
	foreach(j; 1 .. n + 1) write (p[j], " ");
	writeln;
	stdout.flush;
}

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

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

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

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

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

immutable multi = false;

void solve(int tc)
{
	int n = readInt!int;
	auto next = new int[](n+1);
	auto prev = new int[](n+1);
	int zero = 0;
	void get(int i)
	{
		int answer = void;
		write ("? ");
		foreach(j; 1 .. n+1)
		{
			write (int(i == j), " ");
		}
		writeln;
		stdout.flush;
		answer = readInt!int;
		if (answer == 0)
		{
			next[i] = 0;
		}
		else
		{
			if (answer < i)
			{
				next[i] = answer;
				prev[answer] = i;
			}
			else
			{
				assert(answer == i);
			}
		}

		write ("? ");
		foreach(j; 1 .. n+1)
		{
			write (int(i != j), " ");
		}
		writeln;
		stdout.flush;
		answer = readInt!int;
		if (answer == 0)
		{
			prev[i] = 0;
			zero = i;
		}
		else
		{
			if (answer < i)
			{
				prev[i] = answer;
				next[answer] = i;
			}
			else
			{
				assert(answer == i);
			}
		}
	}
	foreach(i; 1 .. n + 1) get(i);
	assert (zero != 0);
	auto p = new int[](n+1);
	int v = 1;
	int i = zero;
	while (i)
	{
		p[i] = v++;
		i = next[i];
	}
	debug writeln(p);
}

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

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

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

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

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


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

string FMT_F = "%.10f";

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

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

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

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

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

		if (k % 2 == 0)
		{
			if (n % 2) continue;
			if (k > n) continue;
			foreach (i; 0..k-1)
			{
				ans[ti] ~= 1;
			}
			ans[ti] ~= n - (k-1);
		}
		else
		{
			if (n % 2)
			{
				if (k > n) continue;
				foreach (i; 0..k-1)
				{
					ans[ti] ~= 1;
				}
				ans[ti] ~= n - (k-1);
			}
			else
			{
				if (k*2 > n) continue;
				foreach (i; 0..k-1)
				{
					ans[ti] ~= 2;
				}
				ans[ti] ~= n - (k-1)*2;
			}
		}
	}

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

// Author: Ivan Kazmenko (gassa@mail.ru)
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

int [] solve (int n, int k)
{
	foreach (v; [1, 2])
	{
		auto last = n - v * (k - 1);
		if (last > 0 && last % 2 == v % 2)
		{
			return v.repeat (k - 1).array ~ last;
		}
	}
	return null;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		auto res = solve (n, k);
		if (res is null)
		{
			writeln ("NO");
		}
		else
		{
			writeln ("YES");
			writefln !("%(%s %)") (res);
		}
	}
}

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

void calc(int n, int k) {
    int x = n - (k - 1);
    if (x > 0 && x % 2 == 1) {
        writeln("YES");
        auto ans = chain(repeat(1, k - 1), [n - (k - 1)]);
        writeln(ans.map!text.join(' '));
        return;
    }

    int y = n - (k - 1) * 2;
    if (y > 0 && y % 2 == 0) {
        writeln("YES");
        auto ans = chain(repeat(2, k - 1), [n - (k - 1) * 2]);
        writeln(ans.map!text.join(' '));
        return;
    }

    writeln("NO");
}

void main() {
    int t; scan(t);
    foreach (_; 0..t) {
        int n, k; scan(n, k);
        calc(n, k);
    }
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;

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

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto t = readNum!int;

  foreach(i; 0 .. t){
    auto nk = readNums!long;

    long a = nk[0] / nk[1];
    long b = nk[0] % nk[1];

    if(b % 2 == 0 && a > 0){
      writeln("YES");
      foreach(j; 0 .. nk[1] - 1){
        write(a, " ");
      }
      writeln(a+b);
    } else if((b+nk[1]) % 2 == 0 && a-1 > 0){
      writeln("YES");
      foreach(j; 0 .. nk[1] - 1){
        write(a-1, " ");
      }
      writeln(a-1+b+nk[1]);
    } else {
      writeln("NO");
    }
  }
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto nk = readln.split.to!(long[]);
        auto N = nk[0];
        auto K = nk[1];

        auto d = N / K;
        auto r = N % K;
        auto x = d+r;

        if (d == 0) {
            writeln("NO");
            continue;
        }

        if (d%2 != x%2) {
            if (d <= 1 || K%2 == 0) {
                writeln("NO");
                continue;
            }
            d -= 1;
            x += K-1;
        }

        long[] as;
        foreach (_k; 0..K-1) as ~= d;
        as ~= x;
        writeln("YES");
        writeln(as.to!(string[]).join(" "));
    }
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto nk = readln.split.to!(long[]);
        auto N = nk[0];
        auto K = nk[1];

        auto d = N / K;
        auto r = N % K;
        auto x = d+r;

        if (d%2 != x%2) {
            if (d <= 1 || K%2 == 0) {
                writeln("NO");
                continue;
            }
            d -= 1;
            x += K-1;
        }

        long[] as;
        foreach (_k; 0..K-1) as ~= d;
        as ~= x;
        writeln("YES");
        writeln(as.to!(string[]).join(" "));
    }
}

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

void main()
{
    auto T = readln.chomp.to!int;
    foreach (_; 0..T) {
        auto nk = readln.split.to!(long[]);
        auto N = nk[0];
        auto K = nk[1];

        auto d = N / K;
        auto r = N % K;
        auto x = d+r;

        if (d%2 != x%2) {
            if (d == 1 || K%2 == 0) {
                writeln("NO");
                continue;
            }
            d -= 1;
            x += K-1;
        }

        long[] as;
        foreach (_k; 0..K-1) as ~= d;
        as ~= x;
        writeln("YES");
        writeln(as.to!(string[]).join(" "));
    }
}

// Author: Ivan Kazmenko (gassa@mail.ru)
// tries to build with 4 instead of 2
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

int [] solve (int n, int k)
{
	foreach (v; [1, 4])
	{
		auto last = n - v * (k - 1);
		if (last > 0 && last % 2 == v % 2)
		{
			return v.repeat (k - 1).array ~ last;
		}
	}
	return null;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		auto res = solve (n, k);
		if (res is null)
		{
			writeln ("NO");
		}
		else
		{
			writeln ("YES");
			writefln !("%(%s %)") (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.datetime.stopwatch;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

immutable int MX = 2 ^^ 14 - 1;

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

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

    auto cnt = new int[] (MX+1);

    arr.each!(x => ++cnt[x]);

    auto ans = 0L;
    foreach (i; 0 .. MX+1) {
        foreach (j; i .. MX+1) {
            if ((i ^ j).popcnt == k) {
                ans += i == j ?
                    cnt[i].to!long * (cnt[i]-1) / 2
                    : cnt[i].to!long * cnt[j];
            }
        }
    }

    ans.writeln;
}

import std.stdio;
import std.string;
import std.format;
import std.algorithm;
import std.math;
import core.bitop;

const int N = 100004;

long ans;
int n, k;
int[N] a;
int[] masks;
int[1 << 14] cnt;

void read() {
	readf(" %s %s", &n, &k);
	foreach (i; 0..n) {
		readf(" %s", &a[i]);
	}
}

void precalc() {
	foreach (mask; 0..1<<14) {
		if (_popcnt(mask) == k) {
			masks ~= mask;
		}
	}
}

void compute() {
	foreach (i; 0..n) {
		foreach (m; masks) {
			ans += cnt[a[i] ^ m];
		}
		cnt[a[i]]++;
	}
}

void solve() {
	read();
	precalc();
	compute();
	writeln(ans);
}

int main() {
	solve();

    return 0;
}

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

immutable int MX = 2 ^^ 14 - 1;

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

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

    auto cnt = new int[] (MX+1);

    arr.each!(x => ++cnt[x]);

    auto ans = 0L;
    foreach (i; 0 .. MX+1) {
        foreach (j; i .. MX+1) {
            if ((i ^ j).popcnt != k) { ans += cnt[i].to!long * cnt[j]; }
        }
    }

    ans.writeln;
}

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

immutable int MX = 2 ^^ 14 - 1;

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

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

    auto cnt = new int[] (MX+1);

    arr.each!(x => ++cnt[x]);

    auto ans = 0L;
    foreach (i; 0 .. MX+1) {
        foreach (j; i .. MX+1) {
            if ((i ^ j).popcnt == k) { ans += cnt[i].to!long * cnt[j]; }
        }
    }

    ans.writeln;
}


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

void theCode(){
    int k = scan!int;
    int j = 0;
    for(int i = 1; i <= 3*k; ++i){
        if(i % 3 == 0 || i % 10 == 3) continue;
        ++j;
        if(j == k){
            writeln(i);
        }
    }
}

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

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

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

void main()
{
  long t;
  readf!" %d "(t);
  while (t--) {
    long n;
    readf!" %d "(n);
    long ans;
    foreach (i ; 1 .. 100000) {
      if (i % 10 == 3 || i % 3 == 0) {
      } else {
        if (--n == 0) {
          writeln(i);
          break;
        }
      }
    }
  }
}


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

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, s; readV(n, s);

  auto t = new int[](n);
  foreach (i; 0..n) {
    int h, m; readV(h, m);
    t[i] = h*60+m;
  }

  auto put(int ans)
  {
    writeln(ans/60, " ", ans%60);
  }

  if (t[0] >= s+1) {
    put(0);
    return;
  }

  foreach (i; 0..n-1) {
    if (t[i+1]-t[i] >= s*2+2) {
      put(t[i]+s+1);
      return;
    }
  }

  put(t[$-1]+s+1);
}

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;

void main() {
	auto ns = readln.chomp.split.map!(to!int);
	int n = ns[0];
	int s = ns[1];
	int[] times;
	times ~= -s - 1;
	foreach (i; 0..n) {
		auto hs = readln.chomp.split.map!(to!int);
		int h = hs[0];
		int m = hs[1];
		int t = h * 60 + m;
		times ~= t;
	}
	times ~= times[$-1] + (1 << 28);
	int len = cast(int) times.length;
	for (int i = 0; i < len - 1; ++i) {
		int t1 = times[i];
		int t2 = times[i + 1];
		debug stderr.writefln("[%d] %d %d ... %d", i, t1, t2, t2 - t1);
		if (t2 - t1 >= s * 2 + 2) {
			int h = t1 / 60;
			int m = t1 % 60;
			debug stderr.writefln("\t%d, %d", h, m);
			m += s + 1;
			h += m / 60;
			m %= 60;
			if (h < 0 || m < 0) {
				continue;
			}
			debug stderr.writefln("\t\t[%d] %d %d ... %d", i, t1, t2, t2 - t1);
			writefln("%d %d", h, m);
			return;
		}
	}
}

import std.stdio;
import std.range;
import std.array;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.typecons;
import std.random;
import std.csv;
import std.regex;
import std.math;
import core.time;
import std.ascii;
import std.digest.sha;
import std.outbuffer;

void main() {
	auto ns = readln.chomp.split.map!(to!int);
	int n = ns[0];
	int s = ns[1];
	int[] times;
	times ~= -s - 1;
	foreach (i; 0..n) {
		auto hs = readln.chomp.split.map!(to!int);
		int h = hs[0];
		int m = hs[1];
		int t = h * 60 + m;
		times ~= t;
	}
	times ~= times[$-1] + s;
	times ~= times[$-1] + 1 << 28;
	int len = cast(int) times.length;
	for (int i = 0; i < len - 1; ++i) {
		int t1 = times[i];
		int t2 = times[i + 1];
		if (t2 - t1 >= s * 2 + 2) {
			int h = t1 / 60;
			int m = t1 % 60;
			m += s + 1;
			h += m / 60;
			m %= 60;
			debug stderr.writefln("[%d] %d %d ... %d", i, t1, t2, t2 - t1);
			writefln("%d %d", h, m);
			return;
		}
	}
}