#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    vector<int> st[k];
    for (int i = 0; i < k; ++i) {
      int c;
      cin >> c;
      while (c--) {
        int x;
        cin >> x;
        st[i].emplace_back(x);
      }
    }
    cout << "? " << n << " ";
    for (int i = 1; i <= n; ++i) {
      cout << i << ' ';
    }
    cout << endl;
    int mx1;
    cin >> mx1;
    int low = 1, high = n;
    while (low < high) {
      int mid = (low + high) >> 1;
      cout << "? " << (mid - low + 1) << " ";
      for (int i = low; i <= mid; ++i) {
        cout << i << ' ';
      }
      cout << endl;
      int val;
      cin >> val;
      if (val == mx1)
        high = mid;
      else
        low = mid + 1;
    }
    int excp, no = -1;
    for (int i = 0; i < k; ++i) {
      sort(st[i].begin(), st[i].end());
      if (binary_search(st[i].begin(), st[i].end(), low)) {
        cout << "? " << (n - (int)st[i].size()) << " ";
        for (int j = 1; j <= n; ++j) {
          if (!binary_search(st[i].begin(), st[i].end(), j)) cout << j << ' ';
        }
        cout << endl;
        cin >> excp;
        no = i;
        break;
      }
    }
    cout << "! ";
    for (int i = 0; i < k; ++i) {
      if (i == no)
        cout << excp << ' ';
      else
        cout << mx1 << ' ';
    }
    cout << endl;
    string s;
    cin >> s;
  }
}
