#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.precision(12);
  std::cerr.precision(12);
  std::mt19937 rng((std::uint_fast32_t)std::chrono::high_resolution_clock::now()
                       .time_since_epoch()
                       .count());
  int test_cases;
  cin >> test_cases;
  while (test_cases--) {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> sets(k);
    for (int i = 0; i < k; ++i) {
      int c;
      cin >> c;
      sets[i].resize(c);
      for (int j = 0; j < c; ++j) {
        cin >> sets[i][j];
      }
    }
    cout << "? " << n;
    for (int i = 1; i <= n; ++i) {
      cout << ' ' << i;
    }
    cout << endl;
    int mx;
    cin >> mx;
    auto ask = [&](int first, int last) {
      int c = 0;
      for (int i = first; i <= last; ++i) {
        c += (int)sets[i].size();
      }
      cout << "? " << c;
      for (int i = first; i <= last; ++i) {
        for (int x : sets[i]) {
          cout << ' ' << x;
        }
      }
      cout << endl;
      int res;
      cin >> res;
      return res;
    };
    int low = 0, high = k;
    while (low < high) {
      int mid = (low + high) >> 1;
      if (ask(low, mid) == mx) {
        high = mid;
      } else {
        low = mid + 1;
      }
    }
    vector<int> ans(k, mx);
    if (low < k) {
      vector<bool> want(n + 1, true);
      for (int x : sets[low]) {
        want[x] = false;
      }
      cout << "? " << n - (int)sets[low].size();
      for (int i = 1; i <= n; ++i) {
        if (want[i]) {
          cout << ' ' << i;
        }
      }
      cout << endl;
      cin >> ans[low];
    }
    cout << '!';
    for (int i = 0; i < k; ++i) {
      cout << ' ' << ans[i];
    }
    cout << endl;
    string s;
    cin >> s;
  }
  return 0;
}
