#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const int MAXN = 1e3 + 5;
set<int> st[MAXN];
int ans[MAXN];
bool solve() {
  int n, k;
  cin >> n >> k;
  int l = 0;
  int r = k - 1;
  for (int i = 0; i < k; i++) {
    st[i].clear();
    int second;
    cin >> second;
    for (int j = 0; j < second; j++) {
      int c;
      cin >> c;
      st[i].insert(c);
    }
  }
  int mx;
  cout << "? " << n;
  for (int i = 0; i < n; i++) {
    cout << " " << i + 1;
  }
  cout << endl;
  cin >> mx;
  int lmx = 0;
  int queries = 1;
  while (l < r) {
    queries++;
    if (queries == 12) break;
    int m = (l + r) / 2;
    int psz = 0;
    for (int i = l; i <= m; i++) {
      psz += st[i].size();
    }
    cout << "? " << psz;
    for (int i = l; i <= m; i++) {
      for (auto& v : st[i]) {
        cout << " " << v;
      }
    }
    cout << endl;
    int lmax;
    cin >> lmax;
    if (lmax == mx) {
      for (int i = m + 1; i <= r; i++) ans[i] = mx;
      r = m;
    } else {
      lmx = max(lmx, lmax);
      for (int i = l; i <= m; i++) ans[i] = mx;
      l = m + 1;
    }
  }
  int psz = n - st[l].size();
  cout << "? " << psz;
  for (int i = 0; i < n; i++) {
    if (st[l].find(i + 1) == st[l].end()) cout << " " << i + 1;
  }
  cout << endl;
  cin >> ans[l];
  cout << "!";
  for (int i = 0; i < k; i++) {
    cout << " " << ans[i];
  }
  cout << endl;
  string res;
  cin >> res;
  if (res.compare("Correct") != 0) return false;
  return true;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    if (!solve()) break;
  }
}
