#include <bits/stdc++.h>
using namespace std;
int t, n, k, c[1005] = {0}, a[1005][1005], b[1005] = {0}, le, ri, x, maxx, pos,
             d[1005], p;
int main() {
  string s;
  cin >> t;
  while (t--) {
    c[0] = 0;
    cin >> n >> k;
    le = 1;
    ri = n;
    for (int i = 1; i <= k; i++) {
      cin >> c[i];
      for (int j = 1; j <= c[i]; j++) {
        cin >> a[i][j];
        b[a[i][j]] = i;
      }
    }
    cout << "? ";
    cout << n << " ";
    for (int i = 1; i <= n; i++) {
      cout << i << " ";
    }
    cout << endl;
    cin >> maxx;
    while (ri > le) {
      cout << "? ";
      pos = (le + ri) / 2;
      cout << pos - le + 1 << " ";
      for (int i = le; i <= pos; i++) {
        cout << i << " ";
      }
      cout << endl;
      cin >> x;
      if (x == maxx) {
        ri = pos;
      } else {
        le = pos + 1;
      }
    }
    cout << "? ";
    cout << n - c[b[le]] << " ";
    for (int i = 1; i <= n; i++) {
      p = 1;
      for (int j = 1; j <= c[b[le]]; j++) {
        if (i == a[b[le]][j]) {
          p = 0;
        }
      }
      if (p) {
        cout << i << " ";
      }
    }
    cout << endl;
    cin >> x;
    cout << "! ";
    for (int i = 1; i <= k; i++) {
      if (i != b[le]) {
        cout << maxx << " ";
      } else {
        cout << x << " ";
      }
    }
    cout << endl;
    cin >> s;
    for (int i = 0; i <= n; i++) {
      c[i] = 0;
      b[i] = 0;
    }
  }
}
