#include <bits/stdc++.h>
using namespace std;
const int N = 210;
bool seen[N][N], ans[N][N];
vector<pair<int, int> > pairs;
void sort_pairs();
bool query_less(int i, int j);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    memset(seen, 0, sizeof(seen));
    int n;
    cin >> n;
    pairs.resize(n);
    for (int i = 1; i <= n; ++i) {
      pairs[i - 1] = {i, i + n};
      if (query_less(i + n, i)) {
        pairs[i - 1] = {i + n, i};
      }
    }
    int cnt = 2 * n;
    while (cnt >= n + 2) {
      int sz = pairs.size();
      sort_pairs();
      if (query_less(pairs[sz - 2].first, pairs[sz - 1].second))
        pairs[sz - 2].first = pairs[sz - 1].second;
      pairs.pop_back();
      if (query_less(pairs[sz - 2].second, pairs[sz - 2].first)) {
        swap(pairs[sz - 2].first, pairs[sz - 2].second);
      }
      cnt -= 2;
    }
    if (cnt == n + 1) {
      sort_pairs();
    }
    cout << "!" << endl;
  }
}
void sort_pairs() {
  int sz = pairs.size();
  for (int i = 0; i < sz - 1; ++i) {
    for (int j = 0; j < sz - 1; ++j) {
      if (!query_less(pairs[j + 1].first, pairs[j].first)) {
        swap(pairs[j], pairs[j + 1]);
      }
    }
  }
}
bool query_less(int i, int j) {
  if (!seen[i][j]) {
    seen[i][j] = seen[j][i] = true;
    cout << "? " << i << ' ' << j << endl;
    char c;
    cin >> c;
    ans[i][j] = (c == '<');
    ans[j][i] = !ans[i][j];
  }
  return ans[i][j];
}
