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

int calculate_cost(string_view str) {
  int n = str.size();
  int res = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= min(i, n-i-1); j++) {
      if (str[i-j] != str[i+j]) {
        break;
      }
      res = max(res, 2*j + 1);
    }
  }
  for (int i = 0; i < n-1; i++) {
    for (int j = 0; j < min(i+1, n-i-1); j++) {
      if (str[i-j] != str[i+j+1]) {
        break;
      }
      res = max(res, 2*(j+1));
    }
  }
  return res;
}

string get_best(int n) {
  auto best = make_tuple(n+1, n+1, n+1, n+1);
  string res = "";
  for (int i = 0; i < (1 << n); i++) {
    string cand(n, 'A');
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        cand[j] = 'P';
      }
    }
    auto curr = make_tuple(calculate_cost(cand), calculate_cost(cand + cand), calculate_cost(cand+cand+cand), calculate_cost(cand+cand+cand+cand));
    if (curr < best) {
      best = curr;
      res = cand;
    }
  }
  cerr << "[BEST] " << res << ", " << get<0>(best) << " " << get<1>(best) << " " << get<2>(best) << " " << get<3>(best) << "\n";
  return res;
}

constexpr string_view OPT = "PPAPAA";

void huge_palindrome_case(int n, int k) {
  string res = string(k, 'A') + string(n-k, 'P');
  cout << res << "\n";
}

void palindrome_three_case(int n) {
  string res = "NIE";
  if (n == 8) {
    res = "PPPAPAAA";
  } else if (n == 7) {
    res = "PPAPAAA";
  }
  cout << res << "\n";
}

void solve() {
  int n, k;
  cin >> n >> k;

  if (2*k >= n) {
    huge_palindrome_case(n, k);
    return;
  }
  if (k == 3) {
    palindrome_three_case(n);
    return;
  }
  if (k == 4 && n == 9) {
    cout << "PPPAPAAAA\n";
    return;
  }
  if (k <= 3) {
    cout << "NIE\n";
    return;
  }

  string ans(k, 'A');
  while ((int) ans.size() < n) {
    ans += OPT;
  }
  ans.resize(n);
  cout << ans << "\n";

  // if (calculate_cost(ans) != k || ans.size() != n) {
   //  cerr << "ERROR" << endl;
//  }

}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int t;
  cin >> t;
  while (t--) {
    solve();
  }

}