#include <bits/stdc++.h>
using namespace std;
#define DB(x) cout<<#x<<"="<<x<<endl;
#define MP make_pair
typedef long long int64;
typedef pair<int,int> pii;
typedef vector<pii> vi;
const int oo = 1<<30;
const double EPS = 1e-9;
const int MAXN = (int)1e6 + 10;
vi ady[MAXN];
int DG[MAXN]; // Degree
int ptr[MAXN], X[MAXN], Y[MAXN];
bool mk[MAXN];
char ANS[MAXN];
map<pii, int> M;
stack<int> S;
int edg, mx, my, cnt;
void init(int n){
edg = cnt = 0;
S = stack<int>();
M.clear();
for (int i = 0; i < n; ++i){
ady[i].clear();
DG[i] = 0;
ptr[i] = 0;
}
}
void add_edge(int u, int v){
if (v < u) swap(u,v);
M[ MP(u,v) ] = edg;
DG[u]++; DG[v]++;
ady[u].push_back( MP(v, edg) );
ady[v].push_back( MP(u, edg) );
ANS[edg] = 0;
X[edg] = u, Y[edg] = v;
mk[edg++] = false;
}
void dfs(int s){
for (; ptr[s] < (int)ady[s].size(); ++ptr[s]){
pii cur = ady[s][ ptr[s] ];
if (mk[cur.second]) continue;
mk[cur.second] = true;
DG[ X[cur.second] ]--;
DG[ Y[cur.second] ]--;
dfs(cur.first);
break;
}
S.push(s);
}
void make(){
if (S.empty()) return;
int a = S.top(); S.pop();
// cout << a << endl;
int cur = 0;
while (!S.empty()){
int b = S.top(); S.pop();
// cout << b << endl;
int u = a, v = b;
if (v < u) swap(u, v);
// assert(0 <= u && u < mx);
// assert(mx <= v && v < mx + my);
// cout << u << " " << v << " " << M[ MP(u, v) ] << endl;
ANS[M[MP(u,v)]] = 'A' + cur;
++cnt;
cur ^= 1;
a = b;
}
// cout << endl;
}
void read1(int n){
int x1, y1, ax, bx, ay, by;
cin >> x1 >> y1 >> ax >> bx >> mx >> ay >> by >> my;
// assert(1 <= n && n <= 100000);
// assert(1 <= mx && mx <= 100);
// assert(1 <= my && my <= 100);
init(mx + my);
for (int i = 0; i < n; ++i){
add_edge(x1, mx + y1);
// cout << x1 << " " << y1 << endl;
x1 = (1LL * ax * x1 + bx) % mx;
y1 = (1LL * ay * y1 + by) % my;
}
// assert(edg == n);
}
void read2(int n)
{
cin >> mx >> my;
init(mx + my);
for (int i = 0; i < n; ++i){
int u, v;
cin >> u >> v;
// cout << u << " " << v + mx << endl;
add_edge(u, v + mx);
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while (t--){
int n; cin >> n;
read1(n);
for (int i = 0; i < mx + my; ++i){
if (DG[i] & 1){
S = stack<int>();
dfs(i);
make();
}
}
for (int i = 0; i < mx + my; ++i){
if (DG[i]){
S = stack<int>();
dfs(i);
make();
}
}
// assert(cnt == n);
for (int i = 0; i < n; ++i) cout << ANS[i];
cout << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBEQih4KSBjb3V0PDwjeDw8Ij0iPDx4PDxlbmRsOwojZGVmaW5lIE1QIG1ha2VfcGFpcgoKdHlwZWRlZiBsb25nIGxvbmcgaW50NjQ7CnR5cGVkZWYgcGFpcjxpbnQsaW50PiBwaWk7CnR5cGVkZWYgdmVjdG9yPHBpaT4gdmk7Cgpjb25zdCBpbnQgb28gPSAxPDwzMDsKY29uc3QgZG91YmxlIEVQUyA9IDFlLTk7CmNvbnN0IGludCBNQVhOID0gKGludCkxZTYgKyAxMDsKCnZpIGFkeVtNQVhOXTsKaW50IERHW01BWE5dOyAvLyBEZWdyZWUKaW50IHB0cltNQVhOXSwgWFtNQVhOXSwgWVtNQVhOXTsKYm9vbCBta1tNQVhOXTsKY2hhciBBTlNbTUFYTl07Cm1hcDxwaWksIGludD4gTTsKc3RhY2s8aW50PiBTOwppbnQgZWRnLCBteCwgbXksIGNudDsKCnZvaWQgaW5pdChpbnQgbil7CgllZGcgPSBjbnQgPSAwOwoJUyA9IHN0YWNrPGludD4oKTsKCU0uY2xlYXIoKTsKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKXsK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