#include <bits/stdc++.h>
const double Pi = acos(-1.0);
using namespace std;
const int maxN = 100005;
int T;
char s[maxN];
int res[2][maxN];
void query(vector<int> &v, int p, int k) {
  if (((int)v.size() - p) / 2 < 1) return;
  printf("Q %d", (v.size() - p) / 2);
  for (int i = p; i + 1 < (int)v.size(); i += 2)
    printf(" %d %d", v[i], v[i + 1]);
  puts("");
  fflush(stdout);
  scanf("%s", s);
  for (int i = p, j = 0; i + 1 < (int)v.size(); i += 2, j++)
    res[k][i] = (s[j] == '1');
}
int col[maxN];
int main(int argc, char **argv) {
  scanf("%d", &T);
  int N;
  while (T--) {
    scanf("%d", &N);
    vector<int> v;
    for (int i = 1; i <= N; i++) v.push_back(i);
    query(v, 0, 0);
    query(v, 1, 0);
    vector<int> v1, v2;
    int cnt = 0;
    for (int i = 0, j; i < N; i++) {
      if (i && res[0][i - 1]) {
        j = i + 1;
        while (res[0][j - 1] && j < N) j++;
        i = j - 1;
      } else {
        if (cnt % 2)
          v2.push_back(i + 1);
        else
          v1.push_back(i + 1);
        cnt++;
      }
    }
    query(v1, 0, 0);
    query(v1, 1, 0);
    query(v2, 0, 1);
    query(v2, 1, 1);
    memset(col, -1, sizeof(col));
    col[v1[0]] = 0;
    if (v2.size()) col[v2[0]] = 1;
    for (int i = 1; i < (int)v1.size(); i++) {
      if (res[0][i - 1])
        col[v1[i]] = col[v1[i - 1]];
      else {
        for (int j = 0; j < 3; j++) {
          if (j != col[v1[i - 1]] && j != col[v2[i - 1]]) col[v1[i]] = j;
        }
      }
      if (i < (int)v2.size()) {
        if (res[1][i - 1])
          col[v2[i]] = col[v2[i - 1]];
        else {
          for (int j = 0; j < 3; j++) {
            if (j != col[v2[i - 1]] && j != col[v1[i]]) col[v2[i]] = j;
          }
        }
      }
    }
    vector<int> ans[3];
    ans[col[1]].push_back(1);
    for (int i = 2; i <= N; i++) {
      if (col[i] == -1) col[i] = col[i - 1];
      ans[col[i]].push_back(i);
    }
    printf("A %d %d %d\n", ans[0].size(), ans[1].size(), ans[2].size());
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < (int)ans[i].size(); j++) printf("%d ", ans[i][j]);
      puts("");
    }
    fflush(stdout);
  }
  return 0;
}
