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
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int ile_testow;
    cin >> ile_testow;

    string gotowiec_na_dwojke = "AAPP";
    string gotowiec_na_trojke = "AAAPAPPP";
    string ogon_pingwina = "PPAPAA";

    while (ile_testow--) {
        int dlugosc_napisu, dlugosc_palusia;
        cin >> dlugosc_napisu >> dlugosc_palusia;

        if (dlugosc_palusia == 1) {
            if (dlugosc_napisu == 1) {
                cout << "A\n";
            } else if (dlugosc_napisu == 2) {
                cout << "AP\n";
            } else {
                cout << "NIE\n";
            }
            continue;
        }

        if (dlugosc_palusia == 2) {
            if (dlugosc_napisu <= 4) {
                cout << gotowiec_na_dwojke.substr(0, dlugosc_napisu) << '\n';
            } else {
                cout << "NIE\n";
            }
            continue;
        }

        if (dlugosc_palusia == 3) {
            if (dlugosc_napisu <= 8) {
                cout << gotowiec_na_trojke.substr(0, dlugosc_napisu) << '\n';
            } else {
                cout << "NIE\n";
            }
            continue;
        }

        string potwor_z_plazy;
        potwor_z_plazy.reserve(dlugosc_napisu);

        potwor_z_plazy.append(dlugosc_palusia, 'A');
        for (int gdzie_foka = dlugosc_palusia; gdzie_foka < dlugosc_napisu; ++gdzie_foka) {
            potwor_z_plazy.push_back(ogon_pingwina[(gdzie_foka - dlugosc_palusia) % 6]);
        }

        cout << potwor_z_plazy << '\n';
    }

    return 0;
}