#include <bits/stdc++.h>
using namespace std;
int query(vector<int>& indices, vector<int>& bound, int l, int r) {
  cout << "? " << bound[r] - bound[l];
  for (int i = bound[l]; i < bound[r]; i++) {
    cout << ' ' << indices[i];
  }
  cout << endl;
  cout.flush();
  int res;
  cin >> res;
  return res;
}
int query_except(vector<int>& indices, vector<int>& bound, int l) {
  cout << "? " << bound.back() - bound.front() - (bound[l + 1] - bound[l]);
  for (int i = bound.front(); i < bound[l]; i++) {
    cout << ' ' << indices[i];
  }
  for (int i = bound[l + 1]; i < bound.back(); i++) {
    cout << ' ' << indices[i];
  }
  cout << endl;
  cout.flush();
  int res;
  cin >> res;
  return res;
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> indices, bound(k + 2, 0);
  vector<bool> selected(n + 1, false);
  for (int i = 0; i < k; i++) {
    int c;
    cin >> c;
    for (int j = 0; j < c; j++) {
      int idx;
      cin >> idx;
      indices.push_back(idx);
      selected[idx] = true;
    }
    bound[i + 1] = indices.size();
  }
  for (int i = 1; i <= n; i++) {
    if (!selected[i]) indices.push_back(i);
  }
  bound.back() = indices.size();
  vector<int> password(k, -1);
  int l = 0, r = k, allMax = query(indices, bound, 0, k + 1);
  while (r - l > 1) {
    int m = l + (r - l) / 2;
    int leftMax = query(indices, bound, l, m);
    if (leftMax < allMax) {
      for (int i = l; i < m; i++) {
        password[i] = allMax;
      }
      l = m;
    } else {
      for (int i = m; i < r; i++) {
        password[i] = allMax;
      }
      r = m;
    }
  }
  password[l] = query_except(indices, bound, l);
  cout << '!';
  for (int i = 0; i < k; i++) {
    cout << ' ' << password[i];
  }
  cout << endl;
  string result;
  cin >> result;
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
