#include <bits/stdc++.h>
using namespace std;
int order[9] = {0, 1, 5, 3, 4, 2, 6, 7, 8};
int A, B;
string read() {
  if (false) {
    if (order[A] > order[B])
      return ">";
    else
      return "<";
  } else {
    string s;
    cin >> s;
    return s;
  }
}
void output(int a, int b) {
  if (false) {
    A = a;
    B = b;
  }
  cout << "? " << a << " " << b << endl;
  cout.flush();
}
int n;
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> goods, bads;
    for (int i = 1; i <= 2 * n; i += 2) {
      output(i, i + 1);
      string s = read();
      if (s[0] == '>') {
        goods.push_back(i);
        bads.push_back(i + 1);
      } else {
        goods.push_back(i + 1);
        bads.push_back(i);
      }
    }
    for (int i = 1; i < n; i++) {
      for (int j = n - 1; j >= i; j--) {
        output(bads[j - 1], bads[j]);
        string s = read();
        if (s[0] == '>') {
          swap(bads[j - 1], bads[j]);
        }
      }
    }
    int very_good = bads[n - 1] % 2 == 0 ? bads[n - 1] - 1 : bads[n - 1] + 1;
    swap(goods[n - 1], goods[(very_good - 1) / 2]);
    for (int i = 1; i < n - 1; i++) {
      for (int j = n - 2; j >= i; j--) {
        output(goods[j - 1], goods[j]);
        string s = read();
        if (s[0] == '>') {
          swap(goods[j - 1], goods[j]);
        }
      }
    }
    int i = n / 2, j = 0;
    while (i + j < n) {
      output(goods[j], bads[i]);
      string s = read();
      if (s[0] == '>') {
        i++;
      } else {
        j++;
      }
    }
    cout << "!" << endl;
    cout.flush();
  }
  return 0;
}
