#ifndef UNCLE
#pragma GCC optimize("O3,unroll-loops")
#endif
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,p,q) for(int i=(p); i<=(q); ++i)
#define ROF(i,p,q) for(int i=(p); i>=(q); --i)
#define REP(i,q) for(int i=0; i<(q); ++i)
#define pb push_back
#define as assign
#define rz resize
#define Co const
#define al(X) X.begin(), X.end()
#define ral(X) X.rbegin(), X.rend()
#define sz(X) (int)((X).size())
#define ckmx(a,b) a=max(a,b)
#define ckmn(a,b) a=min(a,b)
#define V vector
typedef long long ll;
typedef long double ld;
typedef mt19937_64 mt;
#ifndef UNCLE
typedef basic_string<bool> vb;
typedef basic_string<int> vi;
typedef basic_string<ll> vl;
#else
typedef V<bool> vb;
typedef V<int> vi;
typedef V<ll> vl;
#endif
constexpr ll INFl=(ll)1e18+14;
constexpr int INFi=1e9+14, MX_N=5e5+14;
int N,K;
void Inpt(){
cin>>N>>K;
if(N==1){ cout<<"A\n"; return;}
else if(N==2){
if(K==1) cout<<"AP\n";
else cout<<"AA\n";
return;
}
if(K==1){ cout<<"NIE\n"; return;}
if(N==3){
if(K==2) cout<<"APP\n";
else cout<<"AAA\n";
return;
}else if(N==4){
if(K==2) cout<<"AAPP\n";
else if(K==3) cout<<"AAAP\n";
else cout<<"AAAA\n";
return;
}
if(K==2){ cout<<"NIE\n"; return;}
if(K==3){
if(N>8) cout<<"NIE\n";
else{
string sza="AAAPAPPP";
REP(i,N) cout<<sza[i];
cout<<"\n";
}
return;
}
string rs(N,'A'),sza="AAPPAP";
REP(i,K) rs[i]='A';
FOR(i,K,N-1) rs[i]=sza[(i-K+2)%6];
cout<<rs<<"\n";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T=1;
cin>>T;
while(T--) Inpt();
}
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 | #ifndef UNCLE #pragma GCC optimize("O3,unroll-loops") #endif #include <bits/stdc++.h> using namespace std; #define FOR(i,p,q) for(int i=(p); i<=(q); ++i) #define ROF(i,p,q) for(int i=(p); i>=(q); --i) #define REP(i,q) for(int i=0; i<(q); ++i) #define pb push_back #define as assign #define rz resize #define Co const #define al(X) X.begin(), X.end() #define ral(X) X.rbegin(), X.rend() #define sz(X) (int)((X).size()) #define ckmx(a,b) a=max(a,b) #define ckmn(a,b) a=min(a,b) #define V vector typedef long long ll; typedef long double ld; typedef mt19937_64 mt; #ifndef UNCLE typedef basic_string<bool> vb; typedef basic_string<int> vi; typedef basic_string<ll> vl; #else typedef V<bool> vb; typedef V<int> vi; typedef V<ll> vl; #endif constexpr ll INFl=(ll)1e18+14; constexpr int INFi=1e9+14, MX_N=5e5+14; int N,K; void Inpt(){ cin>>N>>K; if(N==1){ cout<<"A\n"; return;} else if(N==2){ if(K==1) cout<<"AP\n"; else cout<<"AA\n"; return; } if(K==1){ cout<<"NIE\n"; return;} if(N==3){ if(K==2) cout<<"APP\n"; else cout<<"AAA\n"; return; }else if(N==4){ if(K==2) cout<<"AAPP\n"; else if(K==3) cout<<"AAAP\n"; else cout<<"AAAA\n"; return; } if(K==2){ cout<<"NIE\n"; return;} if(K==3){ if(N>8) cout<<"NIE\n"; else{ string sza="AAAPAPPP"; REP(i,N) cout<<sza[i]; cout<<"\n"; } return; } string rs(N,'A'),sza="AAPPAP"; REP(i,K) rs[i]='A'; FOR(i,K,N-1) rs[i]=sza[(i-K+2)%6]; cout<<rs<<"\n"; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int T=1; cin>>T; while(T--) Inpt(); } |
English