#include <bits/stdc++.h>
using namespace std;
const int N = 100003;
char s[N];
int f[N], ind[N], arr[N];
inline int find(int x) {
  int r = x, y;
  while (f[r] != r) r = f[r];
  while (x != r) y = f[x], f[x] = r, x = y;
  return r;
}
bool vis[N], pre[N];
int out[N], col[N];
vector<int> rgb[3];
int main() {
  int T, n, i, cntNode, len;
  col[1] = 0, col[2] = 1;
  for (scanf("%d", &T); T; --T) {
    scanf("%d", &n), cntNode = 0;
    for (i = 1; i <= n; ++i) f[i] = i, ind[i] = 0;
    len = n >> 1;
    if (len) {
      printf("Q %d", len);
      for (i = 1; i < n; i += 2) printf(" %d %d", i, i + 1);
      putchar('\n'), fflush(stdout), scanf("%s", s + 1);
      for (i = 1; i <= len; ++i)
        if (s[i] == '1') f[find((i << 1) - 1)] = find(i << 1);
    }
    len = (n - 1) >> 1;
    if (len) {
      printf("Q %d", len);
      for (i = 2; i < n; i += 2) printf(" %d %d", i, i + 1);
      putchar('\n'), fflush(stdout), scanf("%s", s + 1);
      for (i = 1; i <= len; ++i)
        if (s[i] == '1') f[find(i << 1)] = find(i << 1 | 1);
    }
    for (i = 1; i <= n; ++i)
      if (!ind[find(i)]) ind[f[i]] = ++cntNode, arr[cntNode] = f[i];
    if (cntNode > 2) {
      memset(vis + 1, 0, sizeof(bool) * cntNode), len = 0;
      for (i = 3; i <= cntNode; ++i)
        if (!vis[i - 2]) out[++len] = i, vis[i] = 1;
      if (len) {
        printf("Q %d", len);
        for (i = 1; i <= len; ++i)
          printf(" %d %d", arr[out[i] - 2], arr[out[i]]);
        putchar('\n'), fflush(stdout), scanf("%s", s + 1);
        for (i = 1; i <= len; ++i) pre[out[i]] = s[i] == '1';
      }
      memset(vis + 1, 0, sizeof(bool) * cntNode), len = 0;
      for (i = 5; i <= cntNode; ++i)
        if (!vis[i - 2]) out[++len] = i, vis[i] = 1;
      if (len) {
        printf("Q %d", len);
        for (i = 1; i <= len; ++i)
          printf(" %d %d", arr[out[i] - 2], arr[out[i]]);
        putchar('\n'), fflush(stdout), scanf("%s", s + 1);
        for (i = 1; i <= len; ++i) pre[out[i]] = s[i] == '1';
      }
      for (i = 3; i <= cntNode; ++i)
        col[i] = pre[i] ? col[i - 2] : 3 - col[i - 2] - col[i - 1];
    }
    for (i = 0; i < 3; ++i) rgb[i].clear();
    for (i = 1; i <= n; ++i) rgb[col[ind[find(i)]]].push_back(i);
    printf("A %d %d %d\n", rgb[0].size(), rgb[1].size(), rgb[2].size());
    for (i = 0; i < 3; ++i) {
      for (auto x : rgb[i]) printf("%d ", x);
      putchar('\n');
    }
    fflush(stdout);
  }
  return 0;
}
