#include <bits/stdc++.h>
using namespace std;
const int max_n = 100011, inf = 1000111222;
const long long inff = 1000111222333444;
const int mod = 998244353;
struct dsu {
  int p[max_n], sz[max_n], used[max_n];
  dsu() {
    for (int i = 0; i < max_n; ++i) {
      p[i] = i;
      sz[i] = 1;
      used[i] = 0;
    }
  }
  int find_set(int x) {
    if (p[x] == x) return x;
    return p[x] = find_set(p[x]);
  }
  void union_set(int x, int y) {
    x = find_set(x);
    y = find_set(y);
    if (x == y) return;
    if (sz[x] > sz[y]) swap(x, y);
    p[x] = y;
    sz[y] += sz[x];
  }
};
int t;
int n;
dsu d;
int nn;
int arr[max_n];
char s[max_n];
void print_ans() {
  vector<int> v[3];
  v[0] = v[1] = v[2] = vector<int>();
  v[0].push_back(0);
  pair<int, int> f, g, last;
  f = g = {-1, -1};
  last = {0, 0};
  for (int i = 1; i < n; ++i) {
    if (d.find_set(i) == d.find_set(last.second)) {
      v[last.first].push_back(i);
      continue;
    }
    g = f;
    f = last;
    if (g.first == -1) {
      last = {last.first + 1, i};
    } else if (d.find_set(g.second) == d.find_set(i)) {
      last = {g.first, i};
    } else {
      last = {3 - g.first - f.first, i};
    }
    v[last.first].push_back(i);
  }
  cout << "A " << v[0].size() << " " << v[1].size() << " " << v[2].size()
       << endl;
  for (int i = 0; i < 3; ++i) {
    for (int q = 0; q < v[i].size(); ++q) {
      printf("%d ", v[i][q] + 1);
    }
    cout << endl;
  }
  if (nn) {
    for (int i = 0; i < 3; ++i) {
      for (int q = 1; q < v[i].size(); ++q) {
        assert(arr[v[i][q]] == arr[v[i][q - 1]]);
      }
      if (!v[(i + 1) % 3].empty() && !v[i].empty()) {
        assert(arr[v[(i + 1) % 3][0]] != arr[v[i][0]]);
      }
    }
  }
}
void pr(int x, int y) { printf("%d %d ", x + 1, y + 1); }
std::string get_res(const vector<pair<int, int> >& q) {
  if (q.empty()) return "";
  cout << "Q " << q.size() << " ";
  for (auto a : q) {
    pr(a.first, a.second);
  }
  cout << endl;
  if (nn) {
    string ans = "";
    for (auto a : q) {
      ans += (arr[a.first] == arr[a.second]) + '0';
    }
    cout << ans << endl;
    return ans;
  }
  scanf("%s", s);
  return s;
}
void op_q(const vector<pair<int, int> >& q) {
  std::string res = get_res(q);
  for (int i = 0; i < q.size(); ++i) {
    int x = res[i] - '0';
    if (x == 1) {
      d.union_set(q[i].first, q[i].second);
    }
  }
}
void solve() {
  d = dsu();
  vector<pair<int, int> > q1, q2, q3, q4;
  for (int i = 0; i < n; i += 2) {
    if (i + 1 < n) {
      q1.push_back({i, i + 1});
    }
    if (i + 2 < n) {
      q2.push_back({i + 1, i + 2});
    }
  }
  op_q(q1);
  op_q(q2);
  vector<int> aa;
  for (int i = 0; i < n; ++i) {
    if (d.find_set(i) == i) {
      aa.push_back(i);
    }
  }
  for (int i = 0; i < aa.size(); i += 4) {
    if (i + 2 < aa.size()) {
      q3.push_back({aa[i], aa[i + 2]});
    }
    if (i + 3 < aa.size()) {
      q3.push_back({aa[i + 1], aa[i + 3]});
    }
    if (i + 4 < aa.size()) {
      q4.push_back({aa[i + 2], aa[i + 4]});
    }
    if (i + 5 < aa.size()) {
      q4.push_back({aa[i + 3], aa[i + 5]});
    }
  }
  op_q(q3);
  op_q(q4);
  print_ans();
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    nn = 0;
    if (nn) {
      for (int i = 0; i < nn; ++i) {
        arr[i] = rand() % 3;
        cout << arr[i] << " ";
      }
      cout << endl;
    }
    solve();
  }
  return 0;
}
