#include <bits/stdc++.h>
using namespace std;
const long long MXN = 2e5 + 10;
long long q, n, k, sz, x, now;
long long Ans[MXN];
vector<long long> vec[MXN];
bool mark[MXN];
string Ok;
void solve() {
  cout.flush();
  cin >> n >> k;
  for (int i = 1; i <= n; i++) vec[i].clear(), mark[i] = 0;
  for (int i = 1; i <= k; i++) {
    cin >> sz;
    for (int j = 0; j < sz; j++) {
      cin >> x;
      vec[i].push_back(x);
    }
  }
  cout.flush();
  cout << "? " << n << ' ';
  for (int i = 1; i <= n; i++) cout << i << ' ';
  cout << '\n';
  cout.flush();
  long long Max;
  cin >> Max;
  long long l = 1, r = n;
  while (r != l) {
    long long mid = (l + r) / 2;
    cout.flush();
    cout << "? " << (mid - l + 1) << ' ';
    for (int i = l; i <= mid; i++) cout << i << ' ';
    cout << '\n';
    cout.flush();
    cin >> now;
    if (now == Max)
      r = mid;
    else
      l = mid + 1;
  }
  long long id = l;
  for (int i = 1; i <= k; i++) {
    bool f = 0;
    for (auto ind : vec[i]) {
      if (ind == id) {
        f = 1;
      }
    }
    if (!f)
      Ans[i] = Max;
    else {
      for (auto ind : vec[i]) mark[ind] = 1;
      cout.flush();
      cout << "? " << (n - (int)vec[i].size()) << ' ';
      for (int j = 1; j <= n; j++) {
        if (mark[j]) continue;
        cout << j << ' ';
      }
      cout << '\n';
      cout.flush();
      cin >> Ans[i];
    }
  }
  cout.flush();
  cout << "! ";
  for (int i = 1; i <= k; i++) cout << Ans[i] << ' ';
  cout << '\n';
  cout.flush();
  cin >> Ok;
  if (Ok == "Correct")
    return;
  else
    exit(0);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  while (q--) solve();
  return 0;
}
