#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
char s[MAX];
vector<bool> query(const vector<pair<int, int>>& pairs) {
  if (pairs.size() == 0) return vector<bool>();
  printf("Q %d", (int)pairs.size());
  for (const pair<int, int>& p : pairs) {
    printf(" %d %d", p.first, p.second);
  }
  printf("\n");
  fflush(stdout);
  scanf("%s", s);
  int n = strlen(s);
  vector<bool> res(n);
  for (int i = 0; i < n; ++i) {
    res[i] = s[i] == '1';
  }
  return res;
}
void run() {
  int N;
  scanf("%d", &N);
  auto run_queries =
      [](const vector<int>& indices) -> tuple<vector<bool>, vector<bool>> {
    vector<pair<int, int>> q1;
    for (int i = 0; i < indices.size(); i += 2) {
      if (i + 1 < indices.size()) q1.push_back({indices[i], indices[i + 1]});
    }
    vector<pair<int, int>> q2;
    for (int i = 1; i < indices.size(); i += 2) {
      if (i + 1 < indices.size()) q2.push_back({indices[i], indices[i + 1]});
    }
    vector<bool> r1 = query(q1);
    vector<bool> r2 = query(q2);
    return {r1, r2};
  };
  auto differs_from_prev = [](int i, const vector<bool>& r1,
                              const vector<bool>& r2) -> bool {
    if (i == 0)
      return true;
    else if (i % 2 == 0) {
      if (!r2[i / 2 - 1]) {
        return true;
      }
    } else {
      if (!r1[i / 2]) {
        return true;
      }
    }
    return false;
  };
  vector<int> init(N, 0);
  for (int i = 0; i < N; ++i) init[i] = i + 1;
  vector<bool> r1, r2;
  tie(r1, r2) = run_queries(init);
  vector<int> remaining;
  for (int i = 0; i < N; ++i) {
    if (differs_from_prev(i, r1, r2)) {
      remaining.push_back(init[i]);
    }
  }
  vector<int> odd, even;
  for (int i = 0; i < remaining.size(); ++i) {
    if (i % 2 == 0)
      even.push_back(remaining[i]);
    else
      odd.push_back(remaining[i]);
  }
  vector<bool> r3, r4;
  tie(r3, r4) = run_queries(even);
  vector<bool> r5, r6;
  tie(r5, r6) = run_queries(odd);
  vector<int> gnum(N + 1);
  for (int i = 0; i < remaining.size(); ++i) {
    if (i == 0) {
      gnum[remaining[i]] = 0;
    } else if (i == 1) {
      gnum[remaining[i]] = 1;
    } else {
      int prev = gnum[remaining[i - 1]];
      int pprev = gnum[remaining[i - 2]];
      if (i % 2 == 0) {
        if (differs_from_prev(i / 2, r3, r4)) {
          gnum[remaining[i]] = 3 - prev - pprev;
        } else {
          gnum[remaining[i]] = pprev;
        }
      } else {
        if (differs_from_prev(i / 2, r5, r6)) {
          gnum[remaining[i]] = 3 - prev - pprev;
        } else {
          gnum[remaining[i]] = pprev;
        }
      }
    }
    int next = i == remaining.size() - 1 ? N : remaining[i + 1] - 1;
    for (int j = remaining[i]; j <= next; ++j) {
      gnum[j] = gnum[remaining[i]];
    }
  }
  array<vector<int>, 3> res;
  for (int i = 1; i <= N; ++i) {
    res[gnum[i]].push_back(i);
  }
  printf("A %d %d %d\n", (int)res[0].size(), (int)res[1].size(),
         (int)res[2].size());
  for (int g = 0; g < 3; ++g) {
    for (int i = 0; i < res[g].size(); ++i) {
      printf("%d", res[g][i]);
      if (i == res[g].size() - 1)
        printf("\n");
      else
        printf(" ");
    }
  }
  fflush(stdout);
}
int main() {
  int T;
  scanf("%d", &T);
  for (int t = 0; t < T; ++t) {
    run();
  }
  return 0;
}
