#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int mod = 998244353;
const double pi = acos(-1);
const int maxn = 200000 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
int t, n, k, num, sz;
int ans[1007], vis[1007];
vector<int> v[1007];
int query(int l, int r) {
  int cnt = 0;
  for (int i = 1; i <= n; ++i) vis[i] = 0;
  for (int i = l; i <= r; ++i) {
    for (auto x : v[i]) vis[x] = 1, ++cnt;
  }
  printf("? %d", n - cnt);
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) printf(" %d", i);
  }
  printf("\n");
  fflush(stdout);
  scanf("%d", &num);
  return num;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= k; ++i) {
      v[i].clear();
      scanf("%d", &sz);
      while (sz--) {
        scanf("%d", &num);
        v[i].emplace_back(num);
      }
    }
    int l = 1, r = k, mid;
    int mx = query(0, 0);
    while (l < r) {
      mid = (l + r) >> 1;
      int nw = query(l, mid);
      if (nw != mx) {
        for (int i = mid + 1; i <= r; ++i) ans[i] = mx;
        r = mid;
      } else {
        for (int i = l; i <= mid; ++i) ans[i] = mx;
        l = mid + 1;
      }
    }
    ans[l] = query(l, l);
    printf("!");
    for (int i = 1; i <= k; ++i) printf(" %d", ans[i]);
    printf("\n");
    fflush(stdout);
    scanf("%*s");
  }
  return 0;
}
