#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<int> s[k];
    for (int i = 0; i < k; ++i) {
      int c;
      cin >> c;
      for (int j = 0; j < c; ++j) {
        int p;
        cin >> p;
        s[i].push_back(p);
      }
    }
    cout << "? " << n << " ";
    for (int i = 1; i <= n; i++) cout << i << " ";
    cout << "\n";
    int max;
    cin >> max;
    int l = 1, r = n;
    while (l < r) {
      int mid = (l + r) / 2;
      cout << "? " << mid - l + 1 << " ";
      for (int i = l; i <= mid; i++) cout << i << " ";
      cout << "\n";
      int temp;
      cin >> temp;
      if (temp == max)
        r = mid;
      else
        l = mid + 1;
    }
    int sind = 0;
    for (int i = 0; i < k; ++i) {
      for (int j : s[i]) {
        if (j == l) {
          sind = i;
          break;
        }
      }
    }
    int smax;
    cout << "? " << n - s[sind].size() << " ";
    for (int i = 1; i <= n; i++) {
      bool flag = true;
      for (int j : s[sind])
        if (j == i) flag = false;
      if (flag) cout << i << " ";
    }
    cout << "\n";
    cin >> smax;
    cout << "! ";
    for (int i = 0; i < k; i++) {
      if (i == sind)
        cout << smax << " ";
      else
        cout << max << " ";
    }
    cout << "\n";
    string x;
    cin >> x;
  }
}
