#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int ans = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) ans = (ans << 3) + (ans << 1) + (c ^ 48);
  return ans * f;
}
inline int cmin(int &a, int b) { return a = min(a, b); }
inline int cmax(int &a, int b) { return a = max(a, b); }
int n, k;
int s[1005][1005];
int tag[1005];
int ans[1005];
int main() {
  int T = read();
  while (T--) {
    n = read(), k = read();
    for (int i = 1; i <= k; i++) {
      s[i][0] = read();
      for (int j = 1; j <= s[i][0]; j++) s[i][j] = read();
    }
    cout << "? " << n << " ";
    for (int i = 1; i <= n; i++) cout << i << ' ';
    cout << flush << endl;
    int maxx = read();
    int l = 1, r = n;
    while (l < r) {
      int mid = l + r >> 1;
      cout << "? " << mid - l + 1 << ' ';
      for (int i = l; i <= mid; i++) cout << i << ' ';
      cout << flush << endl;
      int tmp = read();
      if (tmp == maxx)
        r = mid;
      else
        l = mid + 1;
    }
    for (int i = 1; i <= k; i++) {
      int flag = 0;
      for (int j = 1; j <= s[i][0]; j++)
        if (s[i][j] == l) flag = 1;
      if (flag) {
        cout << "? " << n - s[i][0] << ' ';
        for (int j = 1; j <= n; j++) tag[j] = 0;
        for (int j = 1; j <= s[i][0]; j++) tag[s[i][j]] = 1;
        for (int j = 1; j <= n; j++)
          if (!tag[j]) cout << j << ' ';
        cout << flush << endl;
        ans[i] = read();
      } else
        ans[i] = maxx;
    }
    cout << "! ";
    for (int i = 1; i <= k; i++) cout << ans[i] << ' ';
    cout << flush << endl;
    string ret;
    cin >> ret;
    if (ret[0] == 'I') break;
  }
  return 0;
}
