#include <bits/stdc++.h>
#pragma optimize("O3")
using namespace std;
const long long MOD = 998244353;
const long long INF = 1e12 + 7;
const int base = 2e5 + 1;
const int MAX = 1e5 + 2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 2 * 1e6 + 47;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<set<int>> s(k);
    for (long long i = (0); i < (k); ++i) {
      int m;
      cin >> m;
      for (long long j = (0); j < (m); ++j) {
        int x;
        cin >> x;
        s[i].insert(x);
      }
    }
    int mx, mx2;
    cout << "? " << n << ' ';
    for (long long i = (1); i < (n + 1); ++i) cout << i << ' ';
    cout << '\n';
    cin >> mx;
    int l = 1, r = n;
    while (l < r) {
      int m = (l + r) / 2;
      cout << "? " << (m - l + 1) << ' ';
      for (long long i = (l); i < (m + 1); ++i) cout << i << ' ';
      cout << '\n';
      int c;
      cin >> c;
      if (c == mx)
        r = m;
      else
        l = m + 1;
    }
    int x = -1;
    for (long long i = (0); i < (k); ++i) {
      if (s[i].count(l)) x = i;
    }
    if (x != -1) {
      cout << "? " << n - (int)s[x].size() << ' ';
      for (long long i = (1); i < (n + 1); ++i) {
        if (!s[x].count(i)) cout << i << ' ';
      }
      cout << '\n';
      cin >> mx2;
    }
    cout << "! ";
    for (long long i = (0); i < (k); ++i) {
      if (i != x)
        cout << mx << ' ';
      else
        cout << mx2 << ' ';
    }
    cout << '\n';
    string g;
    cin >> g;
  }
  return 0;
}
