#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e3 + 100;
set<int> node[N], st;
int ans[N];
char s[N];
int get_max(int l, int r) {
  printf("? %d", r - l + 1);
  for (int i = l; i <= r; i++) printf(" %d", i);
  puts("");
  fflush(stdout);
  int mmax;
  scanf("%d", &mmax);
  return mmax;
}
void init(int n) {
  st.clear();
  for (int i = 1; i <= n; i++) st.insert(i);
}
int main() {
  int w;
  cin >> w;
  while (w--) {
    int n, k;
    scanf("%d%d", &n, &k);
    init(n);
    for (int i = 1; i <= k; i++) {
      node[i].clear();
      int t;
      scanf("%d", &t);
      while (t--) {
        int num;
        scanf("%d", &num);
        node[i].insert(num);
      }
    }
    int mmax = get_max(1, n);
    int l = 1, r = n;
    while (l < r) {
      int mid = l + r >> 1;
      if (get_max(l, mid) == mmax)
        r = mid;
      else
        l = mid + 1;
    }
    for (int i = 1; i <= k; i++) {
      if (node[i].count(l)) {
        for (auto v : node[i]) st.erase(v);
        printf("? %d", st.size());
        for (auto v : st) printf(" %d", v);
        puts("");
        fflush(stdout);
        scanf("%d", &ans[i]);
      } else
        ans[i] = mmax;
    }
    printf("! %d", ans[1]);
    for (int i = 2; i <= k; i++) printf(" %d", ans[i]);
    puts("");
    fflush(stdout);
    scanf("%s", s);
  }
  return 0;
}
