#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
inline void ckmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void ckmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
using VI = vector<int>;
char str[1 << 20];
vector<int> query(const vector<pair<int, int> > &a) {
  if (((int)a.size()) == 0) return vector<int>{};
  printf("Q %d", ((int)a.size()));
  for (pair<int, int> w : a) printf(" %d %d", w.first + 1, w.second + 1);
  printf("\n");
  fflush(stdout);
  scanf("%s", str);
  vector<int> ret;
  for (int i = 0; i < ((int)a.size()); i++) ret.push_back(str[i] - '0');
  return ret;
}
int main() {
  int testcase;
  for (scanf("%d", &testcase); testcase > 0; testcase--) {
    int n;
    scanf("%d", &n);
    vector<pair<int, int> > q1, q2;
    for (int i = 0; i + 1 < n; i += 2) q1.emplace_back(i, i + 1);
    for (int i = 1; i + 1 < n; i += 2) q2.emplace_back(i, i + 1);
    VI e1 = query(q1);
    VI e2 = query(q2);
    vector<pair<int, int> > segs;
    segs.emplace_back(0, 0);
    for (int i = (1); i < (n); ++i) {
      int same = 0;
      if (i % 2 == 1)
        same = e1[(i - 1) / 2];
      else
        same = e2[(i - 2) / 2];
      if (same)
        segs.back().second = i;
      else
        segs.emplace_back(i, i);
    }
    vector<pair<int, int> > q3, q4, q5;
    for (int i = 0; i + 2 < ((int)segs.size()); i += 3)
      q3.emplace_back(segs[i].first, segs[i + 2].first);
    for (int i = 1; i + 2 < ((int)segs.size()); i += 3)
      q4.emplace_back(segs[i].first, segs[i + 2].first);
    for (int i = 2; i + 2 < ((int)segs.size()); i += 3)
      q5.emplace_back(segs[i].first, segs[i + 2].first);
    VI e3 = query(q3);
    VI e4 = query(q4);
    VI e5 = query(q5);
    vector<int> g(max(0, ((int)segs.size()) - 2));
    for (int i = 0; i < (((int)e3.size())); ++i) g[i * 3] = e3[i];
    for (int i = 0; i < (((int)e4.size())); ++i) g[i * 3 + 1] = e4[i];
    for (int i = 0; i < (((int)e5.size())); ++i) g[i * 3 + 2] = e5[i];
    vector<int> color(((int)segs.size()));
    for (int i = 0; i < (((int)segs.size())); ++i)
      if (i == 0)
        color[i] = 0;
      else if (i == 1)
        color[i] = 1;
      else if (g[i - 2])
        color[i] = color[i - 2];
      else
        color[i] = 3 - color[i - 1] - color[i - 2];
    vector<int> r[3];
    for (int i = 0; i < (((int)segs.size())); ++i)
      for (int x = (segs[i].first); x < (segs[i].second + 1); ++x)
        r[color[i]].push_back(x);
    printf("A %d %d %d\n", ((int)r[0].size()), ((int)r[1].size()),
           ((int)r[2].size()));
    for (int k = 0; k < (3); ++k) {
      for (int i = 0; i < (((int)r[k].size())); ++i) {
        if (i > 0) printf(" ");
        printf("%d", r[k][i] + 1);
      }
      printf("\n");
    }
    fflush(stdout);
  }
  return 0;
}
