#include <bits/stdc++.h>
int dx4[] = {0, 0, -1, 1};
int dy4[] = {-1, 1, 0, 0};
bool valid(int r, int c, int x, int y) {
  if (x >= 1 && x <= r && y >= 1 && y <= c) return 1;
  return 0;
}
using namespace std;
int ar[200005];
int main() {
  cout.flush();
  int t;
  cin >> t;
  for (int cs = 1; cs <= t; cs++) {
    int n, k;
    cin >> n >> k;
    vector<int> v[k + 2];
    int p, q;
    for (int i = 0; i < k; i++) {
      cin >> p;
      for (int j = 0; j < p; j++) {
        cin >> q;
        v[i].push_back(q);
      }
    }
    int val, val1;
    cout << "? " << n << " ";
    for (int i = 1; i <= n; i++) cout << i << " ";
    cout << endl;
    cin >> val;
    int low = 0;
    int high = k - 1;
    int mid;
    int pos = 0, m;
    while (low < high) {
      mid = (low + high) / 2;
      vector<int> x;
      for (int i = 0; i <= mid; i++) {
        for (int j = 0; j < v[i].size(); j++) {
          x.push_back(v[i][j]);
        }
      }
      if (x.size()) {
        cout << "? " << x.size() << " ";
        for (int i = 0; i < x.size(); i++) cout << x[i] << " ";
        cout << endl;
        cin >> m;
      }
      if (m < val) {
        pos = mid + 1;
        low = mid + 1;
      } else
        high = mid;
    }
    vector<int> vec;
    for (int i = 0; i < v[pos].size(); i++) {
      ar[v[pos][i]]++;
    }
    for (int i = 1; i <= n; i++) {
      if (ar[i] == 0) vec.push_back(i);
    }
    if (vec.size()) {
      cout << "? " << vec.size() << " ";
      for (int i = 0; i < vec.size(); i++) cout << vec[i] << " ";
      cout << endl;
      cin >> val1;
    }
    cout << "! ";
    for (int i = 0; i < k; i++) {
      if (i == pos)
        cout << val1 << " ";
      else
        cout << val << " ";
    }
    cout << endl;
    string s;
    cin >> s;
    memset(ar, 0, sizeof(ar));
  }
  return 0;
}
