#ifdef _MSC_VER
  #ifndef __GNUC__
    #pragma warning(disable: 4996)
  #endif
  #define main main0
#endif
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long           ll;
typedef unsigned long long ull;
typedef unsigned int      uint;

string intToBinary(int x) {
  string s;
  for(int i = 31; i >= 0; --i) {
    s += (x & (1 << i)) ? '1' : '0';
  }
  return s;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  /*for(int i = 4, i1; i < 10; ++i) {
    i1 = 1;
    cout << "słowo długość: " << i << '\n';
    for(int j = 1; j < i; ++j)
      i1 *= 2;
    --i1;
    vector<string> slowo;
    for(int k = 0, l; k < i1; ++k) {     // kolejne wzorce
      string s;
      l = k;
      for(int j = 0; j < i; ++j) {       // string ze wzorca
        s += (l & 1) == 1 ? 'A' : 'P';
        l >>= 1;
      }
      slowo.push_back(s);
    }
    int dlugosc = i;
    int j, j1;
    for(int js = 0; js < slowo.size(); ++js) {  // string z tablicy
      for(j = i - 1; j > 0; --j) {     // długość podciągu
        string s1, s2;
        for(j1 = 0; j1 <= i - j; ++j1) {    // początek podciągu
          s1 = s2 = slowo[js].substr(j1, j);
          reverse(s2.begin(), s2.end());
          if(s1 == s2) {                      // palindrom
            dlugosc = j;
            break;
          }
        }
      }
    }
    cout << "    " << " podciąg długości " << dlugosc << " brak palindromu" << endl;
  }*/
  string s4("AAPP");
  string s8("AAAPAPPP");
  string s12("PAPPAAPAPPAA");
  int t;
  cin >> t;
  for(int i = 0; i < t; ++i) {
    int n, k;
    cin >> n >> k;
    if(k == 1) {
      if(n < 3)
        cout << s4.substr(1, n);
      else
        cout << "NIE";
    } else if(k == 2) {
      if(n < 5)
        cout << s4.substr(0, n);
      else
        cout << "NIE";
    } else if(k == 3) {
      if(n < 9)
        cout << s8.substr(0, n);
    } else {
      for(int j = 0; j < k; ++k)
        cout << 'A';
      for(n -= k; n > 12; n -= 12)
        cout << s12;
      cout << s12.substr(0, n);
    }
      cout << endl;
  }

  return 0;
}
