#include <bits/stdc++.h>
using namespace std;
int T, fa[100010], ans[100010];
vector<bool> query(vector<pair<int, int> > p) {
  if (!p.size()) return vector<bool>();
  printf("Q %d ", p.size());
  for (auto &x : p) printf("%d %d ", x.first, x.second);
  putchar('\n');
  fflush(stdout);
  string s;
  cin >> s;
  if (s[0] == '-') exit(0);
  vector<bool> ret(p.size());
  for (int i = 0; i < s.size(); i++) ret[i] = s[i] - '0';
  return ret;
}
vector<bool> getadjacent(vector<int> q) {
  if (q.size() <= 1) return vector<bool>();
  vector<pair<int, int> > Q;
  for (int i = 0; i + 1 < q.size(); i += 2)
    Q.push_back(make_pair(q[i], q[i + 1]));
  auto r1 = query(Q);
  Q.clear();
  for (int i = 1; i + 1 < q.size(); i += 2)
    Q.push_back(make_pair(q[i], q[i + 1]));
  auto r2 = query(Q);
  vector<bool> ret;
  for (int i = 0; i + 1 < q.size(); i++) {
    if (i & 1)
      ret.push_back(r2[i >> 1]);
    else
      ret.push_back(r1[i >> 1]);
  }
  return ret;
}
void solve() {
  int n;
  scanf("%d", &n);
  if (n == -1) exit(0);
  vector<int> tmp;
  for (int i = 1; i <= n; i++) tmp.push_back(i);
  auto c = getadjacent(tmp);
  fa[1] = 1;
  vector<int> q2;
  q2.push_back(1);
  for (int i = 1; i < n; i++) {
    if (c[i - 1]) {
      fa[i + 1] = fa[i];
    } else {
      fa[i + 1] = i + 1;
      q2.push_back(i + 1);
    }
  }
  tmp.clear();
  for (int i = 0; i < q2.size(); i += 2) tmp.push_back(q2[i]);
  auto c1 = getadjacent(tmp);
  tmp.clear();
  for (int i = 1; i < q2.size(); i += 2) tmp.push_back(q2[i]);
  auto c2 = getadjacent(tmp);
  if (q2.size() > 1) ans[q2[1]] = 1;
  for (int i = 2; i < q2.size(); i++) {
    if (!(i & 1)) {
      if (!c1[(i >> 1) - 1])
        ans[q2[i]] = 3 - ans[q2[i - 1]] - ans[q2[i - 2]];
      else
        ans[q2[i]] = ans[q2[i - 2]];
    } else {
      if (!c2[(i >> 1) - 1])
        ans[q2[i]] = 3 - ans[q2[i - 1]] - ans[q2[i - 2]];
      else
        ans[q2[i]] = ans[q2[i - 2]];
    }
  }
  vector<int> ret[3];
  for (int i = 2; i <= n; i++) {
    if (fa[i] != i) ans[i] = ans[fa[i]];
  }
  for (int i = 1; i <= n; i++) ret[ans[i]].push_back(i);
  printf("A %d %d %d\n", ret[0].size(), ret[1].size(), ret[2].size());
  for (int i = 0; i < 3; i++) {
    for (int &x : ret[i]) printf("%d ", x);
    puts("");
  }
  fflush(stdout);
}
int main() {
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
