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
#include <bits/stdc++.h>
using namespace std;
const int M = 83'334;
const char A = 'A';
const string P = "P";
const string T = "PAPPAAPAPPAA";
const string NIE = "NIE";
const string P2 = "AAPP";
const string P3 = "AAAPAPPP";
string S;
void resolve(int textLength, int palindromMaxLenght) {

	if (palindromMaxLenght == 1) {
		if (textLength == 1) {
			cout << A << endl;
		} else if (textLength == 2) {
			cout << A << P << endl;
		} else {
			cout << NIE << endl;
		}
	} else if (palindromMaxLenght == 2) {
		if (textLength <= 4) {
			cout << P2.substr(0, textLength) << endl;
		} else {
			cout << NIE << endl;
		}
	} else if (palindromMaxLenght == 3) {
		if (textLength <= 8) {
			cout << P3.substr(0, textLength) << endl;
		} else {
			cout << NIE << endl;
		}
	} else {
		cout << string(palindromMaxLenght, A);
		cout << S.substr(0, textLength - palindromMaxLenght);
		cout << endl;
	}
}
const bool DEBUG = !true;
int main() {
//	ifstream cin("tests/0b.in");

	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	S.reserve(T.size() * M);
	for (int i = 0; i < M; i++) {
		S.append(T);
	}

	int t, n, k;
	cin >> t;

	for (int i = 0; i < t; i++) {
		cin >> n;
		cin >> k;
		if (DEBUG) {
			cout << n << " " << k << endl;
		}
		resolve(n, k);
	}

}