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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const string block = "PPAPAA";
string p;
string tab[11][11];

int check(int val){
    int ans = 0;
    for(int i = 0 ; i < val ; i++){
        int l = i - 1, r = i + 1, curr = 1;
        while(0 <= l && r < val){
            if(p[l] == p[r]){
                curr += 2;
            }else{
                break;
            }
            l--;
            r++;
        }
        ans = max(curr, ans);
        l = i;
        r = i + 1;
        curr = 0;
        while(0 <= l && r < val){
            if(p[l] == p[r]){
                curr += 2;
            }else{
                break;
            }
            l--;
            r++;
        }
        ans = max(curr, ans);
    }
    return ans;
}

string getAns(int n, int k){
    if(tab[n][k] != "") return tab[n][k];
    for(int mask = 0 ; mask < (1 << n) ; mask++){
        p.clear();
        for(int j = 0 ; j < n ; j++){
            if((1 << j) & mask) p.push_back('1');
            else p.push_back('0');
        }
        int w = check(n);
        if(w == k){
            for(int j = 0 ; j < n ; j++){
                if(p[j] == '0') p[j] = 'P';
                else p[j] = 'A';
            }
            return tab[n][k] = p;
        }
    }
    return tab[n][k] = "NIE";
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k, t;
    cin >> t;
    while(t--){
        cin >> n >> k;
        if(n <= 10){
            cout << getAns(n, k);
        }else if(k >= 4){
            for(int i = 0 ; i < k ; i++){
                cout << "A";
            }
            for(int i = k ; i < n ; i++){
                cout << block[(i - k) % 6];
            }
        }else{
            cout << "NIE";
        }
        cout << '\n';
    }
}