#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const int N = 1e6;
const long long INF = 1e18;
const long double EPS = 10e-9;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long random(long long a, long long b) {
  return uniform_int_distribution<long long>(a, b)(rng);
}
long long M;
long long query(long long l, long long r) {
  cout << "? " << r - l + 1;
  for (long long i = l; i < r + 1; i++) cout << " " << i;
  cout << endl;
  long long x;
  cin >> x;
  return x;
}
long long search(long long l, long long r) {
  M = query(l, r);
  if (l == r) return l;
  while (l != r) {
    long long m = (l + r) / 2;
    long long cur = query(l, m);
    if (cur == M)
      r = m;
    else
      l = m + 1;
  }
  return l;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> s[k];
  for (long long i = 0; i < k; i++) {
    long long sz;
    cin >> sz;
    for (long long j = 0; j < sz; j++) {
      long long x;
      cin >> x;
      s[i].push_back(x);
    }
  }
  long long pos = search(1, n);
  long long found = -1;
  for (long long i = 0; i < k; i++) {
    int sz = s[i].size();
    for (long long j = 0; j < sz; j++) {
      if (s[i][j] == pos) {
        found = i;
        break;
      }
    }
    if (found != -1) break;
  }
  if (found == -1) {
    cout << "!";
    for (long long i = 0; i < k; i++) cout << " " << M;
    cout << endl;
    string F;
    cin >> F;
    return;
  }
  long long p[k];
  for (long long i = 0; i < k; i++) p[i] = M;
  set<long long> mens;
  for (long long i = 1; i < n + 1; i++) mens.insert(i);
  int sz = s[found].size();
  for (long long i = 0; i < sz; i++) mens.erase(s[found][i]);
  sz = mens.size();
  cout << "? " << sz;
  std::set<long long>::iterator it;
  for (it = mens.begin(); it != mens.end(); it++) cout << " " << *it;
  cout << endl;
  cin >> p[found];
  cout << "!";
  for (long long i = 0; i < k; i++) cout << " " << p[i];
  cout << endl;
  string F;
  cin >> F;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
