#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAXN = 1e5 + 50;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tc;
  cin >> tc;
  while (tc--) {
    long long n;
    cin >> n;
    if (n == 1) {
      cout << "A 1 0 0\n1\n\n";
      cout.flush();
      continue;
    }
    string a = "", b = "", c = "";
    if (n / 2) {
      cout << "Q " << n / 2;
      for (int i = 1; i < n; i += 2) {
        cout << " " << i << " " << i + 1;
      }
      cout << '\n';
      cout.flush();
      cin >> a;
      if (a == "-1") return 0;
    }
    if ((n - 1) / 2) {
      cout << "Q " << (n - 1) / 2;
      for (int i = 2; i < n; i += 2) {
        cout << " " << i << " " << i + 1;
      }
      cout << '\n';
      cout.flush();
      cin >> b;
      if (b == "-1") return 0;
    }
    string extra = "", adj = "";
    if (a.length() > b.length()) extra = a[n / 2 - 1];
    for (long long i = (1); i <= (b.length()); i++) {
      adj += a[i - 1];
      adj += b[i - 1];
    }
    adj += extra;
    long long ans[MAXN];
    fill(ans, ans + n + 5, -1);
    vector<long long> diffs;
    diffs.push_back(0);
    for (long long i = (1); i <= (adj.length()); i++) {
      if (adj[i - 1] == '0') diffs.push_back(i);
    }
    vector<long long> query1, query2, query3;
    long long sz = diffs.size();
    long long sz1 = 0, sz2 = 0, sz3 = 0;
    for (int i = 2; i < sz; i += 3) {
      query1.push_back(i);
      sz1++;
    }
    for (int i = 3; i < sz; i += 3) {
      query2.push_back(i);
      sz2++;
    }
    for (int i = 4; i < sz; i += 3) {
      query3.push_back(i);
      sz3++;
    }
    string d, emplace, first;
    if (query1.size()) {
      cout << "Q " << query1.size();
      for (int i = 0; i < sz1; i++) {
        cout << " " << diffs[query1[i] - 2] + 1 << " " << diffs[query1[i]] + 1;
      }
      cout << '\n';
      cout.flush();
      cin >> d;
      if (d == "-1") return 0;
    }
    if (query2.size()) {
      cout << "Q " << query2.size();
      for (int i = 0; i < sz2; i++) {
        cout << " " << diffs[query2[i] - 2] + 1 << " " << diffs[query2[i]] + 1;
      }
      cout << '\n';
      cout.flush();
      cin >> emplace;
      if (emplace == "-1") return 0;
    }
    if (query3.size()) {
      cout << "Q " << query3.size();
      for (int i = 0; i < sz3; i++) {
        cout << " " << diffs[query3[i] - 2] + 1 << " " << diffs[query3[i]] + 1;
      }
      cout << '\n';
      cout.flush();
      cin >> first;
      if (first == "-1") return 0;
    }
    string diff = "";
    for (int i = 0; i < first.length(); i++) {
      diff += d[i];
      diff += emplace[i];
      diff += first[i];
    }
    if (d.length() > first.length()) diff += d[sz1 - 1];
    if (emplace.length() > first.length()) diff += emplace[sz2 - 1];
    long long ans1[MAXN];
    fill(ans1, ans1 + n + 5, -1);
    vector<long long> ans2;
    if (diffs.size() > 2) {
      ans2.push_back(1);
      ans2.push_back(2);
      for (long long i = (0); i <= (diff.length() - 1); i++) {
        if (diff[i] == '1') {
          ans2.push_back(ans2[i]);
        } else {
          ans2.push_back(6 - ans2[i] - ans2[i + 1]);
        }
      }
    } else if (diffs.size() == 2) {
      ans2.push_back(1);
      ans2.push_back(2);
    } else {
      ans2.push_back(1);
    }
    sz = ans2.size() - 1;
    for (long long i = (0); i <= (sz); i++) {
      ans1[diffs[i]] = ans2[i];
    }
    vector<long long> final[4];
    for (long long i = (0); i <= (n - 1); i++) {
      if (ans1[i] == -1) ans1[i] = ans1[i - 1];
      final[ans1[i]].push_back(i + 1);
    }
    cout << "A " << final[1].size() << " " << final[2].size() << " "
         << final[3].size() << '\n';
    sz = final[1].size();
    sz--;
    for (long long i = (0); i <= (sz); i++) cout << final[1][i] << " ";
    cout << '\n';
    sz = final[2].size();
    sz--;
    for (long long i = (0); i <= (sz); i++) cout << final[2][i] << " ";
    cout << '\n';
    sz = final[3].size();
    sz--;
    for (long long i = (0); i <= (sz); i++) cout << final[3][i] << " ";
    cout << '\n';
    cout.flush();
  }
  return 0;
}
