#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<int> v[N], ans[3];
int fa[N], sz[N], kk, askx[N], asky[N], nx[N], lst[N], same[N], m, fr[N], p[N],
    l[N];
char s[N];
void ask(bool tt) {
  if (!kk) return;
  printf("Q %d ", kk);
  if (!tt)
    for (int i = 1; i <= kk; i++) printf("%d %d ", askx[i], asky[i]);
  else
    for (int i = 1; i <= kk; i++) printf("%d %d ", nx[askx[i]], nx[asky[i]]);
  puts("");
  fflush(stdout);
  cin >> (s + 1);
  if (s[1] == '-') exit(0);
  if (!tt)
    for (int i = 1; i <= kk; i++) same[askx[i]] = s[i] == '1';
  else
    for (int i = 1; i <= kk; i++) lst[asky[i]] = s[i] == '1';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;
    kk = 0;
    for (int i = 1; i + 1 <= n; i += 2) askx[++kk] = i, asky[kk] = i + 1;
    ask(0);
    kk = 0;
    for (int i = 2; i + 1 <= n; i += 2) askx[++kk] = i, asky[kk] = i + 1;
    ask(0);
    m = 0;
    for (int i = 1; i <= n; i++)
      if (!same[i - 1]) nx[++m] = i;
    for (int i = 1; i <= 3; i += 2) {
      kk = 0;
      for (int j = i; j + 2 <= m; j += 4) askx[++kk] = j, asky[kk] = j + 2;
      for (int j = i + 1; j + 2 <= m; j += 4) askx[++kk] = j, asky[kk] = j + 2;
      ask(1);
    }
    ans[0].clear();
    ans[1].clear();
    ans[2].clear();
    fr[1] = p[nx[1]] = 0;
    fr[2] = p[nx[2]] = 1;
    for (int i = 3; i <= m; i++)
      if (lst[i])
        fr[i] = p[nx[i]] = fr[i - 2];
      else
        fr[i] = p[nx[i]] = 3 - fr[i - 1] - fr[i - 2];
    for (int i = 1; i <= n; i++) l[i] = same[i - 1] ? l[i - 1] : i;
    for (int i = 1; i <= n; i++) ans[p[l[i]]].push_back(i);
    printf("A %d %d %d\n", int(ans[0].size()), int(ans[1].size()),
           int(ans[2].size()));
    for (int i = 0; i < 3; i++) {
      for (auto &j : ans[i]) printf("%d ", j);
      puts("");
    }
    fflush(stdout);
  }
  return 0;
}
