#include <bits/stdc++.h>
using namespace std;
int ps[100010];
void init_set(int n) {
  for (int i = 0; i <= n; i++) ps[i] = i;
}
int find_set(int i) { return ps[i] == i ? i : ps[i] = find_set(ps[i]); }
bool is_same_set(int i, int j) { return find_set(i) == find_set(j); }
void unit_set(int i, int j) { ps[find_set(i)] = find_set(j); }
int k[4], color[100010];
char bts[100010];
void run_query(vector<int> &x, vector<int> &y) {
  printf("Q %d", (int)x.size());
  for (int i = 0; i < x.size(); i++) {
    printf(" %d %d", x[i], y[i]);
  }
  printf("\n");
  fflush(stdout);
  scanf("%s", bts);
  if (strcmp(bts, "-1") == 0) {
    exit(0);
  }
  for (int i = 0; i < x.size(); i++) {
    if (bts[i] == '1') {
      unit_set(x[i], y[i]);
    }
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    if (n == -1) return 0;
    if (n == 1) {
      printf("A 1 0 0\n");
      printf("1\n\n\n");
      fflush(stdout);
      continue;
    }
    init_set(n + 1);
    vector<int> x, y;
    for (int i = 1; i < n; i += 2) {
      x.push_back(i);
      y.push_back(i + 1);
    }
    run_query(x, y);
    if (n == 2) {
      if (is_same_set(1, 2)) {
        printf("A 2 0 0\n");
        printf("1 2\n");
        printf("\n");
        printf("\n");
      } else {
        printf("A 1 1 0\n");
        printf("1\n");
        printf("2\n");
        printf("\n");
      }
      fflush(stdout);
      continue;
    }
    x.clear();
    y.clear();
    for (int i = 2; i < n; i += 2) {
      x.push_back(i);
      y.push_back(i + 1);
    }
    run_query(x, y);
    vector<int> V;
    V.push_back(1);
    for (int i = 2; i <= n; i++) {
      if (!is_same_set(i - 1, i)) {
        V.push_back(i);
      }
    }
    for (int j = 0; j <= 3; j++) {
      x.clear();
      y.clear();
      for (int i = j; i + 2 < V.size(); i += 4) {
        x.push_back(V[i]);
        y.push_back(V[i + 2]);
      }
      if (x.size()) {
        run_query(x, y);
      }
    }
    memset(color, 0, sizeof color);
    color[V[0]] = 1;
    if (V.size() > 1) {
      color[V[1]] = 2;
    }
    int i = 2;
    while (i < V.size()) {
      if (is_same_set(V[i], V[i - 2])) {
        color[V[i]] = color[V[i - 2]];
      } else {
        int c1 = color[V[i - 2]], c2 = color[V[i - 1]];
        if (c1 > c2) swap(c1, c2);
        if (c1 == 1 and c2 == 2) {
          color[V[i]] = 3;
        }
        if (c1 == 1 and c2 == 3) {
          color[V[i]] = 2;
        }
        if (c1 == 2 and c2 == 3) {
          color[V[i]] = 1;
        }
      }
      i++;
    }
    for (int c = 1; c <= 3; c++) {
      k[c] = 0;
      for (int i = 1; i <= n; i++) {
        if (color[i] != c) continue;
        for (int j = i + 1; j <= n; j++) {
          if (color[j] == c) {
            unit_set(i, j);
          }
        }
        for (int j = 1; j <= n; j++) {
          if (is_same_set(i, j)) {
            color[j] = c;
            k[c]++;
          }
        }
        break;
      }
    }
    printf("A %d %d %d\n", k[1], k[2], k[3]);
    for (int c = 1; c <= 3; c++) {
      bool blank = false;
      for (int i = 1; i <= n; i++) {
        if (color[i] == c) {
          if (blank)
            printf(" ");
          else
            blank = true;
          printf("%d", i);
        }
      }
      printf("\n");
    }
    fflush(stdout);
  }
}
