#include <bits/stdc++.h>
using namespace std;
int t, n;
vector<int> v[2];
void add(int x, int pos) {
  char ans;
  bool f = false;
  int j;
  for (j = v[pos].size() - 1; j >= 0; --j) {
    cout << "? " << x << " " << v[pos][j] << "\n";
    cin >> ans;
    if (ans == '<') {
      f = true;
      break;
    }
  }
  if (f == true)
    v[pos].insert(v[pos].begin() + j + 1, x);
  else
    v[pos].insert(v[pos].begin(), x);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> t;
  while (t--) {
    cin >> n;
    char ans;
    for (int i = 1; i < n; ++i) add(i, 0);
    add(n, 1);
    add(n + 1, 1);
    for (int i = n + 2; i <= 2 * n; ++i) {
      cout << "? " << v[0][n - 2] << " " << v[1][1] << "\n";
      cin >> ans;
      if (ans == '>') {
        v[1].pop_back();
        add(i, 1);
      } else {
        v[0].pop_back();
        add(i, 0);
      }
    }
    cout << "? " << v[0][n - 2] << " " << v[1][1] << "\n";
    cin >> ans;
    cout << "!\n";
    v[0].clear();
    v[1].clear();
  }
  return 0;
}
