#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
map<pair<int, int>, int> same;
vector<pair<int, int> > q;
int x[N], y[N];
vector<int> ans[3];
int n, m;
char st[N];
void qry() {
  if (!q.size()) return;
  printf("Q %d ", (int)q.size());
  for (int i = (0); i < (q.size()); i++)
    printf(" %d %d ", q[i].first, q[i].second);
  puts(""), fflush(stdout);
  scanf("%s", st);
  for (int i = (0); i < (q.size()); i++) same[q[i]] = st[i] - '0';
}
void MAIN() {
  same.clear();
  scanf("%d", &n);
  q.clear();
  for (int i = 1; i + 1 <= n; i += 2) q.push_back(make_pair(i, i + 1));
  qry();
  q.clear();
  for (int i = 2; i + 1 <= n; i += 2) q.push_back(make_pair(i, i + 1));
  qry();
  m = 0;
  for (int i = (1); i <= (n); i++)
    if (!same[make_pair(i - 1, i)]) x[++m] = i;
  q.clear();
  for (int i = 1; i + 2 <= m; i += 4) q.push_back(make_pair(x[i], x[i + 2]));
  for (int i = 2; i + 2 <= m; i += 4) q.push_back(make_pair(x[i], x[i + 2]));
  qry();
  q.clear();
  for (int i = 3; i + 2 <= m; i += 4) q.push_back(make_pair(x[i], x[i + 2]));
  for (int i = 4; i + 2 <= m; i += 4) q.push_back(make_pair(x[i], x[i + 2]));
  qry();
  memset(y, -1, sizeof y);
  y[x[1]] = 0, (m >= 2 ? y[x[2]] = 1 : 0);
  for (int i = 3; i <= m; i++)
    if (same[make_pair(x[i - 2], x[i])])
      y[x[i]] = y[x[i - 2]];
    else
      y[x[i]] = 3 - y[x[i - 2]] - y[x[i - 1]];
  for (int i = (1); i <= (n); i++) {
    if (y[i] == -1) y[i] = y[i - 1];
    ans[y[i]].push_back(i);
  }
  printf("A %d %d %d\n", (int)ans[0].size(), (int)ans[1].size(),
         (int)ans[2].size());
  for (int t = (0); t < (3); t++) {
    for (auto x : ans[t]) printf("%d ", x);
    puts(""), ans[t].clear();
  }
  fflush(stdout);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) MAIN();
  return 0;
}
