#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
void read(int& val) {
  int x = 0;
  int bz = 1;
  char c;
  for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
    ;
  if (c == '-') {
    bz = -1;
    c = getchar();
  }
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  val = x * bz;
}
const int maxn = 1e3 + 11;
const int mod = 1e9 + 7;
vector<int> all;
int pr() {
  cout << "? " << all.size() << " ";
  for (auto to : all) {
    cout << to << " ";
  }
  cout << endl;
  fflush(stdout);
  int x;
  cin >> x;
  return x;
}
int n, k;
vector<int> g[maxn];
int ans[maxn];
int get(int res) {
  vector<int> v(n + 1);
  for (auto to : g[res]) {
    v[to] = true;
  }
  all.clear();
  for (int i = 1; i <= n; i++) {
    if (!v[i]) all.emplace_back(i);
  }
  return pr();
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (int i = 1; i <= k; i++) g[i].clear();
    for (int i = 1; i <= k; i++) {
      int x, y;
      cin >> x;
      for (int j = 1; j <= x; j++) {
        cin >> y;
        g[i].emplace_back(y);
      }
    }
    all.clear();
    for (int i = 1; i <= n; i++) all.emplace_back(i);
    int mx = pr();
    int l = 1, r = k, res = 1;
    while (l <= r) {
      int mid = l + r >> 1;
      all.clear();
      for (int i = l; i <= mid; i++) {
        for (auto to : g[i]) all.emplace_back(to);
      }
      int tmp = pr();
      if (tmp >= mx) {
        r = mid - 1;
        res = mid;
      } else {
        l = mid + 1;
      }
    }
    for (int i = 1; i <= k; i++) ans[i] = mx;
    ans[res] = get(res);
    cout << "! ";
    for (int i = 1; i <= k; i++) cout << ans[i] << " ";
    cout << endl;
    fflush(stdout);
    string ss;
    cin >> ss;
  }
  return 0;
}
