#include <bits/stdc++.h>
int main() {
  int tests;
  std::cin >> tests;
  for (int t = 0; t < tests; ++t) {
    int n, k;
    std::cin >> n >> k;
    std::vector<std::vector<int>> sets(k);
    for (int i = 0; i < k; ++i) {
      int c;
      std::cin >> c;
      sets[i].resize(c);
      for (int& j : sets[i]) std::cin >> j;
    }
    std::cout << "? " << n;
    for (int i = 1; i <= n; ++i) std::cout << ' ' << i;
    std::cout << std::endl;
    int max;
    std::cin >> max;
    int i = 0;
    if (k > 1) {
      int s = (k + 1) / 2;
      do {
        int c = 0;
        for (int j = 0; j < s; ++j) c += sets[i + j].size();
        std::cout << "? " << c;
        for (int j = 0; j < s; ++j)
          for (int h : sets[i + j]) std::cout << ' ' << h;
        std::cout << std::endl;
        int x;
        std::cin >> x;
        if (x != max) i += s;
        if (s == 1) break;
        s = (s + 1) / 2;
        s = std::min(s, k - i);
      } while (true);
    }
    int max2;
    if (i < k) {
      std::cout << "? " << n - sets[i].size();
      std::vector<bool> used(n + 1, true);
      for (int j : sets[i]) used[j] = false;
      for (int j = 1; j <= n; ++j)
        if (used[j]) std::cout << ' ' << j;
      std::cout << std::endl;
      std::cin >> max2;
    } else {
      max2 = max;
    }
    std::cout << "! ";
    for (int j = 0; j < k; ++j)
      if (i == j)
        std::cout << max2 << ' ';
      else
        std::cout << max << ' ';
    std::cout << std::endl;
    std::string answer;
    std::cin >> answer;
  }
  return 0;
}
