#include <bits/stdc++.h>
using namespace std;
const int MAX = 200010;
const int MOD = 1000000007;
const int INF = 1e8;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-7;
int query(int l, int r, vector<int> v) {
  vector<int> ind;
  for (int i = l; i <= r; i++) {
    ind.push_back(v[i]);
  }
  cout << "? " << ind.size() << " ";
  for (auto idx : ind) {
    cout << idx << " ";
  }
  cout << '\n';
  cout.flush();
  int x;
  cin >> x;
  assert(x >= 1);
  return x;
}
int query2(vector<int> ind) {
  cout << "? " << ind.size() << " ";
  for (auto idx : ind) {
    cout << idx << " ";
  }
  cout << '\n';
  cout.flush();
  int x;
  cin >> x;
  assert(x >= 1);
  return x;
}
int solve(int l, int r, int maior, vector<int>& v) {
  if (l == r) {
    return v[l];
  }
  int mid = (l + r) / 2;
  int val = query(l, mid, v);
  if (val == maior) {
    return solve(l, mid, maior, v);
  } else {
    return solve(mid + 1, r, maior, v);
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<int> eita;
    vector<int> res(k, -INF);
    vector<vector<int> > s(k, vector<int>());
    for (int i = 0; i < (int)k; i++) {
      int size;
      cin >> size;
      for (int j = 0; j < (int)size; j++) {
        int val;
        cin >> val;
        s[i].push_back(val);
        eita.push_back(val);
      }
    }
    if (eita.size() == 0) {
      cout << "wtf man" << '\n';
    }
    int maior = query2(eita);
    int idx = solve(0, eita.size() - 1, maior, eita);
    for (int i = 0; i < (int)k; i++) {
      set<int> v;
      bool dentro = false;
      for (auto val : s[i]) {
        v.insert(val);
        if (val == idx) dentro = true;
      }
      if (!dentro) {
        res[i] = maior;
      } else {
        vector<int> ind2;
        for (int i = 1; i <= n; i++) {
          if (!v.count(i)) ind2.push_back(i);
        }
        sort(ind2.begin(), ind2.end());
        int tmp = query2(ind2);
        res[i] = tmp;
      }
    }
    cout << "! ";
    for (auto r : res) {
      assert(r != -INF);
      cout << r << " ";
    }
    cout << '\n';
    string sol;
    cin >> sol;
    if (sol == "Incorrect") return 0;
  }
  return 0;
}
