#include <bits/stdc++.h>
using namespace std;
vector<int> v[1001];
int p[1001];
bool checc[1001];
int max1;
int query(int st, int dr) {
  int i, x;
  cout << "? " << dr - st + 1 << " ";
  for (i = st; i <= dr; i++) cout << i << " ";
  cout << '\n';
  cout.flush();
  cin >> x;
  return x;
}
int go(int st, int dr) {
  if (st == dr) return st;
  int mid = (st + dr) / 2;
  int val = query(st, mid);
  if (val == max1)
    return go(st, mid);
  else
    return go(mid + 1, dr);
}
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, n, k, x, dim, i, where, j;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (i = 1; i <= k; i++) {
      cin >> dim;
      v[i].clear();
      for (j = 1; j <= dim; j++) {
        cin >> x;
        v[i].push_back(x);
      }
    }
    cout << "? " << n << " ";
    for (i = 1; i <= n; i++) cout << i << " ";
    cout << '\n';
    cout.flush();
    cin >> max1;
    where = go(1, n);
    for (i = 1; i <= k; i++) {
      for (j = 0; j < v[i].size(); j++)
        if (v[i][j] == where) break;
      if (j == v[i].size())
        p[i] = max1;
      else {
        for (j = 1; j <= n; j++) checc[j] = 0;
        for (j = 0; j < v[i].size(); j++) checc[v[i][j]] = 1;
        cout << "? " << n - v[i].size() << " ";
        for (j = 1; j <= n; j++)
          if (!checc[j]) cout << j << " ";
        cout << '\n';
        cout.flush();
        cin >> p[i];
      }
    }
    cout << "! ";
    for (i = 1; i <= k; i++) cout << p[i] << " ";
    cout << '\n';
    cout.flush();
    cin >> s;
  }
  return 0;
}
