#include <bits/stdc++.h>
using namespace std;
int bs(int st, int en, int m) {
  if (st > en) return en;
  int mid = st + (en - st) / 2;
  cout << "? " << mid << " ";
  for (int i = 1; i <= mid; i++) cout << i << " ";
  cout << '\n';
  cout.flush();
  int val;
  cin >> val;
  if (val < m)
    return bs(mid + 1, en, m);
  else
    return bs(st, mid - 1, m);
}
int solve() {
  int n, k;
  cin >> n >> k;
  vector<vector<int> > v(k);
  int c, a;
  for (int i = 0; i < k; i++) {
    cin >> c;
    while (c--) {
      cin >> a;
      v[i].push_back(a);
    }
  }
  cout << "? " << n << " ";
  for (int i = 1; i <= n; i++) cout << i << " ";
  cout << '\n';
  cout.flush();
  int m;
  cin >> m;
  int idx = bs(1, n, m) + 1;
  vector<int> ans(k);
  for (int i = 0; i < k; i++) {
    bool flag = false;
    map<int, bool> mp;
    for (auto x : v[i]) {
      if (x == idx) {
        flag = 1;
      }
      mp[x] = 1;
    }
    if (!flag)
      ans[i] = m;
    else {
      cout << "? " << n - v[i].size() << " ";
      for (int i = 1; i < n + 1; i++) {
        if (mp[i] == false) cout << i << " ";
      }
      cout << '\n';
      cout.flush();
      cin >> ans[i];
    }
  }
  cout << "! ";
  for (int i = 0; i < k; i++) {
    cout << ans[i] << " ";
  }
  cout << '\n';
  cout.flush();
  string resp;
  cin >> resp;
  if (resp[0] == 'I') return 0;
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  for (int i = 1; i < t + 1; i++) {
    if (solve() == 0) return -1;
  }
  return 0;
}
