#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 998244353LL;
const int maxn = 1e3 + 5;
char s[105];
int a[maxn], c[maxn], d[maxn], ans[maxn];
bool b[maxn][maxn];
int n, k, mx, cnt;
int query(int x, int y) {
  assert(x <= y);
  printf("? %d", y - x + 1);
  for (int i = x; i <= y; ++i) {
    printf(" %d", i);
  }
  puts("");
  ++cnt;
  fflush(stdout);
  int ret;
  scanf("%d", &ret);
  return ret;
}
int query2(int x) {
  printf("? %d", n - c[x]);
  for (int i = 1; i <= n; ++i) {
    if (b[x][i]) continue;
    printf(" %d", i);
  }
  puts("");
  ++cnt;
  fflush(stdout);
  int ret;
  scanf("%d", &ret);
  return ret;
}
int bs() {
  int lf = 1, rt = n;
  while (lf < rt) {
    int mid = (lf + rt) >> 1;
    int now = query(lf, mid);
    if (now != mx)
      lf = mid + 1;
    else
      rt = mid;
  }
  return lf;
}
void output() {
  printf("!");
  for (int i = 1; i <= k; ++i) {
    printf(" %d", ans[i]);
  }
  puts("");
  fflush(stdout);
}
bool solve() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    d[i] = -1;
  }
  for (int i = 1; i <= k; ++i) {
    for (int j = 1; j <= n; ++j) b[i][j] = false;
    scanf("%d", &c[i]);
    for (int j = 1; j <= c[i]; ++j) {
      int x;
      scanf("%d", &x);
      b[i][x] = true;
      d[x] = i;
    }
  }
  cnt = 0;
  mx = query(1, n);
  for (int i = 1; i <= k; ++i) {
    ans[i] = mx;
  }
  int id = bs();
  if (d[id] != -1) {
    ans[d[id]] = query2(d[id]);
  }
  assert(cnt <= 12);
  output();
  scanf("%s", s);
  if (s[0] == 'C') {
    return true;
  }
  return false;
}
int main() {
  int T;
  scanf("%d", &T);
  for (int cs = 1; cs <= T; ++cs) {
    if (!solve()) break;
  }
  return 0;
}
