#include <bits/stdc++.h>
using namespace std;
vector<int> ss[100005];
int pregunta(vector<int> q) {
  if (q.size() == 0) return 0;
  cout << "? " << q.size() << " ";
  for (int i = 0; i < q.size(); i++) {
    cout << q[i] << " ";
  }
  cout << '\n';
  int result;
  cin >> result;
  return result;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
      ss[i].clear();
      int sz;
      cin >> sz;
      for (int j = 0; j < sz; j++) {
        int temp;
        cin >> temp;
        ss[i].push_back(temp);
      }
    }
    int sz = 0;
    vector<int> que;
    for (int i = 0; i < k; i++) {
      sz += ss[i].size();
      for (int j = 0; j < ss[i].size(); j++) {
        que.push_back(ss[i][j]);
      }
    }
    vector<int> result;
    int maxik = pregunta(que);
    int lo = 0;
    int hi = k - 1;
    while (hi != lo) {
      int m = (hi + lo) / 2;
      vector<int> q;
      for (int i = lo; i <= m; i++) {
        for (int j = 0; j < ss[i].size(); j++) {
          q.push_back(ss[i][j]);
        }
      }
      int currentm = pregunta(q);
      if (currentm < maxik) {
        lo = m + 1;
      } else {
        hi = m;
      }
    }
    map<int, bool> is;
    for (int i = 0; i < ss[hi].size(); i++) {
      is[ss[hi][i]] = true;
    }
    vector<int> q;
    for (int i = 1; i <= n; i++) {
      if (!is[i]) q.push_back(i);
    }
    int resto = pregunta(q);
    for (int i = 0; i < k; i++) {
      if (i == hi) {
        result.push_back(resto);
      } else {
        result.push_back(max(resto, maxik));
      }
    }
    cout << "! ";
    for (int i = 0; i < k; i++) {
      cout << result[i] << " ";
    }
    cout << '\n';
    string ans;
    cin >> ans;
    if (ans == "Incorrect") return 0;
  }
  return 0;
}
