#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
const long long MOD = 998244353;
const long long MAX = 4000001;
const double eps = 1E-18;
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  }
  return b;
}
long long min(long long a, long long b) {
  if (a > b) {
    return b;
  }
  return a;
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  if (a < b) {
    return gcd(b, a);
  }
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
struct edge {
  long long ind;
  long long fr;
  long long to;
  long long d;
};
class mint {
  long long x;

 public:
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint& a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint& a) { return (*this) *= a.inv(); }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res /= a;
  }
  friend ostream& operator<<(ostream& os, const mint& m) {
    os << m.x;
    return os;
  }
};
mint pw(mint a, long long b) {
  if (b == 0) {
    return 1;
  }
  mint ret = pw(a, b >> 1);
  ret *= ret;
  if (b & 1) {
    ret *= a;
  }
  return ret;
}
int main() {
  long long T;
  cin >> T;
  for (long long t = 1; t <= T; t++) {
    long long N, K;
    cin >> N >> K;
    vector<vector<long long>> S(K);
    for (long long i = 0; i < K; i++) {
      long long c;
      cin >> c;
      for (long long j = 1; j <= c; j++) {
        long long y;
        cin >> y;
        S[i].push_back(y);
      }
    }
    cout << '?';
    cout << " " << N;
    for (long long i = 1; i <= N; i++) cout << " " << i;
    cout << endl << flush;
    long long mx;
    cin >> mx;
    if (mx == -1) {
      return 0;
    }
    long long b = 0;
    for (long long i = 1; i <= 10; i++) {
      vector<long long> test;
      long long c = 0;
      for (long long j = 0; j < K; j++) {
        if (j % (1 << i) == b) {
          test.push_back(j);
          c += S[j].size();
        }
      }
      if (c == 0) {
        continue;
      }
      cout << '?';
      cout << " " << c;
      for (long long j = 0; j < test.size(); j++) {
        long long y = test[j];
        for (long long l = 0; l < S[y].size(); l++) {
          cout << " " << S[y][l];
        }
      }
      cout << endl << flush;
      long long x;
      cin >> x;
      if (x == -1) {
        return 0;
      }
      if (x != mx) {
        b += (1 << (i - 1));
      }
    }
    long long x = mx;
    if (b < K) {
      cout << '?';
      cout << " " << N - S[b].size();
      vector<bool> sb(N + 1, 0);
      for (long long j = 0; j < S[b].size(); j++) {
        sb[S[b][j]] = 1;
      }
      for (long long i = 1; i <= N; i++) {
        if (sb[i] == 0) {
          cout << " " << i;
        }
      }
      cout << endl << flush;
      cin >> x;
      if (x == -1) {
        return 0;
      }
    }
    cout << "!";
    for (long long i = 0; i < K; i++) {
      if (b != i) {
        cout << " " << mx;
      } else {
        cout << " " << x;
      }
    }
    cout << endl << flush;
    string res;
    cin >> res;
    if (res == "Incorrect") {
      return 0;
    }
  }
}
