#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
const long long inf = 1e18;
long long i, j, k, sch, m, n, sum, fr, to, qq, t, it, ma = -inf, mi = inf, x, y,
                                                      col, md = 998244353;
long long sans = -inf;
vector<long long> bin;
string correct;
long long binsearch(long long l, long long r) {
  if (l == r) return bin[l];
  long long b1, b2, m = (l + r) / 2;
  cout << "? " << m - l + 1 << ' ';
  for (i = l; i <= m; i++) cout << bin[i] << ' ';
  cout << endl;
  cin >> b1;
  if (b1 == ma)
    return binsearch(l, m);
  else
    return binsearch(m + 1, r);
}
int32_t main() {
  cin >> qq;
  while (qq--) {
    cin >> n >> k;
    vector<vector<long long> > a(k);
    vector<long long> b(n + 1, -1);
    bin.resize(n);
    iota(bin.begin(), bin.end(), 1);
    sum = 0;
    for (i = 0; i < k; i++) {
      cin >> x;
      sum += x;
      for (j = 0; j < x; j++) {
        cin >> y;
        a[i].push_back(y);
        b[y] = i;
      }
    }
    cout << "? " << n << ' ';
    for (i = 0; i < n; i++) {
      cout << i + 1 << ' ';
    }
    cout << endl;
    cin >> ma;
    it = binsearch(0, n - 1);
    long long peremennaya;
    if (b[it] == -1)
      peremennaya = n - 1;
    else
      peremennaya = n - a[b[it]].size();
    cout << "? " << peremennaya << ' ';
    for (i = 1; i <= n; i++) {
      if (b[it] == -1) {
        if (it != i) cout << i << ' ';
      } else {
        if (b[i] != b[it]) cout << i << ' ';
      }
    }
    cout << endl;
    cin >> sans;
    cout << "! ";
    for (i = 0; i < k; i++) {
      if (b[it] == i)
        cout << sans << ' ';
      else
        cout << ma << ' ';
    }
    cout << endl;
    cin >> correct;
    continue;
    if (correct != "Correct") {
      return 0;
      cout << "DANEBOMBITUMENYA" << endl;
      return 0;
    } else
      continue;
  }
  return 0;
}
