#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9;
vector<int> sub[1005];
int vis[1005];
string crt;
int query(int l, int r) {
  cout << "? " << r - l + 1;
  for (int i = l; i <= r; i++) {
    cout << ' ' << i;
  }
  cout << endl;
  int ans;
  cin >> ans;
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= k; i++) {
      sub[i].clear();
      int c;
      cin >> c;
      for (int j = 1; j <= c; j++) {
        int tmp;
        cin >> tmp;
        sub[i].push_back(tmp);
      }
    }
    int mx = query(1, n);
    int l = 1, r = n;
    while (l < r) {
      int mid = (l + r) / 2;
      int tmp = query(l, mid);
      if (tmp == mx) {
        r = mid;
      } else {
        l = mid + 1;
      }
    }
    int idx = 0;
    for (int i = 1; i <= k; i++) {
      if (idx) break;
      for (int &j : sub[i]) {
        if (j == l) {
          idx = i;
          break;
        }
      }
    }
    if (idx) {
      cout << "? " << n - sub[idx].size();
      memset(vis, 0, sizeof(vis));
      for (int &i : sub[idx]) {
        vis[i] = 1;
      }
      for (int i = 1; i <= n; i++) {
        if (!vis[i]) cout << ' ' << i;
      }
      cout << endl;
      int tmp;
      cin >> tmp;
      cout << "!";
      for (int i = 1; i <= k; i++) {
        if (i == idx)
          cout << ' ' << tmp;
        else
          cout << ' ' << mx;
      }
      cout << endl;
    } else {
      cout << "!";
      for (int i = 1; i <= k; i++) {
        cout << ' ' << mx;
      }
      cout << endl;
    }
    cin >> crt;
  }
}
