#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;
}