#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;
}
pii getNx(int s){
for (; ptr[s] < (int)ady[s].size(); ++ptr[s]){
pii cur = ady[s][ ptr[s] ];
if (mk[cur.second]) continue;
return cur;
}
return MP(-1, -1);
}
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();
int cur = 0;
while (!S.empty()){
int b = S.top(); S.pop();
int u = a, v = b;
if (v < u) swap(u, v);
ANS[M[MP(u,v)]] = 'A' + cur;
++cnt;
cur ^= 1;
a = b;
}
}
void read1(int n){
int x1, y1, ax, bx, ay, by;
cin >> x1 >> y1 >> ax >> bx >> mx >> ay >> by >> my;
init(mx + my);
for (int i = 0; i < n; ++i){
add_edge(x1, mx + y1);
x1 = (ax * x1 + bx) % mx;
y1 = (ay * y1 + by) % my;
}
}
void read2(int n)
{
cin >> mx >> my;
init(mx + my);
for (int i = 0; i < n; ++i){
int u, v;
cin >> u >> v;
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();
}
}
for (int i = 0; i < n; ++i) cout << ANS[i];
cout << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBEQih4KSBjb3V0PDwjeDw8Ij0iPDx4PDxlbmRsOwojZGVmaW5lIE1QIG1ha2VfcGFpcgoKdHlwZWRlZiBsb25nIGxvbmcgaW50NjQ7CnR5cGVkZWYgcGFpcjxpbnQsaW50PiBwaWk7CnR5cGVkZWYgdmVjdG9yPHBpaT4gdmk7Cgpjb25zdCBpbnQgb28gPSAxPDwzMDsKY29uc3QgZG91YmxlIEVQUyA9IDFlLTk7CmNvbnN0IGludCBNQVhOID0gKGludCkxZTYgKyAxMDsKCnZpIGFkeVtNQVhOXTsKaW50IERHW01BWE5dOyAvLyBEZWdyZWUKaW50IHB0cltNQVhOXSwgWFtNQVhOXSwgWVtNQVhOXTsKYm9vbCBta1tNQVhOXTsKY2hhciBBTlNbTUFYTl07Cm1hcDxwaWksIGludD4gTTsKc3RhY2s8aW50PiBTOwppbnQgZWRnLCBteCwgbXksIGNudDsKCnZvaWQgaW5pdChpbnQgbil7CgllZGcgPSBjbnQgPSAwOwoJUyA9IHN0YWNrPGludD4oKTsKCU0uY2xlYXIoKTsKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKXsKCQlhZHlbaV0uY2xlYXIoKTsKCQlER1tpXSA9IDA7CgkJcHRyW2ldID0gMDsKCX0KfQoKdm9pZCBhZGRfZWRnZShpbnQgdSwgaW50IHYpewoJaWYgKHYgPCB1KS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