#include <bits/stdc++.h>
using namespace std;
int n, k;
int query(int i, int j) {
  if (i > j) return -1;
  cout << "? " << j - i + 1 << " ";
  for (int k = i; k <= j; k++) cout << k << " ";
  cout << endl << flush;
  int a;
  cin >> a;
  return a;
}
int main(int argc, char **argv) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int m, a;
    cin >> n >> k;
    vector<vector<int> > v(k);
    for (int i = 0; i < k; i++) {
      cin >> m;
      for (int j = 0; j < m; j++) {
        cin >> a;
        v[i].push_back(a);
      }
      sort(v[i].begin(), v[i].end());
    }
    int ma = query(1, n);
    int st = 1;
    for (int i = 9; i >= 0; i--) {
      if (query(st + (1 << i), n) == ma) st += 1 << i;
    }
    int fl = -1;
    for (int i = 0; i < k; i++) {
      if (binary_search(v[i].begin(), v[i].end(), st)) {
        fl = i;
        break;
      }
    }
    if (fl == -1) {
      cout << "! ";
      for (int i = 0; i < k; i++) cout << ma << " ";
      cout << endl << flush;
    } else {
      vector<int> temp;
      for (int i = 0; i < n; i++) {
        if (binary_search(v[fl].begin(), v[fl].end(), i + 1)) continue;
        temp.push_back(i + 1);
      }
      cout << "? " << temp.size() << " ";
      for (int i = 0; i < temp.size(); i++) cout << temp[i] << " ";
      cout << endl << flush;
      int ans;
      cin >> ans;
      cout << "! ";
      for (int i = 0; i < k; i++) {
        if (i != fl)
          cout << ma << " ";
        else
          cout << ans << " ";
      }
      cout << endl << flush;
    }
    string s;
    cin >> s;
    if (s == "Incorrect") {
      return 0;
    }
  }
}
