#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const char SPACE = ' ', ENDL = '\n';
const int MODULO = 1e9 + 7;
void readd(ll& target, ll add) {
  target += add;
  target %= MODULO;
}
void remult(ll& target, ll mult) {
  target *= mult;
  target %= MODULO;
}
ll binpow(ll base, ll power) {
  if (0 == power) return 1;
  ll half = binpow(base, power >> 1);
  remult(half, half);
  if (power & 1) remult(half, base);
  return half;
}
template <typename T>
T read() {
  T value;
  cin >> value;
  return value;
}
int ri() { return read<int>(); }
ll rll() { return read<ll>(); }
string rs() { return read<string>(); }
template <typename T>
vector<T> rv(size_t size) {
  vector<T> a(size);
  for (size_t i = 0; i < size; ++i) {
    a[i] = read<T>();
  }
  return a;
}
bool yesNo(bool result, string yes = "YES", string no = "NO") {
  cout << (result ? yes : no) << ENDL;
  return result;
}
template <typename T>
void remin(T& target, T source) {
  target = min(target, source);
}
template <typename T>
void remax(T& target, T source) {
  target = max(target, source);
}
template <typename N, typename D>
N ceil_div(N numerator, D denominator) {
  return (numerator - 1) / denominator + 1;
}
ll for_pow(ll base, int power) {
  ll result = 1;
  for (int i = 0; i < power; ++i) result *= base;
  return result;
}
vector<string> split(string& s, string seps) {
  vector<string> parts;
  string part = "";
  auto add_part = [&]() {
    parts.push_back(part);
    part = "";
  };
  for (char ch : s) {
    if (string::npos != seps.find(ch)) {
      add_part();
    } else {
      part += ch;
    }
  }
  add_part();
  return parts;
}
ld sqrt_ld(ld value) { return sqrt(value); }
int get_bit(ll mask, int bit) { return (mask >> bit) & 1; }
void init_io() {
  string file_name = "";
  if (!file_name.empty()) {
    string input_file_name = file_name + ".in";
    freopen(input_file_name.c_str(), "rt", stdin);
    string output_file_name = file_name + ".out";
    freopen(output_file_name.c_str(), "wt", stdout);
  } else {
  }
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(10) << fixed;
}
void get_answer(int n) {
  n *= 2;
  int unknown = 0, lose = -1, win = 1;
  vector<vi> cmp(n, vi(n, unknown));
  vi wins(n, 0), matches(n, 0);
  auto ask = [&](int a, int b) {
    if (a == b) return;
    cout << "?" << SPACE << a + 1 << SPACE << b + 1 << endl;
    string res = rs();
    if ("<" == res) {
      swap(a, b);
    }
    for (int v = 0; v < n; ++v) {
      if (v == b) continue;
      bool better = (v == a || win == cmp[v][a]);
      if (better && cmp[v][b] == unknown) {
        cmp[v][b] = win;
        cmp[b][v] = lose;
        ++wins[v];
        ++matches[v];
      }
    }
    matches[b] = 0;
    for (int v = 0; v < n; ++v) {
      if (cmp[v][b] != unknown) ++matches[b];
    }
  };
  vector<bool> used(n, false);
  for (int v = 0; v < n; v += 2) {
    ask(v, v + 1);
  }
  int half = n / 2;
  while (true) {
    int cnt = 0;
    for (int wv : wins) {
      if (wv >= half) ++cnt;
    }
    if (half <= cnt) {
      break;
    }
    while (true) {
      int min_wins = n;
      for (int v = 0; v < n; ++v) {
        if (used[v]) continue;
        remin(min_wins, wins[v]);
      }
      std::priority_queue<ii, vii, greater<ii>> candidates;
      for (int v = 0; v < n; ++v) {
        if (used[v]) continue;
        if (wins[v] > min_wins) continue;
        int vm = matches[v];
        candidates.push({vm, v});
        if (candidates.size() > 3) {
          candidates.pop();
        }
      }
      assert(candidates.size() > 0);
      auto first = candidates.top().second;
      candidates.pop();
      if (candidates.empty()) {
        used[first] = true;
      } else {
        int second = candidates.top().second;
        candidates.pop();
        if (!candidates.empty()) {
          int third = candidates.top().second;
          candidates.pop();
          if (matches[third] == matches[second]) {
            swap(third, first);
          }
        }
        ask(first, second);
        break;
      }
    }
  }
}
void solve_test() {
  int n = ri();
  get_answer(n);
  cout << "!" << endl;
}
void solve() {
  int t = ri();
  while (t-- > 0) {
    solve_test();
  }
}
int main() {
  int tests = 1;
  while (tests-- > 0) {
    solve();
  }
  return 0;
}
