#include <bits/stdc++.h>
using namespace std;
const int MAX = 50005 ;
int vis[MAX] , arr[MAX] , vis2[MAX];
int n ;
void dijkstra()
{
for(int i = 0 ; i <= 50000 ; ++i)
vis[i] = 1e9+10 ;
priority_queue< pair<int , int> , vector< pair<int , int> > , greater< pair<int , int> > >q ;
q.push({0 , 0}) ;
vis[0] = 0 ;
while(!q.empty())
{
pair<int , int>p = q.top();
q.pop();
int now = p.first , cur = p.second ;
if(vis[cur] < now)
continue;
if(vis2[cur] == 1)
continue ;
vis2[cur] = 1 ;
for(int i = 0 ; i < n ; ++i)
{
int now2 = now + arr[i] ;
int cur2 = (cur + arr[i]) % arr[0] ;
if(now2 > 1e9)
continue ;
if(now2 < vis[cur2] && now2 <= 1e9)
{
vis[cur2] = now2 ;
q.push({now2 , cur2}) ;
}
}
}
return ;
}
int main()
{
scanf("%d" , &n) ;
for(int i = 0 ; i < n ; ++i)
scanf("%d" , &arr[i]) ;
sort(arr , arr + n) ;
dijkstra();
int q ;
scanf("%d" , &q);
while(q--)
{
int x ;
scanf("%d" , &x);
if(vis[x % arr[0]] <= x)
puts("TAK");
else
puts("NIE");
}
return 0 ;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWCA9IDUwMDA1IDsKaW50IHZpc1tNQVhdICwgYXJyW01BWF0gLCB2aXMyW01BWF07CmludCBuIDsKdm9pZCBkaWprc3RyYSgpCnsKICAgIGZvcihpbnQgaSA9IDAgOyBpIDw9IDUwMDAwIDsgKytpKQogICAgICAgIHZpc1tpXSA9IDFlOSsxMCA7CiAgICBwcmlvcml0eV9xdWV1ZTwgcGFpcjxpbnQgLCBpbnQ+ICwgdmVjdG9yPCBwYWlyPGludCAsIGludD4gPiAsIGdyZWF0ZXI8IHBhaXI8aW50ICwgaW50PiA+ID5xIDsKICAgIHEucHVzaCh7MCAsIDB9KSA7CiAgICB2aXNbMF0gPSAwIDsKICAgIHdoaWxlKCFxLmVtcHR5KCkpCiAgICB7CiAgICAgICAgcGFpcjxpbnQgLCBpbnQ+cCA9IHEudG9wKCk7CiAgICAgICAgcS5wb3AoKTsKICAgICAgICBpbnQgbm93ID0gcC5maXJzdCAsIGN1ciA9IHAuc2Vjb25kIDsKICAgICAgICBpZih2aXNbY3VyXSA8IG5vdykKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgaWYodmlzMltjdXJdID09IDEpCiAgICAgICAgICAgIGNvbnRpbnVlIDsKICAgICAgICB2aXMyW2N1cl0gPSAxIDsKICAgICAgICBmb3IoaW50IGkgPSAwIDsgaSA8IG4gOyArK2kpCiAgICAgICAgewogICAgICAgICAgICBpbnQgbm93MiA9IG5vdyArIGFycltpXSA7CiAgICAgICAgICAgIGludCBjdXIyID0gKGN1ciArIGFycltpXSkgJSBhcnJbMF0gOwogICAgICAgICAgICBpZihub3cyID4gMWU5KQogICAgICAgICAgICAgICAgY29udGludWUgOwogICAgICAgICAgICBpZihub3cyIDwgdmlzW2N1cjJdICYmIG5vdzIgPD0gMWU5KQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB2aXNbY3VyMl0gPSBub3cyIDsKICAgICAgICAgICAgICAgIHEucHVzaCh7bm93MiAsIGN1cjJ9KSA7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gOwp9CgppbnQgbWFpbigpCnsKICAgIHNjYW5mKCIlZCIgLCAmbikgOwogICAgZm9yKGludCBpID0gMCA7IGkgPCBuIDsgKytpKQogICAgICAgIHNjYW5mKCIlZCIgLCAmYXJyW2ldKSA7CiAgICBzb3J0KGFyciAsIGFyciArIG4pIDsKICAgIGRpamtzdHJhKCk7CiAgICBpbnQgcSA7CiAgICBzY2FuZigiJWQiICwgJnEpOwogICAgd2hpbGUocS0tKQogICAgewogICAgICAgIGludCB4IDsKICAgICAgICBzY2FuZigiJWQiICwgJngpOwogICAgICAgIGlmKHZpc1t4ICUgYXJyWzBdXSA8PSB4KQogICAgICAgICAgICBwdXRzKCJUQUsiKTsKICAgICAgICBlbHNlCiAgICAgICAgICAgIHB1dHMoIk5JRSIpOwogICAgfQogICAgcmV0dXJuIDAgOwp9