#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define ST first
#define ND second
#define PB push_back
using ll = long long;
using ld = long double;
using pi = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
#ifdef LOCAL
#define DTP(x, y) \
auto operator<<(auto &o, auto a)->decltype(y, o) \
{ \
o << "("; \
x; \
return o << ")"; \
}
DTP(o << a.first << ", " << a.second, a.second);
DTP(for (auto i : a) o << i << ", ", all(a));
void dump(auto... x) { ((cerr << x << ", "), ...) << '\n'; }
#define debug(x...) cerr << setw(4) << __LINE__ << ":[" #x "]: ", dump(x)
#else
#define debug(...) 0
#endif
void Solve()
{
int n, k;
cin >> n >> k;
if(k==1){
if(n>=3){
cout << "NIE\n";
return;
}
if(n==1){
cout << "A\n";
return;
}else{
cout << "AP\n";
return;
}
}
if(k==2){
string s="AAPP";
if(n>=5){
cout << "NIE\n";
return;
}else{
rep(i, 0, n)
cout << s[i];
cout << "\n";
return;
}
}
if(k==3){
if(n>=9){
cout << "NIE\n";
return;
}
string s="AAAPAPPP";
rep(i, 0, n)
cout << s[i];
cout << "\n";
return;
}
vi A(k);
A.PB(1);
A.PB(1);
A.PB(0);
A.PB(1);
while(sz(A)<n){
int m=sz(A);
if(A[m-3]==1 && A[m-2]==0 && A[m-1]==0){
A.PB(1);
continue;
}
if(A[m-3]==0 && A[m-2]==1 && A[m-1]==1){
A.PB(0);
continue;
}
if(A[m-1]==A[m-3]){
A.PB(1-A[m-4]);
continue;
}
A.PB(1-A[m-5]);
}
rep(i, 0, n){
if(A[i]==0)
cout << 'A';
else
cout << 'P';
}
cout << "\n";
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1;
cin >> t;
while(t--)
{
Solve();
}
return 0;
}
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | #include<bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); i++) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define ST first #define ND second #define PB push_back using ll = long long; using ld = long double; using pi = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; #ifdef LOCAL #define DTP(x, y) \ auto operator<<(auto &o, auto a)->decltype(y, o) \ { \ o << "("; \ x; \ return o << ")"; \ } DTP(o << a.first << ", " << a.second, a.second); DTP(for (auto i : a) o << i << ", ", all(a)); void dump(auto... x) { ((cerr << x << ", "), ...) << '\n'; } #define debug(x...) cerr << setw(4) << __LINE__ << ":[" #x "]: ", dump(x) #else #define debug(...) 0 #endif void Solve() { int n, k; cin >> n >> k; if(k==1){ if(n>=3){ cout << "NIE\n"; return; } if(n==1){ cout << "A\n"; return; }else{ cout << "AP\n"; return; } } if(k==2){ string s="AAPP"; if(n>=5){ cout << "NIE\n"; return; }else{ rep(i, 0, n) cout << s[i]; cout << "\n"; return; } } if(k==3){ if(n>=9){ cout << "NIE\n"; return; } string s="AAAPAPPP"; rep(i, 0, n) cout << s[i]; cout << "\n"; return; } vi A(k); A.PB(1); A.PB(1); A.PB(0); A.PB(1); while(sz(A)<n){ int m=sz(A); if(A[m-3]==1 && A[m-2]==0 && A[m-1]==0){ A.PB(1); continue; } if(A[m-3]==0 && A[m-2]==1 && A[m-1]==1){ A.PB(0); continue; } if(A[m-1]==A[m-3]){ A.PB(1-A[m-4]); continue; } A.PB(1-A[m-5]); } rep(i, 0, n){ if(A[i]==0) cout << 'A'; else cout << 'P'; } cout << "\n"; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t=1; cin >> t; while(t--) { Solve(); } return 0; } |
English