#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1005;
int test, n, k;
int dd[MaxN], ans[MaxN];
vector<int> a[MaxN];
int main() {
  cin >> test;
  while (test--) {
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
      a[i].clear();
      dd[i] = 0;
    }
    for (int i = 1; i <= k; ++i) {
      int sz;
      cin >> sz;
      a[i].resize(sz);
      for (auto &v : a[i]) {
        cin >> v;
        dd[v] = i;
      }
    }
    cout << "? " << n << ' ';
    for (int i = 1; i <= n; ++i) {
      cout << i << ' ';
    }
    cout << endl;
    int maxi;
    cin >> maxi;
    for (int i = 1; i <= k; ++i) {
      ans[i] = maxi;
    }
    int l = 1, r = n, an = 0;
    while (l < r) {
      int mid = l + (r - l) / 2;
      cout << "? " << mid - l + 1 << ' ';
      for (int i = l; i <= mid; ++i) {
        cout << i << ' ';
      }
      cout << endl;
      int que;
      cin >> que;
      if (que == maxi) {
        r = mid;
      } else {
        l = mid + 1;
      }
    }
    if (dd[l]) {
      cout << "? " << n - a[dd[l]].size() << ' ';
      for (int i = 1; i <= n; ++i) {
        if (dd[i] != dd[l]) {
          cout << i << ' ';
        }
      }
      cout << endl;
      cin >> ans[dd[l]];
    }
    cout << "! ";
    for (int i = 1; i <= k; ++i) {
      cout << ans[i] << ' ';
    }
    cout << endl;
    string s;
    cin >> s;
    if (s != "Correct") {
      return 0;
    }
  }
  return 0;
}
