#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long long;
using pii = pair<int, int>;
using vvi = vector<vector<int>>;
using vi = vector<int>;
using vl = vector<ll>;
using pll = pair<ll, ll>;
using vsi = vector<set<int>>;
int query(int l, int r) {
  int c = r - l + 1;
  cout << '?' << ' ' << c << ' ' << flush;
  for (int i = l; i < r + 1; i++) cout << i << ' ' << flush;
  cout << endl << flush;
  int ma;
  cin >> ma;
  return ma;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vsi subs(k);
    for (int i = 0; i < k; i++) {
      int tz;
      cin >> tz;
      for (int j = 0; j < tz; j++) {
        int temp;
        cin >> temp;
        subs[i].insert(temp);
      }
    }
    int ma = query(1, n);
    int l = 1;
    int r = n;
    while (l != r) {
      int mid = (l + r) / 2;
      int tp = query(l, mid);
      if (tp == ma)
        r = mid;
      else
        l = mid + 1;
    }
    int ind = -1;
    for (int i = 0; i < k; i++) {
      if (subs[i].count(l)) {
        ind = i;
        break;
      }
    }
    if (ind == -1) {
      cout << '!' << ' ' << flush;
      for (int i = 0; i < k; i++) cout << ma << ' ' << flush;
      cout << endl << flush;
    } else {
      vi tq;
      for (int i = 1; i < n + 1; i++) {
        if (!subs[ind].count(i)) tq.push_back(i);
      }
      cout << '?' << ' ' << tq.size() << ' ' << flush;
      for (int i = 0; i < tq.size(); i++) cout << tq[i] << ' ' << flush;
      int m2;
      cin >> m2;
      cout << '!' << ' ' << flush;
      for (int i = 0; i < k; i++) {
        if (ind == i)
          cout << m2 << ' ' << flush;
        else
          cout << ma << ' ' << flush;
      }
      cout << endl << flush;
    }
    string temp;
    cin >> temp;
    if (temp != "Correct") break;
  }
}
