#include <bits/stdc++.h>
using namespace std;
long long a[300000], b[3000][2000], vs[300000];
vector<long long> v;
int main() {
  ios_base::sync_with_stdio(false);
  long long i, j = 0, k = 0, mod = 1e9, m, mx, n, l = 0, p, t, h, kk = 0,
               cnt = 0;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    mx = 0;
    v.clear();
    for (i = 1; i <= k; i++) {
      cin >> a[i];
      for (j = 1; j <= a[i]; j++) cin >> b[i][j];
    }
    cout << "? " << n << ' ' << flush;
    for (i = 1; i <= n; i++) cout << i << ' ';
    cout << endl << flush;
    cin >> mx;
    l = 1;
    h = k;
    while (l < h) {
      m = (l + h) / 2;
      v.clear();
      for (i = l; i <= m; i++) {
        for (j = 1; j <= a[i]; j++) v.push_back(b[i][j]);
      }
      cout << "? " << v.size() << ' ' << flush;
      for (i = 0; i < v.size(); i++) cout << v[i] << ' ';
      cout << endl << flush;
      cin >> j;
      if (j != mx)
        l = m + 1;
      else
        h = m;
    }
    v.clear();
    for (i = 1; i <= a[l]; i++) vs[b[l][i]] = 1;
    for (i = 1; i <= n; i++) {
      if (!vs[i]) v.push_back(i);
    }
    cout << "? " << v.size() << ' ' << flush;
    for (i = 0; i < v.size(); i++) cout << v[i] << ' ';
    cout << endl << flush;
    cin >> j;
    cout << "! " << flush;
    for (i = 1; i <= k; i++) {
      if (i == l)
        cout << j << ' ';
      else
        cout << mx << ' ';
      cout << flush;
    }
    cout << endl << flush;
    for (i = 1; i <= n; i++) vs[i] = 0;
    string s;
    cin >> s;
    if (s == "Incorrect") return 0;
  }
  return 0;
}
