#include <bits/stdc++.h>
using namespace std;
const long long M = 1e5 + 10;
long long t, n, k, m;
vector<long long> v[M];
void clearing() {
  for (long long i = 1; i <= k; i++) v[i].clear();
}
long long query(set<long long> q) {
  cout << "? " << q.size();
  for (auto x : q) cout << " " << x;
  cout << endl;
  long long ret;
  cin >> ret;
  return ret;
}
pair<long long, long long> solve(long long l, long long r) {
  set<long long> h;
  for (long long i = 1; i <= n; i++) h.insert(i);
  long long mid = (l + r) / 2;
  for (long long i = l; i <= mid; i++)
    for (auto x : v[i]) h.erase(x);
  long long q = query(h);
  if (l == r) {
    if (q == m)
      return {0, 0};
    else
      return {l, q};
  }
  if (q == m)
    return solve(mid + 1, r);
  else
    return solve(l, mid);
}
int32_t main() {
  cin >> t;
  while (t--) {
    cin >> n >> k;
    set<long long> h;
    for (long long i = 1; i <= n; i++) h.insert(i);
    for (long long i = 1; i <= k; i++) {
      long long c;
      cin >> c;
      v[i].resize(c);
      for (long long j = 0; j < c; j++) cin >> v[i][j];
    }
    m = query(h);
    auto lst = solve(1, k);
    if (lst.first == 0) {
      cout << "!";
      for (long long i = 0; i < k; i++) cout << " " << m;
      cout << endl;
    } else {
      cout << "!";
      for (long long i = 1; i < lst.first; i++) cout << " " << m;
      cout << " " << lst.second;
      for (long long i = lst.first + 1; i <= k; i++) cout << " " << m;
      cout << endl;
    }
    string cor;
    cin >> cor;
    clearing();
  }
  return 0;
}
