#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b % 2 != 0) {
      ans = (ans * a) % 1000000007;
    }
    a = ((a % 1000000007) * (a % 1000000007)) % 1000000007;
    b >>= 1;
  }
  return ans;
}
void sieve(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p]) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (int p = 2; p <= n; p++) {
    if (prime[p]) cout << p << " ";
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> v;
    for (int i = 0; i < k; i++) {
      int c;
      cin >> c;
      vector<int> temp;
      for (int j = 0; j < c; j++) {
        int z;
        cin >> z;
        temp.push_back(z);
      }
      v.push_back(temp);
    }
    int l = 1, h = n;
    int ma;
    cout << "?"
         << " " << n << " ";
    for (int i = 1; i <= n; i++) cout << i << " ";
    cout << endl;
    cin >> ma;
    for (int i = 0; i < 10; i++) {
      int mid = (h + l) / 2;
      int temp;
      cout << "?"
           << " " << mid - l + 1 << " ";
      for (int kha = l; kha <= mid; kha++) cout << kha << " ";
      cout << endl;
      cin >> temp;
      if (temp == ma)
        h = mid;
      else
        l = mid;
    }
    int ind = h;
    bool flag = false;
    vector<int> ans;
    for (int i = 0; i < v.size(); i++) {
      sort(v[i].begin(), v[i].end());
      for (int j = 0; j < v[i].size(); j++) {
        if (v[i][j] == ind) {
          flag = true;
          cout << "?"
               << " ";
          vector<int> loa;
          for (int lo = 1; lo <= n; lo++) {
            if (binary_search(v[i].begin(), v[i].end(), lo) == false) {
              loa.push_back(lo);
            }
          }
          cout << loa.size() << " ";
          for (auto lo : loa) cout << lo << " ";
          cout << endl;
          int kha;
          cin >> kha;
          ans.push_back(kha);
        }
      }
      if (flag == false) {
        ans.push_back(ma);
      } else {
        flag = false;
      }
    }
    cout << "!"
         << " ";
    for (auto i : ans) cout << i << " ";
    cout << endl;
    string sa;
    cin >> sa;
    if (sa == "Correct") {
      continue;
    } else {
      return 0;
    }
  }
  return 0;
}
