#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int inf = 1e9 + 7;
int ans[N], tem[N];
char ss[N];
vector<vector<int> > v(N);
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= k; i++) v[i].clear();
    for (int i = 1; i <= k; i++) {
      int a;
      scanf("%d", &a);
      for (int j = 1; j <= a; j++) {
        int b;
        scanf("%d", &b);
        v[i].push_back(b);
      }
    }
    int mx;
    printf("? %d", n);
    for (int i = 1; i <= n; i++) printf(" %d", i);
    printf("\n");
    fflush(stdout);
    scanf("%d", &mx);
    int l = 1, r = n;
    while (l < r) {
      int mid = (r + l) >> 1;
      printf("? %d", r - mid);
      for (int i = mid + 1; i <= r; i++) printf(" %d", i);
      printf("\n");
      fflush(stdout);
      int x;
      scanf("%d", &x);
      if (x == mx)
        l = mid + 1;
      else
        r = mid;
    }
    int id = l;
    int pos = -1, ti = 0;
    for (int i = 1; i <= k; i++) {
      bool tp = 0;
      for (int j = 0; j < v[i].size(); j++)
        if (v[i][j] == id) tp = 1;
      if (tp && !ti) {
        int cnt = 0;
        for (int j = 1; j <= n; j++) {
          bool fi = 0;
          for (int p = 0; p < v[i].size(); p++)
            if (v[i][p] == j) {
              fi = 1;
              break;
            }
          if (!fi) tem[++cnt] = j;
        }
        printf("? %d", cnt);
        for (int j = 1; j <= cnt; j++) printf(" %d", tem[j]);
        printf("\n");
        fflush(stdout);
        int x;
        scanf("%d", &x);
        ans[i] = x;
        ti = 1;
      } else
        ans[i] = mx;
    }
    printf("!");
    for (int i = 1; i <= k; i++) printf(" %d", ans[i]);
    printf("\n");
    fflush(stdout);
    scanf("%s", ss);
  }
}
