#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int st[N];
char s[20];
int query(vector<int> ask) {
  printf("? %d", (int)ask.size());
  for (auto v : ask) {
    printf(" %d", v);
  }
  printf("\n");
  fflush(stdout);
  int ans;
  scanf("%d", &ans);
  return ans;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) {
      st[i] = 0;
    }
    for (int i = 1; i <= k; i++) {
      int c;
      scanf("%d", &c);
      for (int j = 1; j <= c; j++) {
        int x;
        scanf("%d", &x);
        st[x] = i;
      }
    }
    vector<int> ask;
    for (int i = 1; i <= n; i++) {
      ask.push_back(i);
    }
    int mx = query(ask);
    int l = 1, r = n, mid;
    while (r != l) {
      mid = (l + r) >> 1;
      ask.clear();
      for (int i = l; i <= mid; i++) {
        ask.push_back(i);
      }
      int x = query(ask);
      if (x == mx)
        r = mid;
      else
        l = mid + 1;
    }
    ask.clear();
    for (int i = 1; i <= n; i++) {
      if (st[i] != st[l]) {
        ask.push_back(i);
      }
    }
    int ans = query(ask);
    printf("!");
    for (int i = 1; i <= k; i++) {
      if (st[l] != i) {
        printf(" %d", mx);
      } else
        printf(" %d", ans);
    }
    printf("\n");
    fflush(stdout);
    scanf("%s", s);
    if (s[0] == 'I') {
      return 0;
    }
  }
  return 0;
}
