#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+cCA9IHEudG9wKCk7CiAgICAgICAgcS5wb3AoKTsKICAgICAgICBpbnQgbm93ID0gcC5maXJzdCAsIGN1ciA9IHAuc2Vjb25kIDsKICAgICAgICBpZih2aXNbY3VyXSA8IG5vdykKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgaWYodmlzMltjdXJdID09IDEpCiAgICAgICAgICAgIGNvbnRpbnVlIDsKICAgICAgICB2aXMyW2N1cl0gPSAxIDsKICAgICAgICBmb3IoaW50IGkgPSAwIDsgaSA8IG4gOyArK2kpCiAgICAgICAgewogICAgICAgICAgICBpbnQgbm93MiA9IG5vdyArIGFycltpXSA7CiAgICAgICAgICAgIGludCBjdXIyID0gKGN1ciArIGFycltpXSkgJSBhcnJbMF0gOwogICAgICAgICAgICAvL2lmKG5vdzIgPiAxZTkpCiAgICAgICAgICAgIC8vICAgIGNvbnRpbnVlIDsKICAgICAgICAgICAgaWYobm93MiA8IHZpc1tjdXIyXSAmJiBub3cyIDw9IDFlOSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdmlzW2N1cjJdID0gbm93MiA7CiAgICAgICAgICAgICAgICBxLnB1c2goe25vdzIgLCBjdXIyfSkgOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDsKfQoKaW50IG1haW4oKQp7CiAgICBzY2FuZigiJWQiICwgJm4pIDsKICAgIGZvcihpbnQgaSA9IDAgOyBpIDwgbiA7ICsraSkKICAgICAgICBzY2FuZigiJWQiICwgJmFycltpXSkgOwogICAgc29ydChhcnIgLCBhcnIgKyBuKSA7CiAgICBkaWprc3RyYSgpOwogICAgaW50IHEgOwogICAgc2NhbmYoIiVkIiAsICZxKTsKICAgIHdoaWxlKHEtLSkKICAgIHsKICAgICAgICBpbnQgeCA7CiAgICAgICAgc2NhbmYoIiVkIiAsICZ4KTsKICAgICAgICBpZih2aXNbeCAlIGFyclswXV0gPD0geCkKICAgICAgICAgICAgcHV0cygiVEFLIik7CiAgICAgICAgZWxzZQogICAgICAgICAgICBwdXRzKCJOSUUiKTsKICAgIH0KICAgIHJldHVybiAwIDsKfQ==