#include <bits/stdc++.h>
using namespace std;
const int NN = 1100;
vector<int> s[NN];
char res[20];
int f[NN], sum[NN];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) s[i].clear();
    memset(f, 0, sizeof(f));
    for (int i = 1; i <= k; i++) {
      int c;
      scanf("%d", &c);
      for (int j = 1; j <= c; j++) {
        int x;
        scanf("%d", &x);
        f[x] = i;
        s[i].push_back(x);
      }
      sum[i] = sum[i - 1] + c;
    }
    int maxs = 0;
    printf("? %d\n", sum[k]);
    for (int i = 1; i <= n; i++) {
      if (f[i]) printf("%d ", i);
    }
    printf("\n");
    fflush(stdout);
    scanf("%d", &maxs);
    int l = 1, r = k;
    while (l < r) {
      int mid = (l + r) >> 1;
      printf("? %d\n", sum[mid] - sum[l - 1]);
      for (int i = l; i <= mid; i++) {
        int sz = s[i].size();
        for (int j = 0; j < sz; j++) {
          printf("%d ", s[i][j]);
        }
      }
      printf("\n");
      fflush(stdout);
      int pd;
      scanf("%d", &pd);
      if (pd >= maxs) {
        r = mid;
      } else {
        l = mid + 1;
      }
    }
    memset(f, 0, sizeof(f));
    for (int i = 0; i < s[l].size(); i++) f[s[l][i]] = 1;
    int expl = 0;
    if (n - s[l].size() != 0) {
      printf("? %d\n", n - s[l].size());
      for (int i = 1; i <= n; i++) {
        if (f[i] == 0) {
          printf("%d ", i);
        }
      }
      printf("\n");
      fflush(stdout);
      scanf("%d", &expl);
    }
    printf("! ");
    for (int i = 1; i <= k; i++) {
      if (i != l) {
        printf("%d ", max(maxs, expl));
      } else {
        printf("%d ", expl);
      }
    }
    printf("\n");
    fflush(stdout);
    scanf("%s", res);
  }
  return 0;
}
