#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX;
const long long SZ = 1007;
const long long mod = 1e9 + 7;
long long i, j, k, q, n, t, m, first, second, ans, cnt, a[SZ];
vector<long long> adj[SZ];
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (int i = 1; i <= k; i++) {
      cin >> m;
      adj[i].clear();
      for (int j = 0; j < m; j++) {
        cin >> first;
        adj[i].push_back(first);
      }
    }
    cout << "? ";
    cout << n << " ";
    for (int i = 1; i <= n; i++) cout << i << " ";
    cout << "\n";
    long long mx;
    cin >> mx;
    long long lo = 1, hi = n, mid = 0;
    while (hi - lo > 0) {
      mid = (lo + hi) / 2;
      cout << "? ";
      cout << mid - lo + 1 << " ";
      for (i = lo; i <= mid; i++) cout << i << " ";
      cout << "\n";
      cin >> first;
      if (first == mx)
        hi = mid;
      else
        lo = mid + 1;
    }
    mid = lo;
    vector<long long> v;
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= k; i++) {
      long long m = adj[i].size(), f = 0;
      for (int j = 0; j < m; j++)
        if (adj[i][j] == mid) f = 1;
      if (!f)
        v.push_back(mx);
      else {
        for (int j = 0; j < m; j++) a[adj[i][j]] = 1;
        cout << "? ";
        cout << n - m << " ";
        for (j = 1; j <= n; j++)
          if (!a[j]) cout << j << " ";
        cout << "\n";
        cin >> first;
        v.push_back(first);
      }
    }
    cout << "!"
         << " ";
    for (auto first : v) cout << first << " ";
    cout << "\n";
    string s;
    cin >> s;
  }
  return 0;
}
