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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//fast
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define all(x) x.begin(),x.end()
#define rep(n) for (int i = 0 ; i<n ; i++)
#define pb push_back

string easy[9][9];
string pom = "AAPPAP";

void solve(int ttt){
    int n,k;
	cin >> n >> k;
	//cout << n << ' ' << k << '\n';
	if (n<=8){
		cout << easy[n][k] << '\n';
		return;
	}
	if (k<4){
		cout << "NIE\n";
		return;
	}
	int c = 0;
	if (k==4){
		while (n>0){
			cout << pom[c];
			c++;
			if (c==6) c=0;
			n--;
		}
		cout << '\n';
		return;
	}
	string w;
	c = 5;
	rep(k-1){
		w+='P';
	}
	n-=k-1;
	while (n>0){
		w += pom[c];
		c--;
		n--;
		if (c==-1) c = 5;
	}
	cout << w << '\n';
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
	easy[1][1] = "A";
	easy[2][1] = "AP";
	easy[2][2] = "AA";
	easy[3][1] = "NIE";
	easy[3][2] = "AAP";
	easy[3][3] = "AAA";
	easy[4][1] = "NIE";
	easy[4][2] = "AAPP";
	easy[4][3] = "AAAP";
	easy[4][4] = "AAAA";
	easy[5][1] = "NIE";
	easy[5][2] = "NIE";
	easy[5][3] = "AAAPP";
	easy[5][4] = "AAAAP";
	easy[5][5] = "AAAAA";
	easy[6][1] = "NIE";
	easy[6][2] = "NIE";
	easy[6][3] = "AAAPPP";
	easy[6][4] = "AAAAPP";
	easy[6][5] = "AAAAAP";
	easy[6][6] = "AAAAAA";
	easy[7][1] = "NIE";
	easy[7][2] = "NIE";
	easy[7][3] = "AAAPAPP";
	easy[7][4] = "AAAAPPP";
	easy[7][5] = "AAAAAPP";
	easy[7][6] = "AAAAAAP";
	easy[7][7] = "AAAAAAA";
	easy[8][1] = "NIE";
	easy[8][2] = "NIE";
	easy[8][3] = "AAAPAPPP";
	easy[8][4] = "AAAAPPPP";
	easy[8][5] = "AAAAAPPP";
	easy[8][6] = "AAAAAAPP";
	easy[8][7] = "AAAAAAAP";
	easy[8][8] = "AAAAAAAA";
    rep(t) solve(i);
}