#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long long inf = 1LL << 30;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const int N = 1010;
vector<int> v[N];
bool vis[N];
char s[22];
int id[N];
void _clear() {
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < N; i++) {
    v[i].clear();
    id[i] = 0;
  }
}
int ask(int l, int r) {
  printf("? %d ", r - l + 1);
  for (int i = l; i <= r; i++) printf("%d ", i);
  printf("\n");
  fflush(stdout);
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    _clear();
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= k; i++) {
      int m;
      scanf("%d", &m);
      for (int j = 0; j < m; j++) {
        int x;
        scanf("%d", &x);
        v[i].push_back(x);
        id[x] = i;
      }
    }
    int mx = ask(1, n);
    int lo = 1, hi = n;
    while (hi > lo) {
      int mid = (lo + hi) / 2;
      if (ask(lo, mid) == mx)
        hi = mid;
      else
        lo = mid + 1;
    }
    if (!id[lo]) {
      printf("!");
      for (int i = 0; i < k; i++) printf(" %d", mx);
      printf("\n");
      fflush(stdout);
      scanf("%s", &s);
      if (s[0] == 'I') return 0;
    } else {
      for (auto x : v[id[lo]]) vis[x] = 1;
      printf("? %d ", n - v[id[lo]].size());
      for (int i = 1; i <= n; i++)
        if (!vis[i]) printf("%d ", i);
      printf("\n");
      fflush(stdout);
      int mx1;
      scanf("%d", &mx1);
      printf("!");
      for (int i = 1; i <= k; i++)
        if (i == id[lo])
          printf(" %d", mx1);
        else
          printf(" %d", mx);
      printf("\n");
      fflush(stdout);
      scanf("%s", &s);
      if (s[0] == 'I') return 0;
    }
  }
}
