#include <bits/stdc++.h>
using namespace std;
const int N = 205;
int mem[N][N];
int asol[N];
bool query(int i, int j) {
  i = asol[i];
  j = asol[j];
  if (mem[i][j] != -1) return mem[i][j];
  if (i == j) return false;
  cout << "? " << i << " " << j << endl;
  char c;
  cin >> c;
  mem[i][j] = (c == '<');
  mem[j][i] = !mem[i][j];
  return mem[i][j];
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(mem, -1, sizeof mem);
    int n;
    cin >> n;
    for (int i = 1; i <= 2 * n; i++) asol[i] = i;
    shuffle(asol + 1, asol + 2 * n + 1, mt19937(23232));
    vector<int> worse;
    for (int i = 1; i < 2 * n; i += 2) {
      if (query(i, i + 1))
        worse.push_back(i);
      else
        worse.push_back(i + 1);
    }
    sort(worse.begin(), worse.end(), query);
    int xx = worse.back();
    worse.pop_back();
    int yy = worse.back();
    vector<int> choto, boro;
    for (int i = 1; i <= 2 * n; i++) {
      if (i == yy) continue;
      if (query(yy, i))
        boro.push_back(i);
      else
        choto.push_back(i);
    }
    if (boro.size() <= n) {
      sort(choto.begin(), choto.end(), query);
      cout << "!" << endl;
    } else {
      int xxpr = (xx % 2 ? xx + 1 : xx - 1);
      vector<int> worse;
      if (query(xx, xxpr))
        worse.push_back(xx);
      else
        worse.push_back(xxpr);
      int unpaired = -1;
      for (int x : boro) {
        if (x == xx || x == xxpr) continue;
        if (unpaired == -1)
          unpaired = x;
        else {
          if (query(unpaired, x))
            worse.push_back(unpaired);
          else
            worse.push_back(x);
          unpaired = -1;
        }
      }
      if (unpaired != -1) worse.push_back(unpaired);
      sort(worse.begin(), worse.end(), query);
      cout << "!" << endl;
    }
  }
}
