#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000;
string ask(const vector<pair<int, int> >& a) {
  if (((int)(a.size())) == 0) {
    return {};
  }
  cout << "Q " << ((int)(a.size()));
  for (int i = 0; i < ((int)(a.size())); i++) {
    printf(" %i %i", a[i].first + 1, a[i].second + 1);
  }
  cout << endl;
  string ans;
  cin >> ans;
  return ans;
}
bool was[MAXN];
int color[MAXN];
void solve() {
  memset(was, 0, sizeof was);
  int n;
  cin >> n;
  if (n == -1) {
    exit(100500);
  }
  vector<pair<int, int> > a;
  for (int i = 0; i + 1 < n; i += 2) {
    a.push_back({i, i + 1});
  }
  string ans1 = ask(a);
  a.clear();
  for (int i = 1; i + 1 < n; i += 2) {
    a.push_back({i, i + 1});
  }
  string ans2 = ask(a);
  string equal;
  equal.resize(n - 1);
  for (int i = 0; i + 1 < n; i += 2) {
    equal[i] = ans1[i / 2];
  }
  for (int i = 1; i + 1 < n; i += 2) {
    equal[i] = ans2[i / 2];
  }
  vector<pair<int, int> > ask;
  int prev_group = -1;
  for (int i = 1; i < n; i++) {
    if (equal[i - 1] == '0') {
      if (prev_group != -1) {
        ask.push_back({i, prev_group});
      }
      prev_group = i - 1;
    }
  }
  vector<pair<int, int> > part_ask[2];
  for (int i = 0; i < ask.size(); i++) {
    if (was[ask[i].first] || was[ask[i].second]) {
      part_ask[1].push_back(ask[i]);
      continue;
    }
    was[ask[i].first] = was[ask[i].second] = 1;
    part_ask[0].push_back(ask[i]);
  }
  ans1 = ::ask(part_ask[0]);
  ans2 = ::ask(part_ask[1]);
  string ans;
  ans.resize(n);
  for (int i = 0; i < ((int)(part_ask[0].size())); i++) {
    ans[part_ask[0][i].first] = ans1[i];
  }
  for (int i = 0; i < ((int)(part_ask[1].size())); i++) {
    ans[part_ask[1][i].first] = ans2[i];
  }
  color[0] = 0;
  prev_group = -1;
  for (int i = 1; i < n; i++) {
    if (equal[i - 1] == '0') {
      if (prev_group == -1) {
        color[i] = 1;
      } else {
        if (ans[i] == '0') {
          color[i] = 3 - color[prev_group] - color[i - 1];
        } else {
          color[i] = color[prev_group];
        }
      }
      prev_group = i - 1;
    } else {
      color[i] = color[i - 1];
    }
  }
  int cnt[3] = {0, 0, 0};
  for (int i = 0; i < n; i++) {
    cnt[color[i]]++;
  }
  cout << "A " << cnt[0] << " " << cnt[1] << " " << cnt[2] << endl;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < n; j++) {
      if (color[j] == i) {
        printf("%i ", j + 1);
      }
    }
    cout << endl;
  }
}
int main(int argc, const char* argv[]) {
  int t;
  cin >> t;
  while (t-- > 0) {
    solve();
  }
  return 0;
}
