#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int ans[N], mark[N];
vector<int> S[N];
int get(int x) {
  cout << "? " << x;
  for (int i = 1; i <= x; i++) cout << " " << i;
  cout << endl;
  int res;
  cin >> res;
  return res;
}
void Main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int s;
    cin >> s, S[i].resize(s);
    for (int j = 0; j < s; j++) cin >> S[i][j];
  }
  int mx = get(n);
  int dw = 0, up = n;
  while (up - dw > 1) {
    int mid = (up + dw) >> 1;
    if (get(mid) == mx)
      up = mid;
    else
      dw = mid;
  }
  int id = 0;
  for (int i = 1; i <= k; i++) {
    for (int j : S[i])
      if (j == up) id = i;
  }
  for (int i = 1; i <= k; i++)
    if (i != id) ans[i] = mx;
  if (id) {
    fill(mark, mark + n + 1, 0);
    for (int i : S[id]) mark[i] = 1;
    vector<int> vec;
    for (int i = 1; i <= n; i++)
      if (!mark[i]) vec.push_back(i);
    cout << "? " << vec.size();
    for (int i : vec) cout << " " << i;
    cout << endl;
    cin >> ans[id];
  }
  cout << '!';
  for (int i = 1; i <= k; i++) cout << " " << ans[i];
  cout << endl;
  string junk;
  cin >> junk;
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) Main();
  return 0;
}
