#include <bits/stdc++.h>
using namespace std;
int binary_search(int l, int r, int &max) {
  if (l >= r)
    return l;
  else {
    int m = (l + r) / 2;
    cout << "? " << m - l + 1;
    for (size_t i = l; i <= m; i++) cout << " " << i;
    cout << endl;
    cout.flush();
    int res;
    cin >> res;
    if (res == -1)
      return -1;
    else {
      if (res == max)
        return binary_search(l, m, max);
      else
        return binary_search(m + 1, r, max);
    }
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> S(k, vector<int>(n + 1, 0));
    for (size_t i = 0; i < k; i++) {
      int s;
      cin >> s;
      int idx;
      S[i][0] = s;
      for (size_t j = 0; j < s; j++) {
        cin >> idx;
        S[i][idx] = 1;
      }
    }
    cout << "? " << n;
    for (size_t i = 1; i <= n; i++) cout << " " << i;
    cout << endl;
    cout.flush();
    int max;
    cin >> max;
    if (max == -1) return -1;
    int idx_max = binary_search(1, n, max);
    if (idx_max == -1) return -1;
    vector<int> password(k);
    for (size_t i = 0; i < k; i++) {
      if (S[i][idx_max] == 0)
        password[i] = max;
      else {
        cout << "? " << n - S[i][0];
        for (size_t j = 1; j <= n; j++) {
          if (S[i][j] == 0) cout << " " << j;
        }
        cout << endl;
        cout.flush();
        cin >> password[i];
        if (password[i] == -1) return -1;
      }
    }
    cout << "!";
    for (size_t i = 0; i < k; i++) cout << " " << password[i];
    cout << endl;
    cout.flush();
    string report;
    cin >> report;
    if (report == string("Incorrect")) return -1;
  }
  return 0;
}
