#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int T, x[maxn], y[maxn], a[maxn], b[maxn], r[maxn], cnt, bel[maxn], n;
char s[maxn];
vector<int> col[3];
void query(int cnt) {
  if (!cnt) return;
  printf("Q %d ", cnt);
  for (int i = (1); i <= (cnt); ++i) printf("%d %d ", x[i], y[i]);
  puts("");
  fflush(stdout);
  scanf("%s", s + 1);
  for (int i = (1); i <= (cnt); ++i) a[x[i]] = s[i] ^ 48;
}
void ask(int cnt) {
  if (!cnt) return;
  printf("Q %d ", cnt);
  for (int i = (1); i <= (cnt); ++i) printf("%d %d ", r[x[i]], r[y[i]]);
  puts("");
  fflush(stdout);
  scanf("%s", s + 1);
  for (int i = (1); i <= (cnt); ++i) a[y[i]] = s[i] ^ 48;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    int tot = 0;
    cnt = 0;
    for (int i = (1); i <= (n - 1); ++i)
      if (i & 1) x[++tot] = i, y[tot] = i + 1;
    query(tot);
    tot = 0;
    for (int i = (3); i <= (n); ++i)
      if (i & 1) x[++tot] = i - 1, y[tot] = i;
    query(tot);
    tot = 0;
    for (int i = (1); i <= (n - 1); ++i)
      if (!a[i]) r[++cnt] = i;
    r[++cnt] = n;
    for (int i = (1); i <= (cnt - 2); ++i)
      if (i % 4 == 1 || i % 4 == 2) x[++tot] = i, y[tot] = i + 2;
    ask(tot);
    tot = 0;
    for (int i = (5); i <= (cnt); ++i)
      if (i % 4 == 1 || i % 4 == 2) x[++tot] = i - 2, y[tot] = i;
    ask(tot);
    bel[1] = 0;
    if (cnt > 1) bel[2] = 1;
    for (int i = (3); i <= (cnt); ++i)
      bel[i] = a[i] ? bel[i - 2] : (3 - bel[i - 2] - bel[i - 1]);
    for (int i = (0); i <= (2); ++i) col[i].clear();
    for (int i = (1); i <= (cnt); ++i)
      for (int j = (r[i - 1] + 1); j <= (r[i]); ++j) col[bel[i]].push_back(j);
    printf("A %d %d %d\n", (int)col[0].size(), (int)col[1].size(),
           (int)col[2].size());
    for (int i = (0); i <= (2); ++i) {
      for (int x : col[i]) printf("%d ", x);
      puts("");
    }
    fflush(stdout);
  }
  return 0;
}
