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

using namespace std;

void solve(){
  int n, k; cin >> n >> k;
  cerr << "currently " << n << ' '<< k << '\n';
  string res;
  auto handle = [&](string s){
    if(n<=s.size()){
      for(int i=0; i<n; i++) res.push_back(s[i]);
    } else{
      res = "NIE";
    }
  };

  if(k == 1){
    handle("PA");
  } else if(k == 2){
    handle("AAPP");
  } else if(k==3){
    handle("PPPAPAAA");
  } else {
    if(k == n){
      while(n--)
        res.push_back('P');
    } else {
      if(k+1 == n){
        n--;
        while(n--) 
          res.push_back('P');
        res.push_back('A');
      } else {
        for(int i=0; i<k-2; i++){
          res.push_back('P');
          n--;
        }
        string s = "PPAAPA";
        for(int i=0; i<n; i++)
          res.push_back(s[i%s.size()]);
      }
    }
  }
  cout << res << '\n';
}

signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t; cin >> t;
  while(t--) solve();
}