#include <bits/stdc++.h>
using namespace std;
int t, n, k, x, ans[1001], mx;
vector<int> s[1001];
string state;
int getMx(int l, int r) {
  int mid = l + r >> 1;
  if (l == r) return l;
  int lval;
  cout << '?' << " " << mid - l + 1;
  for (int i = l; i <= mid; i++) cout << " " << i;
  cout << endl;
  cout.flush();
  cin >> lval;
  return lval == mx ? getMx(l, mid) : getMx(mid + 1, r);
}
int getAns(int i) {
  bool vis[1001] = {0};
  for (int j = 0; j < s[i].size(); j++) vis[s[i][j]] = 1;
  cout << '?' << " " << n - s[i].size();
  for (int i = 1; i <= n; i++)
    if (!vis[i]) cout << " " << i;
  cout << endl;
  cout.flush();
  int ans;
  cin >> ans;
  return ans;
}
signed main() {
  cin >> t;
  while (t--) {
    cin >> n >> k;
    mx = 0;
    for (int i = 1; i <= k; i++) {
      int sz;
      cin >> sz;
      for (int j = 0; j < sz; j++) {
        cin >> x;
        s[i].push_back(x);
      }
    }
    cout << '?' << " " << n;
    for (int i = 1; i <= n; i++) cout << " " << i;
    cout << endl;
    cout.flush();
    cin >> mx;
    int id = getMx(1, n);
    for (int i = 1; i <= k; i++) {
      bool tag = 1;
      for (int j = 0; j < s[i].size(); j++)
        if (s[i][j] == id) {
          tag = 0;
          break;
        }
      ans[i] = tag ? mx : getAns(i);
    }
    cout << '!';
    for (int i = 1; i <= k; i++) cout << " " << ans[i];
    cout << endl;
    cout.flush();
    for (int i = 1; i <= k; i++) s[i].clear();
    cin >> state;
  }
  return 0;
}
