#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<long long>;
using vvb = vector<vector<bool>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vpii = vector<pair<int, int>>;
using mii = map<int, int>;
template <typename... ArgTypes>
void print(ArgTypes... args);
template <typename... ArgTypes>
void input(ArgTypes &...args);
template <>
void print() {}
template <>
void input() {}
template <typename T, typename... ArgTypes>
void print(T t, ArgTypes... args) {
  cout << t;
  print(args...);
}
template <typename T, typename... ArgTypes>
void input(T &t, ArgTypes &...args) {
  cin >> t;
  input(args...);
}
vvi segs;
int query(int l, int r) {
  vi all;
  for (int i = l; i <= r; i++)
    for (auto x : segs[i]) all.push_back(x);
  cout << "? " << all.size();
  for (auto x : all) cout << " " << x;
  cout << endl;
  int res;
  cin >> res;
  return res;
}
inline void _() {
  int n, k;
  cin >> n >> k;
  segs = vvi(k, vi());
  for (int i = 0; i < k; i++) {
    int nn;
    cin >> nn;
    for (int j = 0; j < nn; j++) {
      int pos;
      cin >> pos;
      segs[i].push_back(pos);
    }
  }
  cout << "? " << n;
  for (int i = 1; i <= n; i++) cout << " " << i;
  cout << endl;
  int maxi;
  cin >> maxi;
  int l = 0, r = k - 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    int maxEle = query(l, mid);
    if (maxEle == maxi)
      r = mid;
    else
      l = mid + 1;
  }
  set<int> all;
  for (int j = 1; j <= n; j++) all.insert(j);
  for (auto x : segs[l]) all.erase(x);
  cout << "? " << all.size();
  for (auto x : all) cout << " " << x;
  cout << endl;
  int diff;
  cin >> diff;
  cout << "!";
  for (int i = 0; i < k; i++) {
    if (i == l)
      cout << " " << diff;
    else
      cout << " " << maxi;
  }
  cout << endl;
  string correctness;
  cin >> correctness;
  if (correctness == "Correct") return;
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(0);
  int __;
  cin >> __;
  while (__--) _();
}
