#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
vector<int> S[N];
int sz[N];
int ans[N];
int mx = 0, mn = 0;
bool leftMax(int endd) {
  cout << "? ";
  int s = endd;
  cout << s;
  for (int i = 1; i <= endd; i++) {
    cout << " " << i;
  }
  cout << "\n";
  cout << flush;
  int x;
  cin >> x;
  if (x == mx) {
    return true;
  } else {
    return false;
  }
}
int main() {
  int t, arrSize, total_subsets, s;
  cin >> t;
  while (t--) {
    map<int, int> mp;
    cin >> arrSize >> total_subsets;
    memset(sz, 0, sizeof(sz));
    for (int i = 1; i <= total_subsets; i++) {
      cin >> sz[i];
      for (int j = 1; j <= sz[i]; j++) {
        cin >> s;
        mp[s] = i;
        S[i].push_back(s);
      }
    }
    cout << "? " << arrSize;
    for (int i = 1; i <= arrSize; i++) {
      cout << " " << i;
    }
    cout << "\n";
    cout << flush;
    cin >> mx;
    int hi = arrSize;
    int lo = 0;
    while (hi > lo + 1) {
      int mid = (hi + lo) / 2;
      bool left = leftMax(mid);
      if (left) {
        hi = mid;
      } else {
        lo = mid;
      }
    }
    for (int i = 1; i <= total_subsets; i++) {
      int f = false;
      map<int, int> m;
      for (auto x : S[i]) {
        m[x] = 1;
        if (x == hi) f = true;
      }
      if (!f) {
        ans[i] = mx;
        continue;
      }
      cout << "? " << arrSize - S[i].size();
      for (int j = 1; j <= arrSize; j++) {
        if (!m[j]) cout << " " << j;
      }
      cout << endl;
      cin >> ans[i];
    }
    cout << "!";
    for (int i = 1; i <= total_subsets; i++) {
      cout << " " << ans[i];
    }
    cout << "\n";
    cout << flush;
    string str;
    cin >> str;
    mp.clear();
    memset(sz, 0, sizeof(sz));
    for (int i = 1; i <= total_subsets; i++) {
      S[i].clear();
    }
  }
}
