#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> q;
int ask(int i, int j) {
  if (q.count({i, j})) return q[{i, j}];
  int& res = q[{i, j}];
  cout << "? " << i + 1 << " " << j + 1 << endl;
  char c[10];
  cin >> c;
  return res = (c[0] == '>');
}
void solve() {
  q.clear();
  int n;
  cin >> n;
  vector<pair<int, int> > a;
  for (int i = 0; i < (int)(n); ++i) {
    int x = i * 2, y = i * 2 + 1;
    if (ask(x, y))
      a.emplace_back(x, y);
    else
      a.emplace_back(y, x);
  }
  sort((a).begin(), (a).end(), [](pair<int, int> x, pair<int, int> y) {
    return ask(x.second, y.second);
  });
  vector<int> t;
  for (int i = 0; i < (int)(n); ++i)
    if (i) {
      t.push_back(a[i].first);
      t.push_back(a[i].second);
    }
  sort((t).begin(), (t).end(), [](int x, int y) { return ask(x, y); });
  int pidor = a[0].second;
  for (int i = 0; i < (int)(t.size()); ++i)
    if (i) ask(t[i], pidor);
  cout << "!" << endl;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < (int)(t); ++i) solve();
  return 0;
}
