#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
vector<int> a[N];
int par[N];
int ask(int l, int r) {
  cout << "? " << r - l + 1;
  for (; l <= r; l++) cout << ' ' << l;
  cout << endl;
  int x;
  cin >> x;
  assert(x != -1);
  return x;
}
void solve() {
  int n, k;
  cin >> n >> k;
  fill(par, par + n + 1, 0);
  for (int i = 1; i <= k; i++) {
    int z;
    cin >> z;
    a[i].resize(z);
    for (auto &x : a[i]) {
      cin >> x;
      par[x] = i;
    }
  }
  int l = 1;
  int r = n;
  int mx = ask(1, n);
  int p = 0;
  while (l < r) {
    int m = (l + r) >> 1;
    if (ask(l, m) == mx) {
      r = m;
    } else
      l = m + 1;
  }
  int v = par[r];
  string verdict;
  if (v == 0) {
    cout << "! ";
    for (int i = 0; i < k; i++) cout << mx << ' ';
    cout << endl;
  } else {
    assert(a[v].size() != n);
    cout << "? " << n - a[v].size() << ' ';
    for (int i = 1; i <= n; i++) {
      if (par[i] != v) {
        cout << i << ' ';
      }
    }
    cout << endl;
    int mxx;
    cin >> mxx;
    cout << "! ";
    for (int i = 1; i <= k; i++) {
      if (i == v)
        cout << mxx << ' ';
      else
        cout << mx << ' ';
    }
    cout << endl;
  }
  cin >> verdict;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
