#include <bits/stdc++.h>
using namespace std;
int n, k;
int c;
vector<vector<int> > a;
string s;
vector<bool> flag;
int query(int x, int y, int ex = -1) {
  int cnt = 0;
  int v;
  for (int i = x; i <= y; ++i) {
    if (i == ex) continue;
    cnt += a[i].size();
  }
  cout << "? " << cnt;
  for (int i = x; i <= y; ++i) {
    if (i == ex) continue;
    for (int v : a[i]) {
      cout << " " << v;
    }
  }
  cout << endl;
  cout.flush();
  cin >> v;
  return v;
}
void solve() {
  cin >> n >> k;
  flag.clear();
  flag.resize(n + 1);
  a.clear();
  a.resize(k);
  int cnt = 0;
  for (int i = 0; i < k; ++i) {
    cin >> c;
    cnt += c;
    a[i].resize(c);
    for (int j = 0; j < c; ++j) {
      cin >> a[i][j];
      flag[a[i][j]] = true;
    }
  }
  if (cnt < n) {
    a.push_back(vector<int>());
    for (int i = 1; i <= n; ++i) {
      if (!flag[i]) {
        a.back().push_back(i);
      }
    }
  }
  int m = query(0, a.size() - 1);
  int l = 0;
  int r = a.size() - 1;
  int mid;
  int m1;
  while (l < r) {
    mid = (l + r) / 2;
    m1 = query(l, mid);
    if (m1 < m) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  if (r == k) {
    cout << "!";
    for (int i = 0; i < k; ++i) {
      cout << " " << m;
    }
    cout << endl;
    cout.flush();
    cin >> s;
  } else {
    m1 = query(0, a.size() - 1, r);
    cout << "!";
    for (int i = 0; i < k; ++i) {
      if (i == r) {
        cout << " " << m1;
      } else {
        cout << " " << m;
      }
    }
    cout << endl;
    cout.flush();
    cin >> s;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
