#include <bits/stdc++.h>
using namespace std;
long long mod = (1000000007LL);
inline long long Mod(long long a, long long b) { return (a % b); }
inline long long poww(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b, swap(a, b);
  }
  return a;
}
void read(vector<int> &w, int n) {
  w.resize(n);
  for (int i = 0; i < n; i++) cin >> w[i];
}
void print(vector<int> &w) {
  for (int i = 0; i < (int)(w).size(); i++) {
    if (i == (int)(w).size() - 1)
      cout << w[i] << "\n";
    else
      cout << w[i] << " ";
  }
}
int prodmod(vector<int> w);
int summod(vector<int> w);
int n, m, q, k;
int query(vector<int> subset) {
  cout << "? " << (int)(subset).size() << " ";
  for (auto w : subset) cout << w << " ";
  cout << endl;
  int mx;
  cin >> mx;
  return mx;
}
int conjj[1020];
vector<int> T[1020];
int get(int ini, int fim, int mx) {
  if (ini == fim) {
    return ini;
  }
  int mid = (ini + fim) / 2;
  vector<int> L, R;
  for (int i = ini; i <= fim; i++) {
    if (i <= mid)
      L.push_back(i);
    else
      R.push_back(i);
  }
  int A = query(L);
  if (A == mx)
    return get(ini, mid, mx);
  else
    return get(mid + 1, fim, mx);
}
int32_t main() {
  int q;
  cin >> q;
  while (q--) {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) T[i].clear(), conjj[i] = 0;
    for (int i = 1; i <= k; i++) {
      int u;
      cin >> u;
      while (u--) {
        int v;
        cin >> v;
        T[i].push_back(v);
        conjj[v] = i;
      }
    }
    vector<int> todos;
    for (int i = 1; i <= n; i++) todos.push_back(i);
    int mx = query(todos);
    int u = get(1, n, mx);
    vector<int> outros;
    for (int i = 1; i <= n; i++) {
      if (conjj[i] != conjj[u]) {
        outros.push_back(i);
      }
    }
    if (!outros.empty()) {
      int o = query(outros);
      cout << "! ";
      for (int i = 1; i <= k; i++) {
        if (i == conjj[u])
          cout << o << " ";
        else
          cout << mx << " ";
      }
      cout << endl;
    }
    string FDPPPPP;
    cin >> FDPPPPP;
  }
}
int summod(vector<int> w) {
  int curr = 0;
  for (int i = 0; i < (int)(w).size(); i++) {
    curr = (curr + w[i]) % mod;
    if (curr < 0) curr += mod;
  }
  return curr;
}
int prodmod(vector<int> w) {
  int curr = 1;
  for (int i = 0; i < (int)(w).size(); i++) {
    if (w[i] >= mod) w[i] %= mod;
    curr = (curr * w[i]) % mod;
    if (curr < 0) curr += mod;
  }
  return curr;
}
