#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 2e9;
const long long INFLL = 1e18;
const int MAX_N = 100000;
int T;
int N;
bool chk[MAX_N + 1];
vector<pair<int, int> > query;
void ask() {
  if (query.empty()) return;
  printf("Q %d ", (int)query.size());
  for (int i = 0; i < query.size(); i++) {
    printf("%d %d ", query[i].first, query[i].second);
  }
  printf("\n");
  fflush(stdout);
}
vector<int> v;
int color[MAX_N + 1];
bool chk2[MAX_N + 1];
vector<int> ans[4];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
      chk[i] = false;
      chk2[i] = false;
    }
    while (!query.empty()) query.pop_back();
    for (int i = 1; i <= N; i++) {
      if (i * 2 > N) break;
      query.push_back({i * 2 - 1, i * 2});
    }
    ask();
    for (int i = 0; i < query.size(); i++) {
      char c;
      while (1) {
        scanf("%c", &c);
        if (c == '0' || c == '1') break;
      }
      chk[query[i].second] = c - '0';
    }
    while (!query.empty()) query.pop_back();
    for (int i = 1; i <= N; i++) {
      if (i * 2 + 1 > N) break;
      query.push_back({i * 2, i * 2 + 1});
    }
    ask();
    for (int i = 0; i < query.size(); i++) {
      char c;
      while (1) {
        scanf("%c", &c);
        if (c == '0' || c == '1') break;
      }
      chk[query[i].second] = c - '0';
    }
    while (!query.empty()) query.pop_back();
    while (!v.empty()) v.pop_back();
    v.push_back(1);
    for (int i = 2; i <= N; i++) {
      if (!chk[i]) {
        v.push_back(i);
      }
    }
    for (int i = 0; i < v.size(); i++) {
      if (i % 4 == 2 || i % 4 == 3) {
        query.push_back({v[i - 2], v[i]});
      }
    }
    ask();
    for (int i = 0; i < query.size(); i++) {
      char c;
      while (1) {
        scanf("%c", &c);
        if (c == '0' || c == '1') break;
      }
      chk2[query[i].second] = c - '0';
    }
    while (!query.empty()) query.pop_back();
    for (int i = 0; i < v.size(); i++) {
      if (i % 4 == 0 || i % 4 == 1) {
        if (i - 2 < 0) continue;
        query.push_back({v[i - 2], v[i]});
      }
    }
    ask();
    for (int i = 0; i < query.size(); i++) {
      char c;
      while (1) {
        scanf("%c", &c);
        if (c == '0' || c == '1') break;
      }
      chk2[query[i].second] = c - '0';
    }
    while (!query.empty()) query.pop_back();
    color[1] = 1;
    int prv1 = 2, prv2 = 1;
    for (int i = 2; i <= N; i++) {
      if (!chk[i]) {
        if (chk2[i]) {
          color[i] = prv1;
        } else {
          color[i] = 6 - prv1 - prv2;
        }
        prv1 = prv2;
        prv2 = color[i];
      } else {
        color[i] = color[i - 1];
      }
    }
    for (int i = 1; i <= 3; i++) {
      while (!ans[i].empty()) ans[i].pop_back();
    }
    for (int i = 1; i <= N; i++) {
      ans[color[i]].push_back(i);
    }
    printf("A %d %d %d\n", (int)ans[1].size(), (int)ans[2].size(),
           (int)ans[3].size());
    for (int i = 1; i <= 3; i++) {
      for (int j : ans[i]) {
        printf("%d ", j);
      }
      printf("\n");
    }
    fflush(stdout);
  }
  return 0;
}
