#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
int a[N], belong[N];
char s[4][N >> 1];
int c[2][N], num[2];
void query(int *a, int n, char *s1, char *s2) {
  if (n < 2) return;
  printf("Q %d", n >> 1);
  for (int i = 1; i < n; i += 2) printf(" %d %d", a[i], a[i + 1]);
  putchar('\n');
  fflush(stdout);
  scanf("%s", s1 + 1);
  if (n < 3) return;
  printf("Q %d", (n - 1) >> 1);
  for (int i = 2; i < n; i += 2) printf(" %d %d", a[i], a[i + 1]);
  putchar('\n');
  fflush(stdout);
  scanf("%s", s2 + 1);
}
void print() {
  int cnt[3] = {};
  for (int i = 1; i <= n; ++i) ++cnt[a[i]];
  printf("A %d %d %d\n", cnt[0], cnt[1], cnt[2]);
  for (int i = 0; i < 3; ++i) {
    for (int j = 1; j <= n; ++j)
      if (a[j] == i) printf("%d ", j);
    putchar('\n');
  }
  fflush(stdout);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    if (n == -1) return 0;
    for (int i = 1; i <= n; ++i) a[i] = i;
    query(a, n, s[0], s[1]);
    a[0] = -1;
    a[1] = 0;
    for (int i = 2; i <= n; ++i)
      a[i] = s[i & 1][i >> 1] == '1' ? a[i - 1] : a[i - 1] ^ 1;
    num[0] = num[1] = 0;
    for (int i = 1; i <= n; ++i) {
      if (a[i] != a[i - 1]) {
        c[a[i]][++num[a[i]]] = i;
        belong[i] = i;
      } else
        belong[i] = belong[i - 1];
    }
    assert(num[0] == num[1] || num[0] == num[1] + 1);
    for (int i = 0; i < 2; ++i) query(c[i], num[i], s[i << 1], s[i << 1 | 1]);
    for (int i = 2; i <= num[0]; ++i)
      for (int j = 0; j < 2; ++j)
        if (i <= num[j])
          a[c[j][i]] =
              s[j << 1 | i & 1][i >> 1] == '1'
                  ? a[c[j][i - 1]]
                  : 3 - a[c[j][i - 1]] - (j ? a[c[0][i]] : a[c[1][i - 1]]);
    for (int i = 1; i <= n; ++i) a[i] = a[belong[i]];
    print();
  }
  return 0;
}
