#include "bits/stdc++.h"
using namespace std;
#define ll long long
//#define endl "\n"
const int N= 1e9+7;
# define M_PI 3.14159265358979323846
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
template<class T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag, tree_order_statistics_node_update> ;
template<class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
/*/---------------------------IO(Debugging)----------------------/*/
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
istream& operator >> (istream &is, T_container &v) {
for(T &x : v) is >> x; return is;
}
#ifdef __SIZEOF_INT128__
ostream& operator << (ostream &os, __int128 const& value){
static char buffer[64];
int index = 0;
__uint128_t T = (value < 0) ? (-(value + 1)) + __uint128_t(1) : value;
if (value < 0)
os << '-';
else if (T == 0)
return os << '0';
for(; T > 0; ++index){
buffer[index] = static_cast<char>('0' + (T % 10));
T /= 10;
}
while(index > 0)
os << buffer[--index];
return os;
}
istream& operator >> (istream& is, __int128& T){
static char buffer[64];
is >> buffer;
size_t len = strlen(buffer), index = 0;
T = 0; int mul = 1;
if (buffer[index] == '-')
++index, mul *= -1;
for(; index < len; ++index)
T = T * 10 + static_cast<int>(buffer[index] - '0');
T *= mul;
return is;
}
#endif
template<typename A, typename B>
ostream& operator<<(ostream &os, const pair<A, B> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream& operator << (ostream &os, const T_container &v) {
os << '{'; string sep;
for (const T &x : v) os << sep << x, sep = ", ";
return os << '}';
}
template<class P, class Q = vector<P>, class R = less<P> > ostream& operator << (ostream& out, priority_queue<P, Q, R> const& M){
static priority_queue<P, Q, R> U;
U = M;
out << "{ ";
while(!U.empty())
out << U.top() << " ", U.pop();
return (out << "}");
}
template<class P> ostream& operator << (ostream& out, queue<P> const& M){
static queue<P> U;
U = M;
out << "{"; string sep;
while(!U.empty()){
out << sep << U.front(); sep = ", "; U.pop();
}
return (out << "}");
}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
int count_open = 0, len = 1;
for(int k = 1; ; ++k){
char cur = *(names + k);
count_open += (cur == '(' ? 1 : (cur == ')' ? -1: 0));
if (cur == ',' && count_open == 0){
const char* comma = names + k;
cerr.write(names, len) << " : " << arg1 << " | ";
__f(comma + 1, args...);
return;
}
len = (cur == ' ' ? len : k + 1);
}
}
#else
#define trace(...) 1
#endif
/*/---------------------------RNG----------------------/*/
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l = LLONG_MIN,long long r = LLONG_MAX){
uniform_int_distribution<int64_t> generator(l,r);
return generator(rng);
}
struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393
static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
template<typename L, typename R>
size_t operator()(pair<L,R> const& Y) const{
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(Y.first * 31ull + Y.second + FIXED_RANDOM);
}
};
const int ca=1e5+1;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=n-1;i>=0;i--)
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define forr1(i,a,b) for(ll i=a-1;i>=b;i--)
#define No cout<<"No"<<endl;
#define NO cout<<"NO"<<endl;
#define Yes cout<<"Yes"<<endl;
#define YES cout<<"YES"<<endl;
#define out(x) cout<<x<<endl;
typedef priority_queue< pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> mpq;
// Code begins here....................................................................................................................................
int query(vi &c){
cout<<"? ";
cout<<sz(c)<<" ";
f(i,sz(c))cout<<c[i]<<" ";
cout<<endl;
int x; cin>>x;
return x;
}
void solve(){
int n,k; cin>>n>>k;
vector<vi>a(k+1);
f(i,k){
int x; cin>>x;
a[i+1].pb(x);
f(j,x){
int p; cin>>p;
a[i+1].pb(p);
}
}
vi c;
f(i,n)c.pb(i+1);
int ans=query(c);
int lo=1,hi=k;
while(lo<hi){
int mid=lo+(hi-lo)/2;
vi c;
forr(i,lo,mid+1){
forr(j,1,sz(a[i])){
c.pb(a[i][j]);
}
}
if(query(c)==ans){
hi=mid;
}else{
lo=mid+1;
}
}
vi p(k);
f(i,k)p[i]=ans;
vi l;
int d=0;
set<int>st;
f(i,n)st.ins(i+1);
forr(i,1,sz(a[lo]))st.erase(a[lo][i]);
for(auto it : st)l.pb(it);
d=query(l);
p[lo-1]=d;
cout<<"! ";
f(i,k)cout<<p[i]<<" ";
cout<<endl;
string s; cin>>s;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
// freopen("knight.in", "r", stdin);
// freopen("knight.out", "w", stdout);
int t; cin>>t;
while(t--)
solve();
}
468. Validate IP Address | 450. Delete Node in a BST |
445. Add Two Numbers II | 442. Find All Duplicates in an Array |
437. Path Sum III | 436. Find Right Interval |
435. Non-overlapping Intervals | 406. Queue Reconstruction by Height |
380. Insert Delete GetRandom O(1) | 332. Reconstruct Itinerary |
368. Largest Divisible Subset | 377. Combination Sum IV |
322. Coin Change | 307. Range Sum Query - Mutable |
287. Find the Duplicate Number | 279. Perfect Squares |
275. H-Index II | 274. H-Index |
260. Single Number III | 240. Search a 2D Matrix II |
238. Product of Array Except Self | 229. Majority Element II |
222. Count Complete Tree Nodes | 215. Kth Largest Element in an Array |
198. House Robber | 153. Find Minimum in Rotated Sorted Array |
150. Evaluate Reverse Polish Notation | 144. Binary Tree Preorder Traversal |
137. Single Number II | 130. Surrounded Regions |