#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
ll n, k;
cin >> n >> k;
if (k == 1)
{
if (n == 1)
{
cout << "A" << endl;
}
else if (n == 2)
{
cout << "AP" << endl;
}
else
{
cout << "NIE" << endl;
}
}
else if (k == 2)
{
if (n == 2)
{
cout << "AA" << endl;
}
else if (n == 3)
{
cout << "AAP" << endl;
}
else if (n == 4)
{
cout << "AAPP" << endl;
}
else
{
cout << "NIE" << endl;
}
}
else if (k == 3)
{
string pattern = "AAAPAPPP";
if (n <= 8)
{
string c_pattern = "";
for (ll i = 0; i < n; i++)
{
c_pattern += pattern[i];
}
cout << c_pattern << endl;
}
else
{
cout << "NIE" << endl;
}
}
else
{
string pattern = "PPAPAA";
string real_pattern = "";
ll remaining = n - k;
for (ll i = 0; i < k; i++)
{
real_pattern += "A";
}
ll full_remaining = remaining / 6;
ll mod_remaining = remaining % 6;
for (ll i = 0; i < full_remaining; i++)
{
real_pattern += pattern;
}
for (ll i = 0; i < mod_remaining; i++)
{
real_pattern += pattern[i];
}
cout << real_pattern << endl;
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll t;
cin >> t;
while (t--)
{
solve();
}
}
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 | #include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { ll n, k; cin >> n >> k; if (k == 1) { if (n == 1) { cout << "A" << endl; } else if (n == 2) { cout << "AP" << endl; } else { cout << "NIE" << endl; } } else if (k == 2) { if (n == 2) { cout << "AA" << endl; } else if (n == 3) { cout << "AAP" << endl; } else if (n == 4) { cout << "AAPP" << endl; } else { cout << "NIE" << endl; } } else if (k == 3) { string pattern = "AAAPAPPP"; if (n <= 8) { string c_pattern = ""; for (ll i = 0; i < n; i++) { c_pattern += pattern[i]; } cout << c_pattern << endl; } else { cout << "NIE" << endl; } } else { string pattern = "PPAPAA"; string real_pattern = ""; ll remaining = n - k; for (ll i = 0; i < k; i++) { real_pattern += "A"; } ll full_remaining = remaining / 6; ll mod_remaining = remaining % 6; for (ll i = 0; i < full_remaining; i++) { real_pattern += pattern; } for (ll i = 0; i < mod_remaining; i++) { real_pattern += pattern[i]; } cout << real_pattern << endl; } } int main() { ios::sync_with_stdio(0); cin.tie(0); ll t; cin >> t; while (t--) { solve(); } } |
English