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
/* 2026
 * Maciej Szeptuch
 */

#include <cstdio>

const char pattern[7] = "PAPPAA";

int tests;
int length;
int max;

int main(void)
{
    scanf("%d", &tests);
    for(int t = 0; t < tests; ++t)
    {
        scanf("%d %d", &length, &max);
        switch(max)
        {
        case 1:
            if(length > 2)
                puts("NIE");

            else
            {
                for(int p = 0; p < length; ++p)
                    putchar(pattern[p]);

                puts("");
            }

            break;

        case 2:
            if(length > 4)
                puts("NIE");

            else
            {
                for(int p = 0; p < length; ++p)
                    putchar(pattern[p + 2]);

                puts("");
            }
            break;

        case 3:
            if(length > 8)
                puts("NIE");

            else
            {
                int l = 0;
                while(l < max && l < length)
                {
                    ++l;
                    putchar('A');
                }

                for(int p = 0; l < length && p < 4; ++p, ++l)
                    putchar(pattern[p]);

                while(l < length)
                {
                    ++l;
                    putchar('P');
                }

                puts("");
            }
            break;

        default:
            int l = 0;
            while(l < max && l < length)
            {
                ++l;
                putchar('A');
            }

            for(int p = 0; l < length; ++p, ++l)
                putchar(pattern[p % 6]);

            puts("");
            break;
        }
    }

    return 0;
}