#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int read() {
  int x = 0, flag = 1;
  char c = getchar();
  while ((c > '9' || c < '0') && c != '-') c = getchar();
  if (c == '-') flag = 0, c = getchar();
  while (c <= '9' && c >= '0') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return flag ? x : -x;
}
const int maxn = 1005;
int n, k, t, vis[maxn], m, ans[maxn];
vector<int> a[maxn];
char s[maxn];
int getR(int l, int r) {
  int sum = 0;
  for (int i = (l); i <= (int)(r); i++) sum += a[i].size();
  printf("? %d ", sum);
  for (int i = (l); i <= (int)(r); i++)
    for (int j = (0); j <= (int)(a[i].size() - 1); j++) printf("%d ", a[i][j]);
  puts("");
  fflush(stdout);
  return read();
}
int main() {
  t = read();
  while (t--) {
    n = read(), k = read();
    for (int i = (1); i <= (int)(k); i++) a[i].clear();
    for (int i = (1); i <= (int)(k); i++) {
      int c = read();
      while (c--) a[i].push_back(read());
    }
    printf("? %d ", n);
    for (int i = (1); i <= (int)(n); i++) printf("%d ", i);
    puts("");
    fflush(stdout);
    m = read();
    for (int i = (1); i <= (int)(k); i++) ans[i] = m;
    int l = 1, r = k, mid, m1, m2;
    while (l < r) {
      mid = (l + r) >> 1;
      m1 = getR(l, mid);
      if (m1 == m)
        r = mid;
      else
        l = mid + 1;
    }
    if (l <= r) {
      printf("? %d ", n - a[l].size());
      for (int i = (1); i <= (int)(n); i++) {
        int flag = 0;
        for (int j = (0); j <= (int)(a[l].size() - 1); j++)
          if (a[l][j] == i) flag = 1;
        if (!flag) printf("%d ", i);
      }
      puts("");
      fflush(stdout);
      ans[l] = read();
    }
    printf("! ");
    for (int i = (1); i <= (int)(k); i++) printf("%d ", ans[i]);
    puts("");
    fflush(stdout);
    scanf("%s", s);
    if (strcmp(s, "Correct")) break;
  }
  return 0;
}
