#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize( \
    "O3,Ofast,no-stack-protector,unroll-loops,fast-math,-ffp-contract=off")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
const long long N = 1012;
long long n, k, c[N], t;
vector<long long> ans, vec[N];
bool ch[N];
long long pr(long long a) {
  cout << "? " << a << ' ';
  for (long long i = 1; i <= a; i++) cout << i << ' ';
  cout << '\n';
  cout.flush();
  long long ret;
  cin >> ret;
  return ret;
}
void solve() {
  ans.clear();
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    cin >> c[i];
    vec[i].clear();
    for (long long j = 0; j < c[i]; j++) {
      long long a;
      cin >> a;
      vec[i].push_back(a);
    }
  }
  long long mx = pr(n);
  long long high = n;
  long long low = 0;
  while (high - low > 1) {
    long long mid = (low + high) >> 1;
    long long now = pr(mid);
    if (now == mx)
      high = mid;
    else
      low = mid;
  }
  low = high;
  for (long long i = 0; i < k; i++) {
    bool C = 0;
    for (long long j : vec[i]) {
      if (j == low) {
        C = 1;
        cout << "? " << n - c[i] << ' ';
        for (long long L = 0; L <= n; L++) ch[L] = 0;
        for (auto L : vec[i]) ch[L] = 1;
        for (long long L = 1; L <= n; L++) {
          if (!ch[L]) cout << L << ' ';
        }
        cout << '\n';
        cout.flush();
        long long K;
        cin >> K;
        ans.push_back(K);
        break;
      }
    }
    if (!C) ans.push_back(mx);
  }
  cout << "! " << ' ';
  for (auto x : ans) cout << x << ' ';
  cout << '\n';
  cout.flush();
  string S;
  cin >> S;
  return;
}
int32_t main() {
  cin >> t;
  while (t--) solve();
  return 0;
}
