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

using namespace std;

void wypisz(bool a){
    if( a ) cout << "P";
    else  cout << "A";
}

int palindrom(int l, int k, int liczba){
    int j = k;
    for(int i = l; i <= k; i++){
        if( ((liczba >> i) & 1) != ((liczba >> j) & 1) ) return 0;
        j--;
    }
    return 1;
}

int najdluzszy_palindrom(int liczba, int dlugosc){
    int res = 0;
    for(int i = 0; i < dlugosc; i++){
        for(int j = i; j < dlugosc; j++){
            if( palindrom(i,j,liczba) ) res = max(res, j-i+1);
        }
    }
    return res;
}

void solve_brutally(int n, int k){
    for(int liczba = 0; liczba < (1<<n); liczba++){
        if( najdluzszy_palindrom(liczba, n) == k ){
            for(int j = 0; j < n; j++ ) wypisz( (((liczba >> j) & 1) > 0 ) );
            cout << "\n";
            return;
        }
    }
    cout << "NIE\n";
}


void solve(){
    int n, k;
    cin >> n >> k;
    if( n <= 8 ){
        solve_brutally(n, k);
        return;
    }
    if( k < 4 ){
        cout << "NIE\n";
        return;
    }
    for(int i = 1; i <= k; i++) wypisz(0);
    int pattern[6] = {1, 0, 1, 1, 0, 0};
    int w = 0;
    for(int i = k+1; i <= n; i++){
        wypisz(pattern[w]);
        if( ++w == 6) w = 0;
    }
    cout << "\n";
}

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