#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
const int MAXN = 1e6+7;
const int INF = 1e9+7;
const int MOD=  1e9+7;
#define LL long long
#define pb push_back
#define st first
#define nd second
typedef pair<int ,int > pii;
typedef vector<int >  pi;
pi g[maxn];
pi res;
char s[maxn];
int tmp;
int n;
void dfs(int u,int l,int d,int fa)
{
	if(d==l)
	{
		res.pb(u);
		return ;
	}
	for(int to:g[u])
	{
		if(to==fa)
		continue;
		dfs(to,l,d+1,u);
	}
	return ;
}
int tmpx,tmpy;
void query()
{
	if(!res.size())
	{
		tmpy=10001;
		return ;
	}
	printf("? %d",res.size());
	for(int to : res)
	{
		printf(" %d",to);
	}
	puts("");
	fflush(stdout);
	if(res.size())
	scanf("%d %d",&tmp,&tmpy);
	else
	{
		tmpy = 10001;
	}
	return ;
}
int check(int x,int l)
{
	res.clear();
	int i,j;
	dfs(x,l,0,-1);
	query();
	return tmpy;
}
int main()
{
	int i,j,m,t,z;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=1;i<n;i++)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			g[u].pb(v);
			g[v].pb(u);
		}
		printf("? %d",n);
		for(i=1;i<=n;i++)
		{
			printf(" %d",i);
		}
		puts("");
		fflush(stdout);
		int x,v;
		scanf("%d %d",&x,&v);
		int l =(v+1)/2,r=v;
		int ans ;
		while(l<=r)
		{
			int mid = (l+r)>>1;
			if(check(x,mid)<=v)
			{
				ans=tmp;
				l=mid+1;
			}
			else
			{
				r=mid-1;
			}
		}
		res.clear();
		dfs(ans,v,0,-1);
		query();
		printf("! %d %d\n",ans,tmp);
		fflush(stdout);
		scanf("%s",s);
		for(i=1;i<=n;i++)
		g[i].clear();
	}
	return 0;
 }
 /*
1
4
4 2
2 3
3 1
 */


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
const int MAXN = 1e6+7;
const int INF = 1e9+7;
const int MOD=  1e9+7;
#define LL long long
#define pb push_back
#define st first
#define nd second
typedef pair<int ,int > pii;
typedef vector<int >  pi;
pi g[maxn];
pi res;
char s[maxn];
int tmp;
int n;
void dfs(int u,int l,int d,int fa)
{
	if(d==l)
	{
		res.pb(u);
		return ;
	}
	for(int to:g[u])
	{
		if(to==fa)
		continue;
		dfs(to,l,d+1,u);
	}
	return ;
}
int tmpx,tmpy;
void query()
{
	printf("? %d",res.size());
	for(int to : res)
	{
		printf(" %d",to);
	}
	puts("");
	fflush(stdout);
	if(res.size())
	scanf("%d %d",&tmp,&tmpy);
	else
	{
		tmpy = 10001;
	}
	return ;
}
int check(int x,int l)
{
	res.clear();
	int i,j;
	dfs(x,l,0,-1);
	query();
	return tmpy;
}
int main()
{
	int i,j,m,t,z;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=1;i<n;i++)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			g[u].pb(v);
			g[v].pb(u);
		}
		printf("? %d",n);
		for(i=1;i<=n;i++)
		{
			printf(" %d",i);
		}
		puts("");
		fflush(stdout);
		int x,v;
		scanf("%d %d",&x,&v);
		int l =(v+1)/2,r=v;
		int ans ;
		while(l<=r)
		{
			int mid = (l+r)>>1;
			if(check(x,mid)<=v)
			{
				ans=tmp;
				l=mid+1;
			}
			else
			{
				r=mid-1;
			}
		}
		dfs(ans,v,0,-1);
		query();
		printf("! %d %d\n",ans,tmp);
		fflush(stdout);
		scanf("%s",s);
	}
	return 0;
 }


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
const int MAXN = 1e6+7;
const int INF = 1e9+7;
const int MOD=  1e9+7;
#define LL long long
#define pb push_back
#define st first
#define nd second
typedef pair<int ,int > pii;
typedef vector<int >  pi;
pi g[maxn];
pi res;
char s[maxn];
int tmp;
int n;
void dfs(int u,int l,int d,int fa)
{
	if(d==l)
	{
		res.pb(u);
		return ;
	}
	for(int to:g[u])
	{
		if(to==fa)
		continue;
		dfs(to,l,d+1,u);
	}
	return ;
}
int tmpx,tmpy;
void query()
{
	printf("? %d",res.size());
	for(int to : res)
	{
		printf(" %d",to);
	}
	puts("");
	fflush(stdout);
	if(res.size())
	scanf("%d %d",&tmp,&tmpy);
	else
	{
		tmpy = 10001;
	}
	return ;
}
int check(int x,int l)
{
	res.clear();
	int i,j;
	dfs(x,l,0,-1);
	query();
	return tmpy;
}
int main()
{
	int i,j,m,t,z;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=1;i<n;i++)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			g[u].pb(v);
			g[v].pb(u);
		}
		printf("? %d",n);
		for(i=1;i<=n;i++)
		{
			printf(" %d",i);
		}
		puts("");
		fflush(stdout);
		int x,v;
		scanf("%d %d",&x,&v);
		int l =(v+1)/2,r=v;
		int ans ;
		while(l<=r)
		{
			int mid = (l+r)>>1;
			if(check(x,mid)<=v)
			{
				ans=tmp;
				l=mid+1;
			}
			else
			{
				r=mid-1;
			}
		}
		res.clear();
		dfs(ans,v,0,-1);
		query();
		printf("! %d %d\n",ans,tmp);
		fflush(stdout);
		scanf("%s",s);
		for(i=1;i<=n;i++)
		g[i].clear();
	}
	return 0;
 }


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
vector<int>ed[1005];
int dd[1005];
int n;
int mk[1005];
vector<int>lists,listf;
void dfs(int i,int d,int p,int j){
	if(d==0){
		if(mk[i])return;
		if(j)listf.pb(i);
		else lists.pb(i);
		return;
	}
	for(int v:ed[i]){
		if(v==p)continue;
		dfs(v,d-1,i,j);
	}
}
int dfs1(int i,int f,int p){
	if(i==f)return mk[i]=1;
	for(int j:ed[i]){
		if(j==p)continue;
		mk[i]|=dfs1(j,f,i);
	}
	return mk[i];
}
void dfs2(int i,int p,int di){
	dd[i]=di;
	for(int j:ed[i]){
		if(j==p)continue;
		dfs2(j,i,di+1);
	}
}
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++){
		ed[i].clear();
		mk[i]=0;
		dd[i]=0;
	}
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		ed[u].pb(v);
		ed[v].pb(u);
	}
	int root=1,d;
	cout<<"? "<<n<<" ";
	for(int i=1;i<=n;i++)cout<<i<<" ";cout<<"\n";
	cin>>root>>d;
	int s=root,f=root,cur=0;
	dfs2(root,-1,0);
	while(dd[s]+dd[f]<d){
		int p=(d-cur+1)/2;
		//cout<<s<<" "<<f<<"\n";
		lists.clear();
		listf.clear();
		dfs(s,p,-1,0);
		dfs(f,p,-1,1);
		set<int>st;
		for(int i:lists)st.insert(i);
		for(int j:listf)st.insert(j);
		cout<<"? "<<st.size()<<" ";
		for(int i:st)cout<<i<<" ";cout<<"\n";
		int node;
		cin>>node>>d;
		int flag=0;
		for(int i:lists)if(i==node){s=node;flag=1;break;}
		if(!flag)for(int j:listf)if(j==node){f=node;break;}
		dfs1(s,f,-1);
		//mk[s]=mk[f]=0;
		cur=dd[s]+dd[f];
	}
	cout<<"! "<<s<<" "<<f<<"\n";
	string res;
	cin>>res;
}
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	//cout.tie(NULL);
	int t;
	cin>>t;
	//t=1;
	while(t--){
		solve();
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
vector<int>ed[1005];
int dd[1005];
int n;
int mk[1005];
vector<int>lists,listf;
void dfs(int i,int d,int p,int j){
	if(d==0){
		if(mk[i])return;
		if(j)listf.pb(i);
		else lists.pb(i);
	}
	for(int v:ed[i]){
		if(v==p)continue;
		dfs(v,d-1,i,j);
	}
}
int dfs1(int i,int f,int p){
	if(i==f)return 1;
	for(int j:ed[i]){
		if(j==p)continue;
		mk[i]|=dfs1(j,f,i);
	}
	return mk[i];
}
void dfs2(int i,int p,int di){
	dd[i]=di;
	for(int j:ed[i]){
		if(j==p)continue;
		dfs2(j,i,di+1);
	}
}
void solve(){
	for(int i=1;i<=n;i++){
		ed[i].clear();
		mk[i]=0;
		dd[i]=0;
	}
	cin>>n;
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		ed[u].pb(v);
		ed[v].pb(u);
	}
	int root=1,d;
	cout<<"? "<<n<<" ";
	for(int i=1;i<=n;i++)cout<<i<<" ";cout<<"\n";
	cin>>root>>d;
	int s=root,f=root,cur=0;
	dfs2(root,-1,0);
	while(dd[s]+dd[f]<d){
		int p=(d-cur+1)/2;
		lists.clear();
		listf.clear();
		dfs(s,p,-1,0);
		dfs(f,p,-1,1);
		set<int>st;
		for(int i:lists)st.insert(i);
		for(int j:listf)st.insert(j);
		cout<<"? "<<st.size()<<" ";
		for(int i:st)cout<<i<<" ";
		cout<<"\n";
		int node;
		cin>>node>>d;
		int f=0;
		for(int i:lists)if(i==node){s=node;f=1;break;}
		if(!f)for(int j:listf)if(j==node){f=node;break;}
		dfs1(s,f,-1);
		mk[s]=mk[f]=0;
	}
	cout<<"! "<<s<<" "<<f<<"\n";
	string res;
	cin>>res;
}
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	//cout.tie(NULL);
	int t;
	cin>>t;
	//t=1;
	while(t--){
		solve();
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
vector<int>ed[1005];
int dd[1005];
int n;
int mk[1005];
vector<int>lists,listf;
void dfs(int i,int d,int p,int j){
	if(d==0){
		if(mk[i])return;
		if(j)listf.pb(i);
		else lists.pb(i);
	}
	for(int v:ed[i]){
		if(v==p)continue;
		dfs(v,d-1,i,j);
	}
}
int dfs1(int i,int f,int p){
	if(i==f)return 1;
	for(int j:ed[i]){
		if(j==p)continue;
		mk[i]|=dfs1(j,f,i);
	}
	return mk[i];
}
void dfs2(int i,int p,int di){
	dd[i]=di;
	for(int j:ed[i]){
		if(j==p)continue;
		dfs2(j,i,di+1);
	}
}
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++){
		ed[i].clear();
		mk[i]=0;
		dd[i]=0;
	}
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		ed[u].pb(v);
		ed[v].pb(u);
	}
	int root=1,d;
	cout<<"? "<<n<<" ";
	for(int i=1;i<=n;i++)cout<<i<<" ";cout<<"\n";
	cin>>root>>d;
	int s=root,f=root,cur=0;
	dfs2(root,-1,0);
	while(dd[s]+dd[f]<d){
		int p=(d-cur+1)/2;
		lists.clear();
		listf.clear();
		dfs(s,p,-1,0);
		dfs(f,p,-1,1);
		set<int>st;
		for(int i:lists)st.insert(i);
		for(int j:listf)st.insert(j);
		cout<<"? "<<st.size()<<" ";
		for(int i:st)cout<<i<<" ";cout<<"\n";
		int node;
		cin>>node>>d;
		int flag=0;
		for(int i:lists)if(i==node){s=node;flag=1;break;}
		if(!flag)for(int j:listf)if(j==node){f=node;break;}
		dfs1(s,f,-1);
		mk[s]=mk[f]=0;
		cur=dd[s]+dd[f];
	}
	cout<<"! "<<s<<" "<<f<<"\n";
	string res;
	cin>>res;
}
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	//cout.tie(NULL);
	int t;
	cin>>t;
	//t=1;
	while(t--){
		solve();
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
vector<int>ed[1005];
int dd[1005];
int n;
int mk[1005];
vector<int>lists,listf;
void dfs(int i,int d,int p,int j){
	if(d==0){
		if(mk[i])return;
		if(j)listf.pb(i);
		else lists.pb(i);
	}
	for(int v:ed[i]){
		if(v==p)continue;
		dfs(v,d-1,i,j);
	}
}
int dfs1(int i,int f,int p){
	if(i==f)return 1;
	for(int j:ed[i]){
		if(j==p)continue;
		mk[i]|=dfs1(j,f,i);
	}
	return mk[i];
}
void dfs2(int i,int p,int di){
	dd[i]=di;
	for(int j:ed[i]){
		if(j==p)continue;
		dfs2(j,i,di+1);
	}
}
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++){
		ed[i].clear();
		mk[i]=0;
		dd[i]=0;
	}
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		ed[u].pb(v);
		ed[v].pb(u);
	}
	int root=1,d;
	cout<<"? "<<n<<" ";
	for(int i=1;i<=n;i++)cout<<i<<" ";cout<<"\n";
	cin>>root>>d;
	int s=root,f=root,cur=0;
	dfs2(root,-1,0);
	while(dd[s]+dd[f]<d){
		int p=(d-cur+1)/2;
		lists.clear();
		listf.clear();
		dfs(s,p,-1,0);
		dfs(f,p,-1,1);
		set<int>st;
		for(int i:lists)st.insert(i);
		for(int j:listf)st.insert(j);
		cout<<"? "<<st.size()<<" ";
		for(int i:st)cout<<i<<" ";cout<<"\n";
		int node;
		cin>>node>>d;
		int f=0;
		for(int i:lists)if(i==node){s=node;f=1;break;}
		if(!f)for(int j:listf)if(j==node){f=node;break;}
		dfs1(s,f,-1);
		mk[s]=mk[f]=0;
		cur=dd[s]+dd[f];
	}
	cout<<"! "<<s<<" "<<f<<"\n";
	string res;
	cin>>res;
}
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	//cout.tie(NULL);
	int t;
	cin>>t;
	//t=1;
	while(t--){
		solve();
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
vector<int>ed[1005];
int dd[1005];
int n;
int mk[1005];
vector<int>lists,listf;
void dfs(int i,int d,int p,int j){
	if(d==0){
		if(mk[i])return;
		if(j)listf.pb(i);
		else lists.pb(i);
	}
	for(int v:ed[i]){
		if(v==p)continue;
		dfs(v,d-1,i,j);
	}
}
int dfs1(int i,int f,int p){
	if(i==f)return 1;
	for(int j:ed[i]){
		if(j==p)continue;
		mk[i]|=dfs1(j,f,i);
	}
	return mk[i];
}
void dfs2(int i,int p,int di){
	dd[i]=di;
	for(int j:ed[i]){
		if(j==p)continue;
		dfs2(j,i,di+1);
	}
}
void solve(){
	for(int i=1;i<=n;i++){
		ed[i].clear();
		mk[i]=0;
		dd[i]=0;
	}
	cin>>n;
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		ed[u].pb(v);
		ed[v].pb(u);
	}
	int root=1,d;
	cout<<"? "<<n<<" ";
	for(int i=1;i<=n;i++)cout<<i<<" ";cout<<"\n";
	cin>>root>>d;
	int s=root,f=root,cur=0;
	dfs2(root,-1,0);
	while(dd[s]+dd[f]<d){
		int p=(d-cur+1)/2;
		lists.clear();
		listf.clear();
		dfs(s,p,-1,0);
		dfs(f,p,-1,1);
		set<int>st;
		for(int i:lists)st.insert(i);
		for(int j:listf)st.insert(j);
		cout<<"? "<<st.size()<<" ";
		for(int i:st)cout<<i<<" ";
		cout<<"\n";
		int node;
		cin>>node>>d;
		int f=0;
		for(int i:lists)if(i==node){s=node;f=1;break;}
		if(!f)for(int j:listf)if(j==node){f=node;break;}
		dfs1(s,f,-1);
		mk[s]=mk[f]=0;
	}
	cout<<"! "<<s<<" "<<f<<"\n";
	string res;
	cin>>res;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin>>t;
	t=1;
	while(t--){
		solve();
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
vector<int>ed[1005];
int dd[1005];
int n;
int mk[1005];
vector<int>lists,listf;
void dfs(int i,int d,int p,int j){
	if(d==0){
		if(mk[i])return;
		if(j)listf.pb(i);
		else lists.pb(i);
		return;
	}
	for(int v:ed[i]){
		if(v==p)continue;
		dfs(v,d-1,i,j);
	}
}
int dfs1(int i,int f,int p){
	if(i==f)return mk[i]=1;
	for(int j:ed[i]){
		if(j==p)continue;
		mk[i]|=dfs1(j,f,i);
	}
	return mk[i];
}
void dfs2(int i,int p,int di){
	dd[i]=di;
	for(int j:ed[i]){
		if(j==p)continue;
		dfs2(j,i,di+1);
	}
}
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++){
		ed[i].clear();
		mk[i]=0;
		dd[i]=0;
	}
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		ed[u].pb(v);
		ed[v].pb(u);
	}
	int root=1,d;
	cout<<"? "<<n<<" ";
	for(int i=1;i<=n;i++)cout<<i<<" ";cout<<"\n";
	cin>>root>>d;
	int s=root,f=root,cur=0;
	dfs2(root,-1,0);
	while(dd[s]+dd[f]<d){
		int p=(d-cur+1)/2;
		cout<<s<<" "<<f<<"\n";
		lists.clear();
		listf.clear();
		dfs(s,p,-1,0);
		dfs(f,p,-1,1);
		set<int>st;
		for(int i:lists)st.insert(i);
		for(int j:listf)st.insert(j);
		cout<<"? "<<st.size()<<" ";
		for(int i:st)cout<<i<<" ";cout<<"\n";
		int node;
		cin>>node>>d;
		int flag=0;
		for(int i:lists)if(i==node){s=node;flag=1;break;}
		if(!flag)for(int j:listf)if(j==node){f=node;break;}
		dfs1(s,f,-1);
		//mk[s]=mk[f]=0;
		cur=dd[s]+dd[f];
	}
	cout<<"! "<<s<<" "<<f<<"\n";
	string res;
	cin>>res;
}
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	//cout.tie(NULL);
	int t;
	cin>>t;
	//t=1;
	while(t--){
		solve();
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

int n, rt, d, dep[1005], idx, dfn[1005], ed[1005];
std::vector<int> E[1005];

std::pair<int, int> Query(const std::vector<int> &A) {
	if (A.empty()) {
		return {0, 0x3f3f3f3f};
	}
	printf("? %d", (int)A.size());
	for (int i : A) {
		printf(" %d", i);
	}
	putchar('\n');
	fflush(stdout);
	int x, y;
	scanf("%d%d", &x, &y);
	return {x, y};
}

void dfs(int u, int fa = 0) {
	dfn[u] = ++idx;
	for (int v : E[u]) {
		if (v != fa) {
			dep[v] = dep[u] + 1;
			dfs(v, u);
		}
	}
	ed[u] = idx;
}

bool isGF(int u, int v) {
	return dfn[u] <= dfn[v] && dfn[v] <= ed[u];
}

void solve() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		E[i].clear();
	}
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(v), E[v].push_back(u);
	}
	std::vector<int> id;
	for (int i = 1; i <= n; ++i) {
		id.push_back(i);
	}
	std::pair<int, int> tmp = Query(id);
	rt = tmp.first, d = tmp.second;
	idx = 0, dep[rt] = 0, dfs(rt);
	int l = d / 2, r = d, md, x = rt;
	while (l <= r) {
		md = (l + r) >> 1;
		id.clear();
		for (int i = 1; i <= n; ++i) {
			if (isGF(x, i) && dep[i] == md) {
				id.push_back(i);
			}
		}
		tmp = Query(id);
		if (tmp.second == d) {
			x = tmp.first;
			l = md + 1;
		} else {
			r = md - 1;
		}
	}
	idx = 0, dep[x] = 0, dfs(x);
	id.clear();
	for (int i = 1; i <= n; ++i) {
		if (dep[i] == d) {
			id.push_back(i);
		}
	}
	printf("! %d %d\n", x, Query(id).first);
	fflush(stdout);
	static char ret[25];
	scanf("%s", ret);
}

int main() {
	int T = 1;
	scanf("%d", &T);
	while (T--) {
		solve();
	}
}
/*
1
10
9 7
6 10
8 2
4 10
1 5
6 8
3 10
3 9
2 5

6 5
*/


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

int n, rt, d, dep[1005], idx, dfn[1005], ed[1005];
std::vector<int> E[1005];

std::pair<int, int> Query(const std::vector<int> &A) {
	printf("? %d", (int)A.size());
	for (int i : A) {
		printf(" %d", i);
	}
	putchar('\n');
	fflush(stdout);
	int x, y;
	scanf("%d%d", &x, &y);
	return {x, y};
}

void dfs(int u, int fa = 0) {
	dfn[u] = ++idx;
	for (int v : E[u]) {
		if (v != fa) {
			dep[v] = dep[u] + 1;
			dfs(v, u);
		}
	}
	ed[u] = idx;
}

bool isGF(int u, int v) {
	return dfn[u] <= dfn[v] && dfn[v] <= ed[u];
}

void solve() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		E[i].clear();
	}
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(v), E[v].push_back(u);
	}
	std::vector<int> id;
	for (int i = 1; i <= n; ++i) {
		id.push_back(i);
	}
	std::pair<int, int> tmp = Query(id);
	rt = tmp.first, d = tmp.second;
	idx = 0, dep[rt] = 0, dfs(rt);
	int l = d / 2, r = d, md, x = rt;
	while (l <= r) {
		md = (l + r) >> 1;
		id.clear();
		for (int i = 1; i <= n; ++i) {
			if (isGF(x, i) && dep[i] == md) {
				id.push_back(i);
			}
		}
		tmp = Query(id);
		if (tmp.second == d) {
			x = tmp.first;
			l = md + 1;
		} else {
			r = md - 1;
		}
	}
	idx = 0, dep[x] = 0, dfs(x);
	id.clear();
	for (int i = 1; i <= n; ++i) {
		if (dep[i] == d) {
			id.push_back(i);
		}
	}
	printf("! %d %d\n", x, Query(id).first);
	fflush(stdout);
	static char ret[25];
	scanf("%s", ret);
}

int main() {
	int T = 1;
	scanf("%d", &T);
	while (T--) {
		solve();
	}
}
/*
1
10
9 7
6 10
8 2
4 10
1 5
6 8
3 10
3 9
2 5

6 5
*/


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

int n, rt, d, dep[1005], idx, dfn[1005], ed[1005];
std::vector<int> E[1005];

std::pair<int, int> Query(const std::vector<int> &A) {
	printf("? %d", (int)A.size());
	for (int i : A) {
		printf(" %d", i);
	}
	putchar('\n');
	fflush(stdout);
	int x, y;
	scanf("%d%d", &x, &y);
	return {x, y};
}

void dfs(int u, int fa = 0) {
	dfn[u] = ++idx;
	for (int v : E[u]) {
		if (v != fa) {
			dep[v] = dep[u] + 1;
			dfs(v, u);
		}
	}
	ed[u] = idx;
}

bool isGF(int u, int v) {
	return dfn[u] <= dfn[v] && dfn[v] <= ed[u];
}

void solve() {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(v), E[v].push_back(u);
	}
	std::vector<int> id;
	for (int i = 1; i <= n; ++i) {
		id.push_back(i);
	}
	std::pair<int, int> tmp = Query(id);
	rt = tmp.first, d = tmp.second;
	dep[rt] = 0, dfs(rt);
	int l = d / 2, r = d, md, x = rt;
	while (l <= r) {
		md = (l + r) >> 1;
		id.clear();
		for (int i = 1; i <= n; ++i) {
			if (isGF(x, i) && dep[i] == md) {
				id.push_back(i);
			}
		}
		tmp = Query(id);
		if (tmp.second == d) {
			x = tmp.first;
			l = md + 1;
		} else {
			r = md - 1;
		}
	}
	dep[x] = 0, dfs(x);
	id.clear();
	for (int i = 1; i <= n; ++i) {
		if (dep[i] == d) {
			id.push_back(i);
		}
	}
	printf("! %d %d\n", x, Query(id).first);
	fflush(stdout);
	static char ret[25];
	scanf("%s", ret);
}

int main() {
	int T = 1;
	scanf("%d", &T);
	while (T--) {
		solve();
	}
}


#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int T,n,eu,ev,depth[1020],mix,vis1[1020],vis2[1020];
vector<int> ga[1020],package,nodes[1020];
int min_dist,min_pos,leng,root;
string info;
void ask(){
	cout<<"? "<<package.size();
	for(int i=0;i<package.size();i++)
		cout<<" "<<package[i];
	cout<<endl;cout.flush();
	cin>>min_pos>>min_dist;
}
void ask(int id){
	if(vis1[id]){
		min_dist=vis1[id];
		min_pos=vis2[id];
		return;
	}
	package=nodes[id];
	ask();
	vis1[id]=min_dist;
	vis2[id]=min_pos;
}
void dfs(int cur,int par){
	mix=max(mix,depth[cur]);
	for(int nxt:ga[cur])
		if(nxt!=par){
			depth[nxt]=depth[cur]+1;
			dfs(nxt,cur);
		}
}
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++) ga[i].clear();
	for(int i=1;i<n;i++){
		cin>>eu>>ev;
		ga[eu].push_back(ev);
		ga[ev].push_back(eu);
	}
	package.clear();
	for(int i=1;i<=n;i++) package.push_back(i);
	ask();
	leng=min_dist;root=min_pos;depth[root]=0;
	mix=0;
	dfs(root,-1);
	for(int i=0;i<=mix;i++) vis1[i]=0;
	for(int i=0;i<=mix;i++) vis2[i]=0;
	for(int i=1;i<=n;i++)
		nodes[depth[i]].push_back(i);
	int le=0,ri=min(leng/2,mix),mi;
	while(le<ri){
		mi=(le+ri)/2;
		ask(mi);
		if(min_dist==leng) ri=mi;
		else le=mi+1;
	}
	int a1,a2;
	ask(le);
	a1=min_pos;
	package.clear();
	for(int i=1;i<=n;i++) if(depth[i]==leng-le&&i!=a1)
		package.push_back(i);
	ask();
	a2=min_pos;
	cout<<"! "<<a1<<" "<<a2<<endl;
	cout.flush();
	cin>>info;
}
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>T;
	while(T--) solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = 1010;
int dd[N][N];
vector<int> T[N];
void dfs(int u, int par, int di, int root){
    dd[root][u] = di;
    for(auto x : T[u]){
        if(x == par) continue;
        dfs(x, u, di + 1, root);
    }
}
pii query(vector<int> ask){
    cout << "? " << ask.size() << " ";
    for(auto x : ask) cout << x << " ";
    cout << "\n";
    fflush(stdout);
    pii ans;
    cin >> ans.fi >> ans.se;
    return ans;
}
void solve(){
    int n;
    cin >> n;
    int u, v;
    for(int i = 1; i <= n; i ++ ) T[i].clear();
    for(int i = 1; i < n; i ++ ){
        cin >> u >> v;
        T[u].push_back(v);
        T[v].push_back(u);
    }
    for(int i = 1; i <= n; i ++ ) dfs(i, -1, 0, i);
    pii ss;
    vector<int> qq;
    for(int i = 1; i <= n; i ++ ) qq.push_back(i);
    ss = query(qq);
    int root = ss.fi;
    int len = ss.se;
    int l = (len+1)/2-1, r = len+1;
    int mid;
    bool good;
    pii fsh;
    while(l + 1 < r){
        mid = (l + r) / 2;
        vector<int> ask;
        good = true;
        for(int i = 1; i <=n ; i ++ )
            if(dd[root][i] == mid)
                ask.push_back(i);
        if(ask.empty()) good = false;
        else{
            ss = query(ask);
            if(ss.se != len) good = false;
            else good = true;
        }
        if(good){
            fsh = ss;
            l = mid;
        }
        else r = mid;
    }
    int v1 = fsh.fi;
    vector<int> ask;
    for(int i = 1; i <= n; i ++ )
        if(dd[v1][i] == len)
            ask.push_back(i);
    ss = query(ask);
    int v2 = ss.fi;
    cout << "! " << v1 << " " << v2 << "\n";
    fflush(stdout);
    string res;
    cin >> res;
}
int main(){
    int tc;
    cin >> tc;
    for(int t = 0 ; t < tc; t ++ )
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int T,n,eu,ev,depth[1020],mix,vis1[1020],vis2[1020];
vector<int> ga[1020],package,nodes[1020];
int min_dist,min_pos,leng,root;
string info;
void ask(){
	cout<<"? "<<package.size();
	for(int i=0;i<package.size();i++)
		cout<<" "<<package[i];
	cout<<endl;cout.flush();
	cin>>min_pos>>min_dist;
}
void ask(int id){
	if(vis1[id]){
		min_dist=vis1[id];
		min_pos=vis2[id];
		return;
	}
	package=nodes[id];
	ask();
	vis1[id]=min_dist;
	vis2[id]=min_pos;
}
void dfs(int cur,int par){
	mix=max(mix,depth[cur]);
	for(int nxt:ga[cur])
		if(nxt!=par){
			depth[nxt]=depth[cur]+1;
			dfs(nxt,cur);
		}
}
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++) ga[i].clear();
	for(int i=1;i<n;i++){
		cin>>eu>>ev;
		ga[eu].push_back(ev);
		ga[ev].push_back(eu);
	}
	package.clear();
	for(int i=1;i<=n;i++) package.push_back(i);
	ask();
	leng=min_dist;root=min_pos;depth[root]=0;
	mix=0;
	dfs(root,-1);
	for(int i=0;i<=mix;i++) vis1[i]=0;
	for(int i=0;i<=mix;i++) vis2[i]=0;
	for(int i=1;i<=n;i++)
		nodes[depth[i]].push_back(i);
	int le=0,ri=min(leng/2,mix),mi;
	while(le<ri){
		mi=(le+ri+1)/2;
		ask(mi);
		if(min_dist!=leng) ri=mi-1;
		else le=mi;
	}
	int a1,a2;
	ask(le);
	a1=min_pos;
	ask(leng-le);
	a2=min_pos;
	cout<<"! "<<a1<<" "<<a2<<endl;
	cin>>info;
}
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>T;
	while(T--) solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = 1010;
int dd[N][N];
vector<int> T[N];
void dfs(int u, int par, int di, int root){
    dd[root][u] = di;
    for(auto x : T[u]){
        if(x == par) continue;
        dfs(x, u, di + 1, root);
    }
}
pii query(vector<int> ask){
    cout << "? " << ask.size() << " ";
    for(auto x : ask) cout << x << " ";
    cout << "\n";
    fflush(stdout);
    pii ans;
    cin >> ans.fi >> ans.se;
    return ans;
}
void solve(){
    int n;
    cin >> n;
    int u, v;
    for(int i = 1; i <= n; i ++ ) T[i].clear();
    for(int i = 1; i < n; i ++ ){
        cin >> u >> v;
        T[u].push_back(v);
        T[v].push_back(u);
    }
    for(int i = 1; i <= n; i ++ ) dfs(i, -1, 0, i);
    pii ss;
    vector<int> qq;
    for(int i = 1; i <= n; i ++ ) qq.push_back(i);
    ss = query(qq);
    int root = ss.fi;
    int len = ss.se;
    int l = (len+1)/2, r = len+1;
    int mid;
    bool good;
    while(l + 1 < r){
        mid = (l + r) / 2;
        vector<int> ask;
        good = true;
        for(int i = 1; i <=n ; i ++ )
            if(dd[root][i] == mid)
                ask.push_back(i);
        if(ask.empty()) good = false;
        else{
            ss = query(ask);
            if(ss.se != len)  good = false;
            else good = true;
        }
        if(good) l = mid;
        else r = mid;
    }
    vector<int> ask;
    for(int i = 1; i <= n; i ++ )
        if(dd[root][i] == l)
            ask.push_back(i);
    ss = query(ask);
    int v1 = ss.fi;
    ask.clear();
    for(int i = 1; i <= n; i ++ )
        if(dd[v1][i] == len)
            ask.push_back(i);
    ss = query(ask);
    int v2 = ss.fi;
    cout << "! " << v1 << " " << v2 << "\n";
    fflush(stdout);
    string res;
    cin >> res;
}
int main(){
    int tc;
    cin >> tc;
    for(int t = 0 ; t < tc; t ++ )
        solve();
    return 0;
}


#include <bits/stdc++.h>
//#include <unordered_map>

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb push_back
#define sz(x) (int)x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)z
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(str) scanf("%s",str)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define NL printf("\n")
#define Max 200005
#define INF 1e15
#define mod 1000000007
#define un(x) x.erase(unique( x.begin() , x.end() ), x.end())

#define FI freopen("z.txt","r",stdin)

#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define DDD(x,y,z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl
#define all(x) x.begin(),x.end()
#define prntvctr(x) for(int i = 0; i < x.size(); i++) printf("%d%c", x[i], i + 1 == x.size() ? '\n' : ' ' );
#define pc(x) __builtin_popcount(x)

#define pii pair <int, int>

typedef long long LL;
typedef unsigned long long ULL;

const long double PI = acos(-1.0);

using namespace std;

int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
bool checkb(int n, int pos)
{
    return (bool)(n & (1 << pos));
}

inline LL bigmod(LL b, LL p, LL m)
{
    LL ret = 1, cur = b % m;
    while( p )
    {
        if(p & 1) ret = ( ret * cur ) % m;
        cur = ( cur * cur ) % m;
        p = p >> 1;
    }
    return ret;
}

int n;
vector <int> g[1005];

pii ask(vector <int> v)
{
    printf("? %d", v.size());
    for(int i = 0; i < v.size(); i++) printf(" %d", v[i]);
    puts("");
    fflush(stdout);

    int u, d;
    scanf("%d %d", &u, &d);
    return {u, d};
}

pii init()
{
    vector <int> v;
    for(int i = 1; i <= n; i++) v.pb( i );
    return ask(v);
}

int ara[1002][1002];
void dfs(int root, int u, int p, int d)
{
    ara[root][u] = d;
    for(int i = 0; i < g[u].size(); i++)
    {
        int v = g[u][i];
        if( v == p ) continue;
        dfs(root, v, u, d + 1);
    }
}

void prework()
{
    for(int i = 1; i <= n; i++) dfs(i, i, i, 0);
}

vector <int> get_all(int u, int d)
{
    vector <int> ret;
    for(int i = 1; i <= n; i++)
    {
        //DDD(u, i, ara[u][i]);
        if( ara[u][i] >= d ) ret.pb( i );
    }
    return ret;
}

int get_mid(int x, int y)
{
    return (x + y + 1) / 2;
}

void solve()
{
    prework();

    int root, d;
    pii now = init();
    root = now.first;
    d = now.second;

    int low = d / 2, high = d, mid, ans = -1;
    while( low <= high )
    {
        mid = get_mid(low, high);
        int current_d = d + 2;
        int current_u = -1;

        vector <int> v = get_all(root, mid);
        if( v.size() > 0 )
        {
            pii now = ask(v);
            current_d = now.second;
            current_u = now.first;
        }
        if( current_d == d )
        {
            ans = current_u;
            low = mid + 1;
        }
        else high = mid - 1;
    }

    vector <int> v = get_all(ans, d);
    now = ask(v);

    printf("! %d %d\n", ans, now.first);
    fflush(stdout);

    char str[105];
    scanf("%s", str);
    assert( strcmp(str, "Correct") == 0 );
}

void Clear()
{
    for(int i = 1; i <= n; i++) g[i].clear();
}

int main()
{
    int t, T, i, x, y;
    si(T);
    rep(t, T)
    {
        si(n);
        rep(i, n - 1)
        {
            sii(x, y);
            g[x].pb(y);
            g[y].pb(x);
        }
        solve();
        Clear();
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <unordered_map>

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb push_back
#define sz(x) (int)x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)z
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(str) scanf("%s",str)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define NL printf("\n")
#define Max 200005
#define INF 1e15
#define mod 1000000007
#define un(x) x.erase(unique( x.begin() , x.end() ), x.end())

#define FI freopen("z.txt","r",stdin)

#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define DDD(x,y,z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl
#define all(x) x.begin(),x.end()
#define prntvctr(x) for(int i = 0; i < x.size(); i++) printf("%d%c", x[i], i + 1 == x.size() ? '\n' : ' ' );
#define pc(x) __builtin_popcount(x)

#define pii pair <int, int>

typedef long long LL;
typedef unsigned long long ULL;

const long double PI = acos(-1.0);

using namespace std;

int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
bool checkb(int n, int pos)
{
    return (bool)(n & (1 << pos));
}

inline LL bigmod(LL b, LL p, LL m)
{
    LL ret = 1, cur = b % m;
    while( p )
    {
        if(p & 1) ret = ( ret * cur ) % m;
        cur = ( cur * cur ) % m;
        p = p >> 1;
    }
    return ret;
}

int n;
vector <int> g[1005];

pii ask(vector <int> v)
{
    printf("? %d", v.size());
    for(int i = 0; i < v.size(); i++) printf(" %d", v[i]);
    puts("");
    fflush(stdout);

    int u, d;
    scanf("%d %d", &u, &d);
    return {u, d};
}

pii init()
{
    vector <int> v;
    for(int i = 1; i <= n; i++) v.pb( i );
    return ask(v);
}

int ara[1002][1002];
void dfs(int root, int u, int p, int d)
{
    ara[root][u] = d;
    for(int i = 0; i < g[u].size(); i++)
    {
        int v = g[u][i];
        if( v == p ) continue;
        dfs(root, v, u, d + 1);
    }
}

void prework()
{
    for(int i = 1; i <= n; i++) dfs(i, i, i, 0);
}

vector <int> get_all(int u, int d)
{
    vector <int> ret;
    for(int i = 1; i <= n; i++)
    {
        //DDD(u, i, ara[u][i]);
        if( ara[u][i] >= d ) ret.pb( i );
    }
    return ret;
}

int get_mid(int x, int y)
{
    return (x + y + 1) / 2;
}

void solve()
{
    prework();

    int root, d;
    pii now = init();
    root = now.first;
    d = now.second;

    int low = 1, high = d, mid, ans = -1;
    while( low <= high )
    {
        mid = get_mid(low, high);
        //D(mid);
        int current_d = d + 2;
        int current_u = -1;

        vector <int> v = get_all(root, mid);
        if( v.size() > 0 )
        {
            pii now = ask(v);
            current_d = now.second;
            current_u = now.first;
        }
        if( current_d == d )
        {
            ans = current_u;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    //D(ans);
    //D("helolo");

    vector <int> v = get_all(ans, d);
    now = ask(v);

    printf("! %d %d\n", ans, now.first);
    fflush(stdout);

    char str[105];
    scanf("%s", str);
    assert( strcmp(str, "Correct") == 0 );
}

void Clear()
{
    for(int i = 1; i <= n; i++) g[i].clear();
}

int main()
{
    int t, T, i, x, y;
    si(T);
    rep(t, T)
    {
        si(n);
        rep(i, n - 1)
        {
            sii(x, y);
            g[x].pb(y);
            g[y].pb(x);
        }
        solve();
        Clear();
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <unordered_map>

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb push_back
#define sz(x) (int)x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)z
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(str) scanf("%s",str)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define NL printf("\n")
#define Max 200005
#define INF 1e15
#define mod 1000000007
#define un(x) x.erase(unique( x.begin() , x.end() ), x.end())

#define FI freopen("z.txt","r",stdin)

#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define DDD(x,y,z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl
#define all(x) x.begin(),x.end()
#define prntvctr(x) for(int i = 0; i < x.size(); i++) printf("%d%c", x[i], i + 1 == x.size() ? '\n' : ' ' );
#define pc(x) __builtin_popcount(x)

#define pii pair <int, int>

typedef long long LL;
typedef unsigned long long ULL;

const long double PI = acos(-1.0);

using namespace std;

int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
bool checkb(int n, int pos)
{
    return (bool)(n & (1 << pos));
}

inline LL bigmod(LL b, LL p, LL m)
{
    LL ret = 1, cur = b % m;
    while( p )
    {
        if(p & 1) ret = ( ret * cur ) % m;
        cur = ( cur * cur ) % m;
        p = p >> 1;
    }
    return ret;
}

int n;
vector <int> g[1005];

pii ask(vector <int> v)
{
    printf("? %d", v.size());
    for(int i = 0; i < v.size(); i++) printf(" %d", v[i]);
    puts("");
    fflush(stdout);

    int u, d;
    scanf("%d %d", &u, &d);
    return {u, d};
}

pii init()
{
    vector <int> v;
    for(int i = 1; i <= n; i++) v.pb( i );
    return ask(v);
}

int ara[1002][1002];
void dfs(int root, int u, int p, int d)
{
    ara[root][u] = d;
    for(int i = 0; i < g[u].size(); i++)
    {
        int v = g[u][i];
        if( v == p ) continue;
        dfs(root, v, u, d + 1);
    }
}

void prework()
{
    for(int i = 1; i <= n; i++) dfs(i, i, i, 0);
}

vector <int> get_all(int u, int d)
{
    vector <int> ret;
    for(int i = 1; i <= n; i++)
    {
        //DDD(u, i, ara[u][i]);
        if( ara[u][i] >= d ) ret.pb( i );
    }
    return ret;
}

void solve()
{
    prework();

    int root, d;
    pii now = init();
    root = now.first;
    d = now.second;

    int low = 1, high = d, mid, ans = -1;
    while( low <= high )
    {
        mid = (low + high) / 2;
        //D(mid);
        int current_d = d + 2;
        int current_u = -1;

        vector <int> v = get_all(root, mid);
        if( v.size() > 0 )
        {
            pii now = ask(v);
            current_d = now.second;
            current_u = now.first;
        }
        if( current_d == d )
        {
            ans = current_u;
            low = mid + 1;
        }
        else high = mid - 1;
    }
    //D(ans);
    //D("helolo");

    vector <int> v = get_all(ans, d);
    now = ask(v);

    printf("! %d %d\n", ans, now.first);
    fflush(stdout);

    char str[105];
    scanf("%s", str);
    assert( strcmp(str, "Correct") == 0 );
}

void Clear()
{
    for(int i = 1; i <= n; i++) g[i].clear();
}

int main()
{
    int t, T, i, x, y;
    si(T);
    rep(t, T)
    {
        si(n);
        rep(i, n - 1)
        {
            sii(x, y);
            g[x].pb(y);
            g[y].pb(x);
        }
        solve();
        Clear();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define ll long long
const int inf = 0x3f3f3f3f;
const int maxn = 1000 + 10;

int n;
vector<int> edge[maxn];
vector<int> gu;
int dis[maxn];
vector<int> level[maxn];

void print(int a[], int n, int st = 0) {
    for (int i = 0; i < n; i++) {
        if (i != 0) printf(" ");
        printf("%d", a[i + st]);
    }
    printf("\n");
}
void init() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) edge[i].clear();
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
}
void guess(vector<int> a, int &u, int &value) {
    printf("? %d", int(a.size()));
    for (int i = 0; i < a.size(); i++) printf(" %d", a[i]);
    printf("\n");
    fflush(stdout);
    scanf("%d%d", &u, &value);
}
void answer(int u1, int u2) {
    char s[20];
    printf("! %d %d\n", u1, u2);
    fflush(stdout);
    scanf("%s", s);
}
void dfs(int u) {
    for (int i = 0; i < edge[u].size(); i++) {
        int v = edge[u][i];
        if (dis[v] == -1) {
            dis[v] = dis[u] + 1;
            level[dis[v]].push_back(v);
            dfs(v);
        }
    }
}
void doit() {
    int r, len, k1, k2;
    gu.clear();
    for (int i = 1; i <= n; i++) gu.push_back(i);
    guess(gu, r, len);
    for (int i = 0; i <= n; i++) level[i].clear();
    for (int i = 0; i <= n; i++) dis[i] = -1;
    dis[r] = 0;
    level[0].push_back(r);
    dfs(r);
    int left = (len + 1) / 2, right = len, mid, ans, u, d;
    while (left <= right) {
        mid = (left + right) >> 1;
        guess(level[mid], u, d);
        if (d <= len) {
            ans = mid;
            k1 = u;
            left = mid + 1;
        }
        else {
            right = mid - 1;
        }
    }
    if (ans == len) {
        answer(r, k1);
        return;
    }
    gu.clear();
    for (int i = 0; i < level[len - ans].size(); i++) {
        if (level[len - ans][i] != k1) {
            gu.push_back(level[len - ans][i]);
        }
    }
    guess(gu, k2, d);
    answer(k1, k2);
}
int main()
{
    //freopen("test.in", "r", stdin);
    int t;
    scanf("%d", &t);
    while (t--) {
        init();
        doit();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define ll long long
const int inf = 0x3f3f3f3f;
const int maxn = 1000 + 10;

int n;
vector<int> edge[maxn];
vector<int> gu;
int dis[maxn];
vector<int> level[maxn];

void print(int a[], int n, int st = 0) {
    for (int i = 0; i < n; i++) {
        if (i != 0) printf(" ");
        printf("%d", a[i + st]);
    }
    printf("\n");
}
void init() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) edge[i].clear();
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
}
void guess(vector<int> a, int &u, int &value) {
    printf("? %d", int(a.size()));
    for (int i = 0; i < a.size(); i++) printf(" %d", a[i]);
    printf("\n");
    fflush(stdout);
    scanf("%d%d", &u, &value);
}
void answer(int u1, int u2) {
    char s[20];
    printf("! %d %d\n", u1, u2);
    fflush(stdout);
    scanf("%s", s);
}
int maxLevel = 0;
void dfs(int u) {
    for (int i = 0; i < edge[u].size(); i++) {
        int v = edge[u][i];
        if (dis[v] == -1) {
            dis[v] = dis[u] + 1;
            maxLevel = max(maxLevel, dis[v]);
            level[dis[v]].push_back(v);
            dfs(v);
        }
    }
}
void doit() {
    int r, len, k1, k2;
    gu.clear();
    for (int i = 1; i <= n; i++) gu.push_back(i);
    guess(gu, r, len);
    for (int i = 0; i <= n; i++) level[i].clear();
    for (int i = 0; i <= n; i++) dis[i] = -1;
    dis[r] = 0;
    level[0].push_back(r);
    dfs(r);
    int left = (len + 1) / 2, right = min(len, maxLevel), mid, ans, u, d;
    while (left <= right) {
        mid = (left + right) >> 1;
        guess(level[mid], u, d);
        if (d <= len) {
            ans = mid;
            k1 = u;
            left = mid + 1;
        }
        else {
            right = mid - 1;
        }
    }
    if (ans == len) {
        answer(r, k1);
        return;
    }
    gu.clear();
    for (int i = 0; i < level[len - ans].size(); i++) {
        if (level[len - ans][i] != k1) {
            gu.push_back(level[len - ans][i]);
        }
    }
    guess(gu, k2, d);
    answer(k1, k2);
}
int main()
{
    //freopen("test.in", "r", stdin);
    int t;
    scanf("%d", &t);
    while (t--) {
        init();
        doit();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define ll long long
const int inf = 0x3f3f3f3f;
const int maxn = 1000 + 10;

int n, maxLevel;
vector<int> edge[maxn];
vector<int> gu;
int dis[maxn];
vector<int> level[maxn];

void print(int a[], int n, int st = 0) {
    for (int i = 0; i < n; i++) {
        if (i != 0) printf(" ");
        printf("%d", a[i + st]);
    }
    printf("\n");
}
void init() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) edge[i].clear();
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
}
void guess(vector<int> a, int &u, int &value) {
    printf("? %d", int(a.size()));
    for (int i = 0; i < a.size(); i++) printf(" %d", a[i]);
    printf("\n");
    fflush(stdout);
    scanf("%d%d", &u, &value);
    if (u == -1) while (1);
}
void answer(int u1, int u2) {
    char s[20];
    printf("! %d %d\n", u1, u2);
    fflush(stdout);
    scanf("%s", s);
}
void dfs(int u) {
    for (int i = 0; i < edge[u].size(); i++) {
        int v = edge[u][i];
        if (dis[v] == -1) {
            dis[v] = dis[u] + 1;
            maxLevel = max(maxLevel, dis[v]);
            level[dis[v]].push_back(v);
            dfs(v);
        }
    }
}
void doit() {
    int r, len, k1, k2;
    gu.clear();
    for (int i = 1; i <= n; i++) gu.push_back(i);
    guess(gu, r, len);
    for (int i = 0; i <= n; i++) level[i].clear();
    for (int i = 0; i <= n; i++) dis[i] = -1;
    dis[r] = 0;
    level[0].push_back(r);
    maxLevel = 0;
    dfs(r);
    int left = (len + 1) / 2, right = min(len, maxLevel), mid, ans, u, d;
    while (left <= right) {
        mid = (left + right) >> 1;
        if (level[mid].size() == 0) while(1);
        guess(level[mid], u, d);
        if (d <= len) {
            ans = mid;
            k1 = u;
            left = mid + 1;
        }
        else {
            right = mid - 1;
        }
    }
    if (ans == len) {
        answer(r, k1);
        return;
    }
    gu.clear();
    for (int i = 0; i < level[len - ans].size(); i++) {
        if (level[len - ans][i] != k1) {
            gu.push_back(level[len - ans][i]);
        }
    }
    guess(gu, k2, d);
    answer(k1, k2);
}
int main()
{
    //freopen("test.in", "r", stdin);
    int t;
    scanf("%d", &t);
    while (t--) {
        init();
        doit();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define ll long long
const int inf = 0x3f3f3f3f;
const int maxn = 1000 + 10;

int n, maxLevel;
vector<int> edge[maxn];
vector<int> gu;
int dis[maxn];
vector<int> level[maxn];

void print(int a[], int n, int st = 0) {
    for (int i = 0; i < n; i++) {
        if (i != 0) printf(" ");
        printf("%d", a[i + st]);
    }
    printf("\n");
}
void init() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) edge[i].clear();
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
}
void guess(vector<int> a, int &u, int &value) {
    printf("? %d", int(a.size()));
    for (int i = 0; i < a.size(); i++) printf(" %d", a[i]);
    printf("\n");
    fflush(stdout);
    scanf("%d%d", &u, &value);
}
void answer(int u1, int u2) {
    char s[20];
    printf("! %d %d\n", u1, u2);
    fflush(stdout);
    scanf("%s", s);
}
void dfs(int u) {
    for (int i = 0; i < edge[u].size(); i++) {
        int v = edge[u][i];
        if (dis[v] == -1) {
            dis[v] = dis[u] + 1;
            maxLevel = max(maxLevel, dis[v]);
            level[dis[v]].push_back(v);
            dfs(v);
        }
    }
}
void doit() {
    int r, len, k1, k2;
    gu.clear();
    for (int i = 1; i <= n; i++) gu.push_back(i);
    guess(gu, r, len);
    for (int i = 0; i <= n; i++) level[i].clear();
    for (int i = 0; i <= n; i++) dis[i] = -1;
    dis[r] = 0;
    level[0].push_back(r);
    maxLevel = 0;
    dfs(r);
    int left = (len + 1) / 2, right = min(len, maxLevel), mid, ans, u, d;
    while (left <= right) {
        mid = (left + right) >> 1;
        guess(level[mid], u, d);
        if (d <= len) {
            ans = mid;
            k1 = u;
            left = mid + 1;
        }
        else {
            right = mid - 1;
        }
    }
    if (ans == len) {
        answer(r, k1);
        return;
    }
    gu.clear();
    for (int i = 0; i < level[len - ans].size(); i++) {
        if (level[len - ans][i] != k1) {
            gu.push_back(level[len - ans][i]);
        }
    }
    guess(gu, k2, d);
    answer(k1, k2);
}
int main()
{
    //freopen("test.in", "r", stdin);
    int t;
    scanf("%d", &t);
    while (t--) {
        init();
        doit();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define ll long long
const int inf = 0x3f3f3f3f;
const int maxn = 1000 + 10;

int n, maxLevel;
vector<int> edge[maxn];
vector<int> gu;
int dis[maxn];
vector<int> level[maxn];

void print(int a[], int n, int st = 0) {
    for (int i = 0; i < n; i++) {
        if (i != 0) printf(" ");
        printf("%d", a[i + st]);
    }
    printf("\n");
}
void init() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) edge[i].clear();
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
}
void guess(vector<int> a, int &u, int &value) {
    printf("? %d", int(a.size()));
    for (int i = 0; i < a.size(); i++) printf(" %d", a[i]);
    printf("\n");
    fflush(stdout);
    scanf("%d%d", &u, &value);
}
void answer(int u1, int u2) {
    char s[20];
    printf("! %d %d\n", u1, u2);
    fflush(stdout);
    scanf("%s", s);
}
void dfs(int u) {
    for (int i = 0; i < edge[u].size(); i++) {
        int v = edge[u][i];
        if (dis[v] == -1) {
            dis[v] = dis[u] + 1;
            maxLevel = max(maxLevel, dis[v]);
            level[dis[v]].push_back(v);
            dfs(v);
        }
    }
}
void doit() {
    int r, len, k1, k2;
    gu.clear();
    for (int i = 1; i <= n; i++) gu.push_back(i);
    guess(gu, r, len);
    for (int i = 0; i <= n; i++) level[i].clear();
    for (int i = 0; i <= n; i++) dis[i] = -1;
    dis[r] = 0;
    level[0].push_back(r);
    maxLevel = 0;
    dfs(r);
    int left = (len + 1) / 2, right = min(len, maxLevel), mid, ans, u, d;
    while (left <= right) {
        mid = (left + right) >> 1;
        if (level[mid].size() == 0) while(1);
        guess(level[mid], u, d);
        if (d <= len) {
            ans = mid;
            k1 = u;
            left = mid + 1;
        }
        else {
            right = mid - 1;
        }
    }
    if (ans == len) {
        answer(r, k1);
        return;
    }
    gu.clear();
    for (int i = 0; i < level[len - ans].size(); i++) {
        if (level[len - ans][i] != k1) {
            gu.push_back(level[len - ans][i]);
        }
    }
    guess(gu, k2, d);
    answer(k1, k2);
}
int main()
{
    //freopen("test.in", "r", stdin);
    int t;
    scanf("%d", &t);
    while (t--) {
        init();
        doit();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define ll long long
const int inf = 0x3f3f3f3f;
const int maxn = 1000 + 10;

int n;
vector<int> edge[maxn];
vector<int> gu;
int dis[maxn];
vector<int> level[maxn];

void print(int a[], int n, int st = 0) {
    for (int i = 0; i < n; i++) {
        if (i != 0) printf(" ");
        printf("%d", a[i + st]);
    }
    printf("\n");
}
void init() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) edge[i].clear();
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
}
void guess(vector<int> a, int &u, int &value) {
    printf("? %d", int(a.size()));
    for (int i = 0; i < a.size(); i++) printf(" %d", a[i]);
    printf("\n");
    fflush(stdout);
    scanf("%d%d", &u, &value);
}
void answer(int u1, int u2) {
    printf("! %d %d\n", u1, u2);
    fflush(stdout);
}
void dfs(int u) {
    for (int i = 0; i < edge[u].size(); i++) {
        int v = edge[u][i];
        if (dis[v] == -1) {
            dis[v] = dis[u] + 1;
            level[dis[v]].push_back(v);
            dfs(v);
        }
    }
}
void doit() {
    int r, len, k1, k2;
    gu.clear();
    for (int i = 1; i <= n; i++) gu.push_back(i);
    guess(gu, r, len);
    for (int i = 0; i <= n; i++) level[i].clear();
    for (int i = 0; i <= n; i++) dis[i] = -1;
    dis[r] = 0;
    level[0].push_back(r);
    dfs(r);
    int left = (len + 1) / 2, right = len, mid, ans, u, d;
    while (left <= right) {
        mid = (left + right) >> 1;
        guess(level[mid], u, d);
        if (d <= len) {
            ans = mid;
            k1 = u;
            left = mid + 1;
        }
        else {
            right = mid - 1;
        }
    }
    if (ans == len) {
        answer(r, k1);
        return;
    }
    gu.clear();
    for (int i = 0; i < level[len - ans].size(); i++) {
        if (level[len - ans][i] != k1) {
            gu.push_back(level[len - ans][i]);
        }
    }
    guess(gu, k2, d);
    answer(k1, k2);
}
int main()
{
    //freopen("test.in", "r", stdin);
    int t;
    scanf("%d", &t);
    while (t--) {
        init();
        doit();
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define ll long long
const int inf = 0x3f3f3f3f;
const int maxn = 1000 + 10;

int n, maxLevel;
vector<int> edge[maxn];
vector<int> gu;
int dis[maxn];
vector<int> level[maxn];
int fa[maxn];
bool used[maxn];

void print(int a[], int n, int st = 0) {
    for (int i = 0; i < n; i++) {
        if (i != 0) printf(" ");
        printf("%d", a[i + st]);
    }
    printf("\n");
}
void init() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) edge[i].clear();
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
}
void guess(vector<int> a, int &u, int &value) {
    printf("? %d", int(a.size()));
    for (int i = 0; i < a.size(); i++) printf(" %d", a[i]);
    printf("\n");
    fflush(stdout);
    scanf("%d%d", &u, &value);
}
void answer(int u1, int u2) {
    char s[20];
    printf("! %d %d\n", u1, u2);
    fflush(stdout);
    scanf("%s", s);
}
void dfs(int u) {
    for (int i = 0; i < edge[u].size(); i++) {
        int v = edge[u][i];
        if (dis[v] == -1) {
            dis[v] = dis[u] + 1;
            fa[v] = u;
            maxLevel = max(maxLevel, dis[v]);
            level[dis[v]].push_back(v);
            dfs(v);
        }
    }
}
void doit() {
    int r, len, k1, k2;
    gu.clear();
    for (int i = 1; i <= n; i++) gu.push_back(i);
    guess(gu, r, len);
    for (int i = 0; i <= n; i++) level[i].clear();
    for (int i = 0; i <= n; i++) dis[i] = -1;
    dis[r] = 0;
    level[0].push_back(r);
    maxLevel = 0;
    dfs(r);
    int left = (len + 1) / 2, right = min(len, maxLevel), mid, ans, u, d;
    while (left <= right) {
        mid = (left + right) >> 1;
        guess(level[mid], u, d);
        if (d <= len) {
            ans = mid;
            k1 = u;
            left = mid + 1;
        }
        else {
            right = mid - 1;
        }
    }
    if (ans == len) {
        answer(r, k1);
        return;
    }
    u = k1;
    for (int i = 1; i <= n; i++) used[i] = false;
    while (u != r) {
        used[u] = true;
        u = fa[u];
    }
    gu.clear();
    for (int i = 0; i < level[len - ans].size(); i++) {
        if (!used[level[len - ans][i]]) {
            gu.push_back(level[len - ans][i]);
        }
    }
    guess(gu, k2, d);
    answer(k1, k2);
}
int main()
{
    //freopen("test.in", "r", stdin);
    int t;
    scanf("%d", &t);
    while (t--) {
        init();
        doit();
    }
    return 0;
}


/*Lucky_Glass*/
#include<cstdio>
#include<cassert>
#include<cstring>
#include<algorithm>
using namespace std;

#define ci const int &
const int N=1005;

struct GRAPH{
	int head[N],to[N<<1],nxt[N<<1],du[N],ncnt;
	void AddEdge(ci u,ci v){
		int p=++ncnt;
		to[p]=v,nxt[p]=head[u],head[u]=p;
		du[u]++;
	}
	inline int operator [](ci u){return head[u];}
	void Init(ci siz){for(int i=1;i<=siz;i++) head[i]=du[i]=0;ncnt=0;}
}Gr,De;

int cas,n,rt,len,mxdep;
int dep[N],anc[N];
bool ban[N];

inline int Read(){
	register int r=0,c=getchar();
	while(c<'0' || '9'<c) c=getchar();
	while('0'<=c && c<='9') r=(r<<1)+(r<<3)+(c^'0'),c=getchar();
	return r;
}
void DFS(ci u,ci fa){
	anc[u]=fa,dep[u]=dep[fa]+1;
	De.AddEdge(dep[u],u);
	mxdep=max(mxdep,dep[u]);
	for(int it=Gr[u];it;it=Gr.nxt[it]){
		int v=Gr.to[it];
		if(v==fa) continue;
		DFS(v,u);
	}
}
void Check(){
	int c=getchar();
	while(c!='C' && c!='I') c=getchar();
	if(c=='I') exit(0);
}
int main(){
	cas=Read();
	while(cas--){
		Gr.Init(n=Read());
		De.Init(n);
		for(int i=1;i<n;i++){
			ban[i]=false;
			int u=Read(),v=Read();
			Gr.AddEdge(u,v),Gr.AddEdge(v,u);
		}
		ban[n]=false;
		printf("? %d",n);for(int i=1;i<=n;i++) printf(" %d",i);
		printf("\n"),fflush(stdout);
		rt=Read(),len=Read();
		mxdep=0,DFS(rt,0);
		int l=len/2+1,r=min(len,mxdep)+1,deper;
		for(int i=1;i<=9;i++){
			int m=(l+r)>>1;
			if(!De.du[m]) m--;
			printf("? %d",De.du[m]);
			int cnt=0;
			for(int it=De[m];it;it=De.nxt[it])
				printf(" %d",De.to[it]),cnt++;
			assert(cnt==De.du[m]);
			printf("\n"),fflush(stdout);
			int U=Read(),D=Read();
			if(D!=len) r=m-1;
			else l=m+1,deper=U;
		}
		if(dep[deper]==len+1){
			printf("! %d %d\n",deper,rt),fflush(stdout);
			Check();
			continue;
		}
		int tmp=deper,qd=len-dep[deper]+2;
		while(tmp) ban[tmp]=true,tmp=anc[tmp];
		printf("? %d",De.du[qd]-1);
		int cnt=0;
		for(int it=De[qd];it;it=De.nxt[it])
			if(!ban[De.to[it]])
				printf(" %d",De.to[it]),cnt++;
		assert(De.du[qd]-1==cnt);
		printf("\n"),fflush(stdout);
		int ano=Read();Read();
		printf("! %d %d\n",ano,deper),fflush(stdout);
		Check();
	}
	return 0;
}


/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define ci const int &
const int N=1005;

struct GRAPH{
	int head[N],to[N<<1],nxt[N<<1],du[N],ncnt;
	void AddEdge(ci u,ci v){
		int p=++ncnt;
		to[p]=v,nxt[p]=head[u],head[u]=p;
		du[u]++;
	}
	inline int operator [](ci u){return head[u];}
	void Init(ci siz){for(int i=1;i<=siz;i++) head[i]=du[i]=0;ncnt=0;}
}Gr,De;

int cas,n,rt,len,mxdep;
int dep[N],anc[N];
bool ban[N];

inline int Read(){
	register int r=0,c=getchar();
	while(c<'0' || '9'<c) c=getchar();
	while('0'<=c && c<='9') r=(r<<1)+(r<<3)+(c^'0'),c=getchar();
	return r;
}
void DFS(ci u,ci fa){
	anc[u]=fa,dep[u]=dep[fa]+1;
	De.AddEdge(dep[u],u);
	mxdep=max(mxdep,dep[u]);
	for(int it=Gr[u];it;it=Gr.nxt[it]){
		int v=Gr.to[it];
		if(v==fa) continue;
		DFS(v,u);
	}
}
void Check(){
	int c=getchar();
	while(c!='C' && c!='I') c=getchar();
	if(c=='I') exit(1);
}
int main(){
	cas=Read();
	while(cas--){
		Gr.Init(n=Read());
		De.Init(n);
		for(int i=1;i<n;i++){
			ban[i]=false;
			int u=Read(),v=Read();
			Gr.AddEdge(u,v),Gr.AddEdge(v,u);
		}
		ban[n]=false;
		printf("? %d",n);for(int i=1;i<=n;i++) printf(" %d",i);
		printf("\n"),fflush(stdout);
		rt=Read(),len=Read();
		mxdep=0,DFS(rt,0);
		int l=len/2+1,r=min(len,mxdep)+1,deper;
		for(int i=1;i<=9;i++){
			int m=(l+r)>>1;
			if(!De.du[m]) m--;
			printf("? %d",De.du[m]);
			for(int it=De[m];it;it=De.nxt[it])
				printf(" %d",De.to[it]);
			printf("\n"),fflush(stdout);
			int U=Read(),D=Read();
			if(D!=len) r=m-1;
			else l=m+1,deper=U;
		}
		if(dep[deper]==len+1){
			printf("! %d %d\n",deper,rt);
			Check();
			continue;
		}
		int tmp=deper,qd=len-dep[deper]+2;
		while(tmp) ban[tmp]=true,tmp=anc[tmp];
		printf("? %d",De.du[qd]);
		for(int it=De[qd];it;it=De.nxt[it])
			if(!ban[De.to[it]])
				printf(" %d",De.to[it]);
		printf("\n"),fflush(stdout);
		int ano=Read();Read();
		printf("! %d %d\n",ano,deper);
		Check();
	}
	return 0;
}


/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define ci const int &
const int N=1005;

struct GRAPH{
	int head[N],to[N<<1],nxt[N<<1],du[N],ncnt;
	void AddEdge(ci u,ci v){
		int p=++ncnt;
		to[p]=v,nxt[p]=head[u],head[u]=p;
		du[u]++;
	}
	inline int operator [](ci u){return head[u];}
	void Init(ci siz){for(int i=1;i<=siz;i++) head[i]=du[i]=0;ncnt=0;}
}Gr,De;

int cas,n,rt,len,mxdep;
int dep[N],anc[N];
bool ban[N];

inline int Read(){
	register int r=0,c=getchar();
	while(c<'0' || '9'<c) c=getchar();
	while('0'<=c && c<='9') r=(r<<1)+(r<<3)+(c^'0'),c=getchar();
	return r;
}
void DFS(ci u,ci fa){
	anc[u]=fa,dep[u]=dep[fa]+1;
	De.AddEdge(dep[u],u);
	mxdep=max(mxdep,dep[u]);
	for(int it=Gr[u];it;it=Gr.nxt[it]){
		int v=Gr.to[it];
		if(v==fa) continue;
		DFS(v,u);
	}
}
void Check(){
	int c=getchar();
	while(c!='C' && c!='I') c=getchar();
	if(c=='I') exit(1);
}
int main(){
	cas=Read();
	while(cas--){
		Gr.Init(n=Read());
		De.Init(n);
		for(int i=1;i<n;i++){
			ban[i]=false;
			int u=Read(),v=Read();
			Gr.AddEdge(u,v),Gr.AddEdge(v,u);
		}
		ban[n]=false;
		printf("? %d",n);for(int i=1;i<=n;i++) printf(" %d",i);
		printf("\n"),fflush(stdout);
		rt=Read(),len=Read();
		mxdep=0,DFS(rt,0);
		int l=len/2+1,r=min(len,mxdep)+1,deper;
		for(int i=1;i<=9;i++){
			int m=(l+r)>>1;
			if(!De.du[m]) m--;
			printf("? %d",De.du[m]);
			for(int it=De[m];it;it=De.nxt[it])
				printf(" %d",De.to[it]);
			printf("\n"),fflush(stdout);
			int U=Read(),D=Read();
			if(D!=len) r=m-1;
			else l=m+1,deper=U;
		}
		if(dep[deper]==len+1){
			printf("!1 %d %d\n",deper,rt);
			Check();
			continue;
		}
		int tmp=deper,qd=len-dep[deper]+2;
		while(tmp) ban[tmp]=true,tmp=anc[tmp];
		printf("? %d",De.du[qd]);
		for(int it=De[qd];it;it=De.nxt[it])
			if(!ban[De.to[it]])
				printf(" %d",De.to[it]);
		printf("\n"),fflush(stdout);
		int ano=Read();Read();
		printf("! %d %d\n",ano,deper);
		Check();
	}
	return 0;
}


/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define ci const int &
const int N=1005;

struct GRAPH{
	int head[N],to[N<<1],nxt[N<<1],du[N],ncnt;
	void AddEdge(ci u,ci v){
		int p=++ncnt;
		to[p]=v,nxt[p]=head[u],head[u]=p;
		du[u]++;
	}
	inline int operator [](ci u){return head[u];}
	void Init(ci siz){for(int i=1;i<=siz;i++) head[i]=du[i]=0;ncnt=0;}
}Gr,De;

int cas,n,rt,len,mxdep;
int dep[N],anc[N];
bool ban[N];

inline int Read(){
	register int r=0,c=getchar();
	while(c<'0' || '9'<c) c=getchar();
	while('0'<=c && c<='9') r=(r<<1)+(r<<3)+(c^'0'),c=getchar();
	return r;
}
void DFS(ci u,ci fa){
	anc[u]=fa,dep[u]=dep[fa]+1;
	De.AddEdge(dep[u],u);
	mxdep=max(mxdep,dep[u]);
	for(int it=Gr[u];it;it=Gr.nxt[it]){
		int v=Gr.to[it];
		if(v==fa) continue;
		DFS(v,u);
	}
}
void Check(){
	int c=getchar();
	while(c!='C' && c!='I') c=getchar();
	if(c=='I') exit(1);
}
int main(){
	cas=Read();
	while(cas--){
		Gr.Init(n=Read());
		De.Init(n);
		for(int i=1;i<n;i++){
			ban[i]=false;
			int u=Read(),v=Read();
			Gr.AddEdge(u,v),Gr.AddEdge(v,u);
		}
		ban[n]=false;
		printf("? %d",n);for(int i=1;i<=n;i++) printf(" %d",i);
		printf("\n"),fflush(stdout);
		rt=Read(),len=Read();
		mxdep=0,DFS(rt,0);
		int l=len/2+1,r=min(len,mxdep)+1,deper;
		for(int i=1;i<=9;i++){
			int m=(l+r)>>1;
			if(!De.du[m]) m--;
			printf("? %d",De.du[m]);
			for(int it=De[m];it;it=De.nxt[it])
				printf(" %d",De.to[it]);
			printf("\n"),fflush(stdout);
			int U=Read(),D=Read();
			if(D!=len) r=m-1;
			else l=m+1,deper=U;
		}
		if(dep[deper]==len+1){
			printf("! %d %d\n",deper,rt),fflush(stdout);
			Check();
			continue;
		}
		int tmp=deper,qd=len-dep[deper]+2;
		while(tmp) ban[tmp]=true,tmp=anc[tmp];
		printf("? %d",De.du[qd]);
		for(int it=De[qd];it;it=De.nxt[it])
			if(!ban[De.to[it]])
				printf(" %d",De.to[it]);
		printf("\n"),fflush(stdout);
		int ano=Read();Read();
		printf("! %d %d\n",ano,deper),fflush(stdout);
		Check();
	}
	return 0;
}


// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd()
{
	static uint seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args)
{
	read(t);read(args...);
}
Finline int read_str(char *s)
{
	char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=1005;
struct edge{
	int v,nxt;
}c[N<<1];
int front[N],edge_cnt;
Finline void addedge(int u,int v)
{
	c[++edge_cnt]=(edge){v,front[u]};
	front[u]=edge_cnt;
}
int dep[N];
std::vector<int> v;
void dfs(int x,int fa)
{
	dep[x]=dep[fa]+1;
	for(int i=front[x];i;i=c[i].nxt)
	{
		int v=c[i].v;
		if(v==fa) continue;
		dfs(v,x);
	}
}
int goal;
std::vector<int> cur,res;
void getpath(int x,int fa)
{
	cur.pb(x);
	if(x==goal)
	{
		res=cur;
		return;
	}
	for(int i=front[x];i;i=c[i].nxt)
	{
		int v=c[i].v;
		if(v==fa) continue;
		getpath(v,x);
	}
	cur.pop_back();
}
bool mark[N];
char s[20];
void MAIN()
{
	edge_cnt=0;
	memset(front,0,sizeof(front));
	int n;
	read(n);
	int x,y;
	for(int i=1;i<n;++i)
	{
		read(x,y);
		addedge(x,y),addedge(y,x);
	}
	printf("? %d ",n);
	for(int i=1;i<=n;++i) printf("%d ",i);
	printf("\n");
	fflush(stdout);
	read(x,y);
	int l=0,r=y;
	int A=0;
	dfs(x,0);
	while(l<r)
	{
		int mid=(l+r+1)>>1;
		v.clear();
		for(int i=1;i<=n;++i) if(dep[i]>=mid) v.pb(i);
		if(v.empty())
		{
			r=mid-1;
			continue;
		}
		printf("? %d ",SZ(v));
		for(auto it:v) printf("%d ",it);
		printf("\n");
		fflush(stdout);
		int a,b;
		read(a,b);
		if(b==y) l=mid,A=a;
		else r=mid-1;
	}
	cur.clear(),res.clear();
	goal=A;
	getpath(x,0);
	memset(mark,0,sizeof(mark));
	for(auto it:res) mark[it]=true;
	mark[x]=0;
	v.clear();
	for(int i=1;i<=n;++i) if(dep[i]==y-dep[A]&&!mark[i]) v.pb(i);
	printf("? %d ",SZ(v));
	for(auto it:v) printf("%d ",it);
	printf("\n");
	fflush(stdout);
	read(y);
	printf("! %d %d\n",A,y);
	fflush(stdout);
	read_str(s);
}
int main()
{
	dep[0]=-1;
	int _;
	read(_);
	while(_--) MAIN();
	return 0;
}


	// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd()
{
	static uint seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args)
{
	read(t);read(args...);
}
Finline int read_str(char *s)
{
	char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=1005;
struct edge{
	int v,nxt;
}c[N<<1];
int front[N],edge_cnt;
Finline void addedge(int u,int v)
{
	c[++edge_cnt]=(edge){v,front[u]};
	front[u]=edge_cnt;
}
int dep[N];
std::vector<int> v;
void dfs(int x,int fa)
{
	dep[x]=dep[fa]+1;
	for(int i=front[x];i;i=c[i].nxt)
	{
		int v=c[i].v;
		if(v==fa) continue;
		dfs(v,x);
	}
}
int goal;
std::vector<int> cur,res;
void getpath(int x,int fa)
{
	cur.pb(x);
	if(x==goal)
	{
		res=cur;
		return;
	}
	for(int i=front[x];i;i=c[i].nxt)
	{
		int v=c[i].v;
		if(v==fa) continue;
		getpath(v,x);
	}
	cur.pop_back();
}
bool mark[N];
char s[20];
void MAIN()
{
	edge_cnt=0;
	memset(front,0,sizeof(front));
	int n;
	read(n);
	int x,y;
	for(int i=1;i<n;++i)
	{
		read(x,y);
		addedge(x,y),addedge(y,x);
	}
	printf("? %d ",n);
	for(int i=1;i<=n;++i) printf("%d ",i);
	printf("\n");
	fflush(stdout);
	read(x,y);
	int l=(y>>1)-1,r=y;
	int A=0;
	dfs(x,0);
	while(l<r)
	{
		int mid=(l+r+1)>>1;
		v.clear();
		for(int i=1;i<=n;++i) if(dep[i]>=mid) v.pb(i);
		if(v.empty())
		{
			r=mid-1;
			continue;
		}
		printf("? %d ",SZ(v));
		for(auto it:v) printf("%d ",it);
		printf("\n");
		fflush(stdout);
		int a,b;
		read(a,b);
		if(b==y) l=mid,A=a;
		else r=mid-1;
	}
	cur.clear(),res.clear();
	goal=A;
	getpath(x,0);
	memset(mark,0,sizeof(mark));
	for(auto it:res) mark[it]=true;
	mark[x]=0;
	v.clear();
	for(int i=1;i<=n;++i) if(dep[i]==y-dep[A]&&!mark[i]) v.pb(i);
	if(SZ(v)!=1)
	{
		printf("? %d ",SZ(v));
		for(auto it:v) printf("%d ",it);
		printf("\n");
		fflush(stdout);
		read(y);
	}
	else y=v.back();
	printf("! %d %d\n",A,y);
	fflush(stdout);
	read_str(s);
}
int main()
{
	dep[0]=-1;
	int _;
	read(_);
	while(_--) MAIN();
	return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

vi edges[1001];

pi q(vi &a){
    cout << "? " << a.size();
    for(auto &e:a) cout << " " << e;
    cout << endl;
    int x,d; cin >> x >> d;
    return {x,d};
}

vi parent;
vi height;

int lheight = 0;

void dfs(int child, int par,int ht){
    parent[child] = par;
    height[child] = ht;
    lheight = max(lheight,ht);
    for(auto &a:edges[child]){
        if(a == par) continue;
        dfs(a,child,ht+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        parent.resize(n+1);
        height.resize(n+1);
        FOR(i,n+1) edges[i].clear();
        FOR(i,n-1){
            int a,b; cin >> a >> b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        vi al; F0R(i,1,n) al.push_back(i);
        pi lca = q(al);
        int dist = lca.s; int root = lca.f;
        lheight = 0;
        dfs(root,0,0);
        int l = (dist+1)/2; int r = lheight+1;
        int person = root;
        do{
            int mid = (r+l)/2;
            vi quer;
            F0R(i,1,n) if(height[i] == mid) quer.push_back(i);
            pi re = q(quer);
            if(re.s == dist){
                l = mid; person = re.f;
            }
            else r = mid;
        }while(r-l > 1);
        vector<bool> anc(n+1);
        int cur = person;
        while(cur != root){
            anc[cur] = 1;
            cur = parent[cur];
        }
        vi fin;
        F0R(i,1,n) if(height[i] == dist-l && !(anc[i])) fin.push_back(i);
        pi finp = q(fin);
        cout << "! " << person << " " << finp.f << endl;
        string congrat; cin >> congrat;
    }
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

vi edges[1001];

pi q(vi &a){
    cout << "? " << a.size();
    for(auto &e:a) cout << " " << e;
    cout << endl;
    int x,d; cin >> x >> d;
    return {x,d};
}

vi parent;
vi height;

int lheight = 0;

void dfs(int child, int par,int ht){
    parent[child] = par;
    height[child] = ht;
    lheight = max(lheight,ht);
    for(auto &a:edges[child]){
        if(a == par) continue;
        dfs(a,child,ht+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        parent.resize(n+1);
        height.resize(n+1);
        FOR(i,n+1) edges[i].clear();
        FOR(i,n-1){
            int a,b; cin >> a >> b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        vi al; F0R(i,1,n) al.push_back(i);
        pi lca = q(al);
        int dist = lca.s; int root = lca.f;
        lheight = 0;
        dfs(root,0,0);
        int l = (dist+1)/2; int r = lheight;
        int person = root;
        while(r >= l){
            int mid = (r+l)/2;
            vi quer;
            F0R(i,1,n) if(height[i] == mid) quer.push_back(i);
            pi re = q(quer);
            if(re.s == dist){
                l = mid+1; person = re.f;
            }
            else r = mid-1;
        }
        l = height[person];
        vector<bool> anc(n+1);
        int cur = person;
        while(cur != root){
            anc[cur] = 1;
            cur = parent[cur];
        }
        vi fin;
        F0R(i,1,n) if(height[i] == dist-l && !(anc[i])) fin.push_back(i);
        pi finp = q(fin);
        cout << "! " << person << " " << finp.f << endl;
        string congrat; cin >> congrat;
    }
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

vi edges[1001];

pi q(vi &a){
    cout << "? " << a.size();
    for(auto &e:a) cout << " " << e;
    cout << endl;
    int x,d; cin >> x >> d;
    if(x == -1) cout << 5/0 << endl;
    return {x,d};
}

vi height;
vi parent;

int lheight = 0;

void dfs(int child, int par,int ht){
    parent[child] = par;
    height[child] = ht;
    lheight = max(lheight,ht);
    for(auto &a:edges[child]){
        if(a == par) continue;
        dfs(a,child,ht+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        height.resize(n+1);
        parent.resize(n+1);
        FOR(i,n+1) edges[i].clear();
        FOR(i,n-1){
            int a,b; cin >> a >> b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        vi al; F0R(i,1,n) al.push_back(i);
        pi lca = q(al);
        int dist = lca.s; int root = lca.f;
        lheight = 0;
        dfs(root,0,0);
//        F0R(i,1,10) cerr << height[i] << " ";
//        cerr << endl;
        int l = (dist+1)/2, r = min(dist,lheight)+1;
        int person = root;
        do{
            int mid = (l+r)/2;
            vi quer;
            F0R(i,1,n){
                if(height[i] == mid) quer.push_back(i);
            }
            pi re = q(quer);
//            cerr << mid << endl;
            if(re.s == dist){
                l = mid; person = re.f;
            } else r = mid;
        }while(l + 1 < r);
        vi fin;
        vector<bool> anc(n+1);
        int cur = person;
        while(cur != 0){
            anc[cur] = 1;
            cur = parent[cur];
        }
        F0R(i,1,n) if(height[i] == dist-l && !(anc[i])) fin.push_back(i);
        pi finp = q(fin);
        cout << "! " << person << " " << finp.f << endl;
        string conf; cin >> conf;
        if(conf == "Incorrect") cout << 5/0 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

vi edges[1001];

pi q(vi &a){
    cout << "? " << a.size();
    for(auto &e:a) cout << " " << e;
    cout << endl;
    int x,d; cin >> x >> d;
    if(x == -1) cout << 5/0 << endl;
    return {x,d};
}

vi height;

int lheight = 0;

void dfs(int child, int par,int ht){
    height[child] = ht;
    lheight = max(lheight,ht);
    for(auto &a:edges[child]){
        if(a == par) continue;
        dfs(a,child,ht+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        height.resize(n+1);
        FOR(i,n+1) edges[i].clear();
        FOR(i,n-1){
            int a,b; cin >> a >> b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        vi al; F0R(i,1,n) al.push_back(i);
        pi lca = q(al);
        int dist = lca.s; int root = lca.f;
        lheight = 0;
        dfs(root,0,0);
//        F0R(i,1,10) cerr << height[i] << " ";
//        cerr << endl;
        int l = 0, r = lheight+1;
        int person = root;
        while(r-l > 1){
            int mid = (l+r)/2;
            vi quer;
            F0R(i,1,n){
                if(height[i] == mid) quer.push_back(i);
            }
            pi re = q(quer);
//            cerr << mid << endl;
            if(re.s == dist){
                l = mid; person = re.f;
            } else r = mid;
        }
        vi fin;
        F0R(i,1,n) if(height[i] == dist-l && (i != person)) fin.push_back(i);
        pi finp = q(fin);
        cout << "! " << person << " " << finp.f << endl;
        string conf; cin >> conf;
        if(conf == "Incorrect") cout << 5/0 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

vi edges[1001];

pi q(vi &a){
    cout << "? " << a.size();
    for(auto &e:a) cout << " " << e;
    cout << endl;
    int x,d; cin >> x >> d;
    return {x,d};
}

vi parent;
vi height;

int lheight = 0;

void dfs(int child, int par,int ht){
    parent[child] = par;
    height[child] = ht;
    lheight = max(lheight,ht);
    for(auto &a:edges[child]){
        if(a == par) continue;
        dfs(a,child,ht+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        parent.resize(n+1);
        height.resize(n+1);
        FOR(i,n+1) edges[i].clear();
        FOR(i,n-1){
            int a,b; cin >> a >> b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        vi al; F0R(i,1,n) al.push_back(i);
        pi lca = q(al);
        int dist = lca.s; int root = lca.f;
        lheight = 0;
        dfs(root,0,0);
        int l = (dist+1)/2; int r = min(lheight,dist)+1;
        int person = root;
        do{
            int mid = (r+l)/2;
            vi quer;
            F0R(i,1,n) if(height[i] == mid) quer.push_back(i);
            pi re = q(quer);
            if(re.s == dist){
                l = mid; person = re.f;
            }
            else r = mid;
        }while(r-l > 1);
        vector<bool> anc(n+1);
        int cur = person;
        while(cur != root){
            anc[cur] = 1;
            cur = parent[cur];
        }
        vi fin;
        F0R(i,1,n) if(height[i] == dist-l && !(anc[i])) fin.push_back(i);
        pi finp = q(fin);
        cout << "! " << person << " " << finp.f << endl;
        string congrat; cin >> congrat;
    }
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

vi edges[1001];

pi q(vi &a){
    cout << "? " << a.size();
    for(auto &e:a) cout << " " << e;
    cout << endl;
    int x,d; cin >> x >> d;
    if(x == -1) cout << 5/0 << endl;
    return {x,d};
}

vi height;

int lheight = 0;

void dfs(int child, int par,int ht){
    height[child] = ht;
    lheight = max(lheight,ht);
    for(auto &a:edges[child]){
        if(a == par) continue;
        dfs(a,child,ht+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        height.resize(n+1);
        FOR(i,n+1) edges[i].clear();
        FOR(i,n-1){
            int a,b; cin >> a >> b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        vi al; F0R(i,1,n) al.push_back(i);
        pi lca = q(al);
        int dist = lca.s; int root = lca.f;
        lheight = 0;
        dfs(root,0,0);
//        F0R(i,1,10) cerr << height[i] << " ";
//        cerr << endl;
        int l = 0, r = lheight+1;
        int person = root;
        while(r-l > 1){
            int mid = (l+r)/2;
            vi quer;
            F0R(i,1,n){
                if(height[i] == mid) quer.push_back(i);
            }
            pi re = q(quer);
//            cerr << mid << endl;
            if(re.s == dist){
                l = mid; person = re.f;
            } else r = mid;
        }
        vi fin;
        F0R(i,1,n) if(height[i] == dist-l && (i != person)) fin.push_back(i);
        pi finp = q(fin);
        if((person == 2 && finp.f == 8) || (person == 8 && finp.f == 2)) cout << 5/0 << endl;
        cout << "! " << person << " " << finp.f << endl;
        string conf; cin >> conf;
        if(conf == "Incorrect") cout << 5/0 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

vi edges[1001];

pi q(vi &a){
    cout << "? " << a.size();
    for(auto &e:a) cout << " " << e;
    cout << endl;
    int x,d; cin >> x >> d;
    if(x == -1) cout << 5/0 << endl;
    return {x,d};
}

vi height;
vi parent;

int lheight = 0;

void dfs(int child, int par,int ht){
    parent[child] = par;
    height[child] = ht;
    lheight = max(lheight,ht);
    for(auto &a:edges[child]){
        if(a == par) continue;
        dfs(a,child,ht+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        height.resize(n+1);
        FOR(i,n+1) edges[i].clear();
        FOR(i,n-1){
            int a,b; cin >> a >> b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        vi al; F0R(i,1,n) al.push_back(i);
        pi lca = q(al);
        int dist = lca.s; int root = lca.f;
        lheight = 0;
        dfs(root,0,0);
//        F0R(i,1,10) cerr << height[i] << " ";
//        cerr << endl;
        int l = (dist+1)/2, r = min(dist,lheight);
        int person = root;
        while(l <= r){
            int mid = (l+r)/2;
            vi quer;
            F0R(i,1,n){
                if(height[i] == mid) quer.push_back(i);
            }
            pi re = q(quer);
//            cerr << mid << endl;
            if(re.s == dist){
                l = mid+1; person = re.f;
            } else r = mid-1;
        }
        l--;
        vi fin;
        vector<bool> anc(n+1);
        int cur = person;
        while(cur != 0){
            anc[cur] = 1;
            cur = parent[cur];
        }
        F0R(i,1,n) if(height[i] == dist-l && !(anc[i])) fin.push_back(i);
        pi finp = q(fin);
        cout << "! " << person << " " << finp.f << endl;
        string conf; cin >> conf;
        if(conf == "Incorrect") cout << 5/0 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

vi edges[1001];

pi q(vi &a){
    cout << "? " << a.size();
    for(auto &e:a) cout << " " << e;
    cout << endl;
    int x,d; cin >> x >> d;
    if(x == -1) exit(0);
    return {x,d};
}

vi height;

int lheight = 0;

void dfs(int child, int par,int ht){
    height[child] = ht;
    lheight = max(lheight,ht);
    for(auto &a:edges[child]){
        if(a == par) continue;
        dfs(a,child,ht+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        height.resize(n+1);
        FOR(i,n+1) edges[i].clear();
        FOR(i,n-1){
            int a,b; cin >> a >> b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        vi al; F0R(i,1,n) al.push_back(i);
        pi lca = q(al);
        int dist = lca.s; int root = lca.f;
        lheight = 0;
        dfs(root,0,0);
//        F0R(i,1,10) cerr << height[i] << " ";
//        cerr << endl;
        int l = 0; int r = lheight+1;
        int person = root;
        while(r-l > 1){
            int mid = (r+l)/2;
            vi quer;
            F0R(i,1,n) if(height[i] == mid) quer.push_back(i);
            pi re = q(quer);
            if(re.s == dist){
                l = mid; person = re.f;
            }
            else r = mid;
        }
        vi fin;
        F0R(i,1,n) if(height[i] == dist-l && (i != person)) fin.push_back(i);
        pi finp = q(fin);
        cout << "! " << person << " " << finp.f << endl;
        string congrat; cin >> congrat;
    }
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

vi edges[1001];

pi q(vi &a){
    cout << "? " << a.size();
    for(auto &e:a) cout << " " << e;
    cout << endl;
    int x,d; cin >> x >> d;
    if(x == -1) cout << 5/0 << endl;
    return {x,d};
}

vi height;

int lheight = 0;

void dfs(int child, int par,int ht){
    height[child] = ht;
    lheight = max(lheight,ht);
    for(auto &a:edges[child]){
        if(a == par) continue;
        dfs(a,child,ht+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        height.resize(n+1);
        FOR(i,n+1) edges[i].clear();
        FOR(i,n-1){
            int a,b; cin >> a >> b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        vi al; F0R(i,1,n) al.push_back(i);
        pi lca = q(al);
        int dist = lca.s; int root = lca.f;
        lheight = 0;
        dfs(root,0,0);
//        F0R(i,1,10) cerr << height[i] << " ";
//        cerr << endl;
        int l = 0, r = lheight+1;
        int person = root;
        while(l <= r){
            int mid = (l+r)/2;
            vi quer;
            F0R(i,1,n){
                if(height[i] == mid) quer.push_back(i);
            }
            pi re = q(quer);
//            cerr << mid << endl;
            if(re.s == dist){
                l = mid; person = re.f;
            } else r = mid-1;
        }
        vi fin;
        F0R(i,1,n) if(height[i] == dist-l && (i != person)) fin.push_back(i);
        pi finp = q(fin);
        cout << "! " << person << " " << finp.f << endl;
        string conf; cin >> conf;
        if(conf == "Incorrect") cout << 5/0 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

vi edges[1001];

pi q(vi &a){
    cout << "? " << a.size();
    for(auto &e:a) cout << " " << e;
    cout << endl;
    int x,d; cin >> x >> d;
    if(x == -1) exit(0);
    return {x,d};
}

vi height;

int lheight = 0;

void dfs(int child, int par,int ht){
    height[child] = ht;
    lheight = max(lheight,ht);
    for(auto &a:edges[child]){
        if(a == par) continue;
        dfs(a,child,ht+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        height.resize(n+1);
        FOR(i,n+1) edges[i].clear();
        FOR(i,n-1){
            int a,b; cin >> a >> b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        vi al; F0R(i,1,n) al.push_back(i);
        pi lca = q(al);
        int dist = lca.s; int root = lca.f;
        lheight = 0;
        dfs(root,0,0);
//        F0R(i,1,10) cerr << height[i] << " ";
//        cerr << endl;
        int l = 0; int r = lheight+1;
        int person = root;
        while(r-l > 1){
            int mid = (l+r)/2;
            vi quer;
            F0R(i,1,n) if(height[i] == mid) quer.push_back(i);
            pi re = q(quer);
//            cerr << mid << endl;
            if(re.s == dist){
                l = mid; person = re.f;
            }
            else r = mid;
        }
        vi fin;
        F0R(i,1,n) if(height[i] == dist-l && (i != person)) fin.push_back(i);
        pi finp = q(fin);
        cout << "! " << person << " " << finp.f << endl;
        string conf; cin >> conf;
        if(conf == "Incorrect") return 0;
    }
    return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;

long long n,a,sum,l,m,x,y;
char c;
bool g;
vector<pair<long long,long long> >v[3],w[3];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>c>>x>>y;
		if(c=='B')
		{
			v[0].push_back(make_pair(x,y));
		}
		else
		{
			v[1].push_back(make_pair(x,y));
		}
	}
	sort(v[0].begin(),v[0].end(),greater<pair<long long,long long> >());
	sort(v[1].begin(),v[1].end());
	for(int j=1;j>=0;j--)
	{
		l=m;
		sum=0;
		for(int i=0;i<v[j].size();i++)
		{
			g=false;
			sum+=v[j][i].se;
			if(v[j][i].fi==v[j][i+1].fi)
			{
				g=true;
				continue;
			}
			else if(v[j][i].fi!=v[j][i+1].fi&&l)
			{
				if(j==0)
				{
					w[0].push_back(make_pair(v[j][i].fi,sum));
				}
				else
				{
					w[1].push_back(make_pair(v[j][i].fi,sum));
				}
				sum=0;
				l--;
			}
			if(g&&l)
			{
				if(j==0)
				{
					w[0].push_back(make_pair(v[j][i].fi,sum));
				}
				else
				{
					w[1].push_back(make_pair(v[j][i].fi,sum));
				}
			}
		}
	}
	sort(w[1].begin(),w[1].end(),greater<pair<long long,long long> >());
	for(int i=1;i>=0;i--)
	{
		for(int j=0;j<w[i].size();j++)
		{
			if(i==1)
			{
				cout<<"S "<<w[i][j].fi<<" "<<w[i][j].se<<endl;
			}
			else
			{
				cout<<"B "<<w[i][j].fi<<" "<<w[i][j].se<<endl;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;

long long n,a,sum,l,m,x,y;
char c;
vector<pair<long long,long long> >v[3],w[3];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>c>>x>>y;
		if(c=='B')
		{
			v[0].push_back(make_pair(x,y));
		}
		else
		{
			v[1].push_back(make_pair(x,y));
		}
	}
	sort(v[0].begin(),v[0].end(),greater<pair<long long,long long> >());
	sort(v[1].begin(),v[1].end());
	v[0].push_back(make_pair(-69,-69));
	v[1].push_back(make_pair(-69,-69));
	for(int j=1;j>=0;j--)
	{
		l=m;
		sum=0;
		for(int i=0;i<v[j].size()-1;i++)
		{
			sum+=v[j][i].se;
			if(v[j][i].fi==v[j][i+1].fi)
			{
				continue;
			}
			else if(v[j][i].fi!=v[j][i+1].fi&&l)
			{
				if(j==0)
				{
					w[0].push_back(make_pair(v[j][i].fi,sum));
				}
				else
				{
					w[1].push_back(make_pair(v[j][i].fi,sum));
				}
				sum=0;
				l--;
			}
		}
	}
	sort(w[1].begin(),w[1].end(),greater<pair<long long,long long> >());
	for(int i=1;i>=0;i--)
	{
		for(int j=0;j<w[i].size();j++)
		{
			if(i==1)
			{
				cout<<"S "<<w[i][j].fi<<" "<<w[i][j].se<<endl;
			}
			else
			{
				cout<<"B "<<w[i][j].fi<<" "<<w[i][j].se<<endl;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;

long long n,a,sum,l,m,x,y;
char c;
bool g;
vector<pair<long long,long long> >v[3];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>c>>x>>y;
		if(c=='B')
		{
			v[0].push_back(make_pair(x,y));
		}
		else
		{
			v[1].push_back(make_pair(x,y));
		}
	}
	sort(v[0].begin(),v[0].end(),greater<pair<long long,long long> >());
	sort(v[1].begin(),v[1].end(),greater<pair<long long,long long> >());
	for(int j=1;j>=0;j--)
	{
		l=m;
		sum=0;
		for(int i=0;i<v[j].size();i++)
		{
			g=false;
			sum+=v[j][i].se;
			if(v[j][i].fi==v[j][i+1].fi)
			{
				g=true;
				continue;
			}
			else if(v[j][i].fi!=v[j][i+1].fi&&l)
			{
				if(j==0)
				{
					cout<<"B"<<" "<<v[j][i].fi<<" "<<sum<<endl;
				}
				else
				{
					cout<<"S"<<" "<<v[j][i].fi<<" "<<sum<<endl;
				}
				sum=0;
				l--;
			}
			if(g&&l)
			{
				if(j==0)
				{
					cout<<"B"<<" "<<v[j][i].fi<<" "<<sum<<endl;
				}
				else
				{
					cout<<"S"<<" "<<v[j][i].fi<<" "<<sum<<endl;
				}
			}
		}
	}

}


#include <iostream>
#include <vector>

using namespace std;

vector <int> buy;
vector <int> sell;

int main(){
	buy.resize(100001, 0);
	sell.resize(100001, 0);
	int n, s, p, q;
	char d;
	cin>>n>>s;
	for(int i = 0; i < n; i++){
		cin>>d>>p>>q;
		if(d == 'B'){
			buy[p] += q;
		}
		else{
			sell[p] += q;
		}
	}
	int counter = 0;
	for(int i = 100001; i >= 0; i--){
		if(buy[i] != 0){
			cout<<"B "<<i<<" "<<buy[i]<<"\n";
			counter++;
		}
		if(counter >= s) break;
	}
	counter = 0;
	for(int i = 100001; i >= 0; i--){
		if(sell[i] != 0){
			cout<<"S "<<i<<" "<<sell[i]<<"\n";
			counter++;
		}
		if(counter >= s) break;
	}
	return 0;
}