#include <bits/stdc++.h>
using namespace std;
long long INF = 0x7FFFFFFFFFFFFFFF;
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long ask(vector<long long>& v) {
  cout << "? " << (long long int)(v).size() << ' ';
  for (long long i = 0; i < (long long int)(v).size(); ++i) cout << v[i] << ' ';
  cout << "\n" << flush;
  long long res;
  cin >> res;
  return res;
}
vector<long long> comp(vector<long long>& st, long long n) {
  vector<bool> pres(n + 1, 0);
  for (long long i = 0; i < (long long int)(st).size(); ++i) pres[st[i]] = 1;
  vector<long long> res;
  for (long long i = 1; i < n + 1; ++i) {
    if (!pres[i]) res.push_back(i);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    long long n, k;
    cin >> n >> k;
    vector<vector<long long> > st(k);
    for (long long i = 0; i < k; ++i) {
      long long c;
      cin >> c;
      st[i].resize(c);
      for (long long j = 0; j < c; ++j) cin >> st[i][j];
    }
    vector<long long> a(n);
    iota((a).begin(), (a).end(), 1);
    long long mx = ask(a);
    long long l = 0, r = k - 1;
    while (l < r) {
      long long md = (l + r) / 2;
      a.clear();
      for (long long i = 0; i < md + 1; ++i) {
        for (long long j = 0; j < (long long int)(st[i]).size(); ++j)
          a.push_back(st[i][j]);
      }
      long long m = ask(a);
      if (m == mx)
        r = md;
      else
        l = md + 1;
    }
    vector<long long> ans(k, mx);
    vector<long long> c = comp(st[l], n);
    long long m = ask(c);
    ans[l] = m;
    cout << "! ";
    for (long long i = 0; i < k; ++i) cout << ans[i] << ' ';
    cout << "\n" << flush;
    string strl;
    cin >> strl;
  }
}
