#include <bits/stdc++.h>
using namespace std;
int cansel_sync = (ios::sync_with_stdio(0), cin.tie(0), 0);
const int N = 1010;
int T, n, k;
vector<int> a[N];
vector<int> q;
int ans[N];
string s;
int query() {
  cout << "? " << q.size();
  for (auto i : q) cout << ' ' << i;
  cout << endl;
  cout.flush();
  int ans;
  cin >> ans;
  if (ans == -1) exit(233);
  return ans;
}
void pushquery(int l, int r) {
  for (int i = (l), _ = (r + 1); i < _; i++)
    for (auto j : a[i]) q.push_back(j);
}
void output() {
  cout << "! ";
  for (int i = (1), _ = (k + 1); i < _; i++) cout << ans[i] << ' ';
  cout << endl;
  cout.flush();
  cin >> s;
  if (s[0] == 'I') exit(234);
}
signed main() {
  cin >> T;
  while (T--) {
    cin >> n >> k;
    for (int i = (1), _ = (k + 1); i < _; i++) {
      int c;
      cin >> c;
      a[i].clear();
      while (c--) {
        int x;
        cin >> x;
        a[i].push_back(x);
      }
      sort(a[i].begin(), a[i].end());
      a[i].erase(unique(a[i].begin(), a[i].end()), a[i].end());
    }
    int l = 1, r = k;
    q.clear();
    for (int i = (1), _ = (n + 1); i < _; i++) q.push_back(i);
    int maxx = query();
    fill(ans + 1, ans + k + 1, maxx);
    while (l < r) {
      int m = (l + r) / 2;
      q.clear();
      pushquery(l, m);
      if (query() != maxx)
        l = m + 1;
      else
        r = m;
    }
    int t = l;
    {
      sort(a[t].begin(), a[t].end());
      q.clear();
      for (int i = (1), _ = (n + 1); i < _; i++) {
        if (!binary_search(a[t].begin(), a[t].end(), i)) q.push_back(i);
      }
      ans[t] = query();
    }
    output();
  }
  return 0;
}
