#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, x;
    cin >> n >> x;
    vector<vector<int>> v(x);
    int sz;
    int a;
    for (int i = 0; i < x; i++) {
      cin >> sz;
      for (int j = 0; j < sz; j++) {
        cin >> a;
        v[i].push_back(a);
      }
    }
    int maxx;
    cout << '?' << " " << n << " ";
    for (int i = 0; i < n; i++) {
      cout << i + 1 << " ";
    }
    cout << endl;
    cin >> maxx;
    int lo = 0, hi = x - 1, mid;
    int curr;
    while (lo < hi) {
      mid = (lo + hi) / 2;
      sz = 0;
      for (int i = lo; i <= mid; i++) {
        sz += v[i].size();
      }
      cout << "? " << sz << " ";
      for (int i = lo; i <= mid; i++) {
        for (auto it : v[i]) {
          cout << it << " ";
        }
      }
      cout << endl;
      cin >> curr;
      if (curr == maxx) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
    }
    sz = n - v[lo].size();
    unordered_set<int> us;
    for (auto it : v[lo]) {
      us.insert(it);
    }
    cout << "? " << sz << " ";
    for (int i = 0; i < n; i++) {
      if (us.find(i + 1) != us.end()) {
        continue;
      }
      cout << i + 1 << " ";
    }
    cout << endl;
    int temp;
    cin >> temp;
    cout << "! ";
    for (int i = 0; i < x; i++) {
      if (i == lo) {
        cout << temp << " ";
      } else {
        cout << maxx << " ";
      }
    }
    cout << endl;
    string ans;
    cin >> ans;
    if (ans == "Incorrect") {
      return 0;
    }
  }
  return 0;
}
