#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007;
const long long INFL = 1000000000000000007;
const long double INFS = 0.00000001;
const long long MOD = 1000000007;
const long double PI = 3.14159265;
const int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const int dir2[8][2] = {{1, 1},  {1, 0},  {1, -1}, {0, 1},
                        {0, -1}, {-1, 1}, {-1, 0}, {-1, -1}};
long long re() {
  long long x;
  scanf("%lld", &x);
  return x;
}
char rc() {
  char x;
  scanf("%c", &x);
  return x;
}
string rs() {
  char x[10000001];
  scanf("%s", &x);
  return string(x);
}
void pr(long long x) { printf("%lld", x); }
void prc(char x) { printf("%c", x); }
void prs(string x) { printf("%s", x.c_str()); }
void ps() { printf(" "); }
void pl() { printf("\n"); }
long long min(long long x, long long y) { return x < y ? x : y; }
long long minr(vector<long long> x) {
  long long Min = INFL;
  for (auto i : x) Min = min(Min, i);
  return Min;
}
long long max(long long x, long long y) { return x > y ? x : y; }
long long maxr(vector<long long> x) {
  long long Max = -INFL;
  for (auto i : x) Max = max(Max, i);
  return Max;
}
void ex_gcd(long long a, long long b, long long &d, long long &x,
            long long &y) {
  if (!b)
    d = a, x = 1, y = 0;
  else
    ex_gcd(b, a % b, d, y, x), y -= x * (a / b);
}
long long modinv(long long x) {
  long long ret, tr1, tr2;
  ex_gcd(x, MOD, tr1, ret, tr2);
  while (ret < 0) ret += MOD;
  return ret;
}
int n, k;
int sz[1001];
vector<int> ele[1001];
bool used[1001];
int ans[1001];
bool wrong = false;
int query(int l, int r, int dir, int dir2) {
  vector<int> out;
  int i, j;
  if (dir == 0) {
    for (i = l; i <= r; i++)
      for (j = 0; j < ele[i].size(); j++) out.push_back(ele[i][j]);
  } else {
    for (i = 1; i < l; i++)
      for (j = 0; j < ele[i].size(); j++) out.push_back(ele[i][j]);
    for (i = l + 1; i <= k; i++)
      for (j = 0; j < ele[i].size(); j++) out.push_back(ele[i][j]);
  }
  if (dir2)
    for (i = 1; i <= n; i++)
      if (!used[i]) out.push_back(i);
  cout << "? " << out.size() << " ";
  for (i = 0; i < out.size() - 1; i++) cout << out[i] << " ";
  cout << out[i] << endl;
  int ret;
  cin >> ret;
  return ret;
}
void wk() {
  int i, j;
  cin >> n >> k;
  for (i = 1; i <= n; i++) used[i] = false;
  for (i = 1; i <= k; i++) {
    cin >> sz[i];
    ele[i].clear();
    for (j = 1; j <= sz[i]; j++) {
      int x;
      cin >> x;
      used[x] = true;
      ele[i].push_back(x);
    }
  }
  int Max = query(1, k, 0, 1);
  int lo = 1, hi = k, m;
  while (lo < hi) {
    m = (lo + hi) / 2;
    if (query(1, m, 0, 0) == Max) {
      for (j = m + 1; j <= hi; j++) ans[j] = Max;
      hi = m;
    } else {
      for (j = lo; j <= m; j++) ans[j] = Max;
      lo = m + 1;
    }
  }
  ans[lo] = query(lo, lo + 1, 1, 1);
  cout << "!";
  for (i = 1; i <= k; i++) cout << " " << ans[i];
  cout << endl;
  string s;
  cin >> s;
  if (s == "Incorrect") {
    wrong = true;
    while (true) {
      int aa = 1;
      aa++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  int i;
  cin >> t;
  for (i = 1; i <= t; i++)
    if (!wrong) wk();
  return 0;
}
