1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define BOOST ios_base::sync_with_stdio(0), cin.tie(0)
template<typename T>
using vc = vector<T>;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;

string res[10][10];

void solve(){
	int n, k;
	cin >> n >> k;
	if(n < 10 && k < 10){
		cout << res[n][k] << "\n";
		return;
	}
	if(n >= 10 && k < 4){
		cout << "NIE\n";
		return;
	}

	string magic = "PAPPAA";
	for(int i=0; i<k; i++) cout << "A";
	for(int i=0; i<n-k; i++) cout << magic[i%((int)magic.size())];
	cout << "\n";
}

int lp(int x, int len){
	int mx = 0;
	for(int i=0; i<len; i++){
		for(int j=i; j<len; j++){
			int l = (j-i+1);
			bool pali = 1;
			for(int k=0; k<l; k++){
				if((x&(1<<(i+k))) > 0 != (x&(1<<(j-k))) > 0) pali = 0;
			}
			if(pali) mx = max(mx, l);
		}
	}
	return mx;
}

int main(){
	BOOST;

	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			res[i][j] = "NIE";
		}
	}

	for(int len=1; len<10; len++){
		for(int i=0; i<(1<<len); i++){
			string s = "";
			for(int j=0; j<len; j++){
				if(i&(1<<j)) s += 'P';
				else s += 'A';
			}
			res[len][lp(i, len)] = s;
		}
	}

	int q;
	cin >> q;
	while(q--) solve();
}