#include <bits/stdc++.h>
using namespace std;
int INF = 2000000000,A[5005],dist[50005];
set < pair<int,int> > dijk;
int main()
{
// freopen("input.txt", "r", stdin);
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i)
{
scanf("%d", &A[i]);
}
for (int i = 0; i < A[0]; ++i)
{
dist[i] = INF;
}
dist[0] = 0;
dijk.insert(make_pair(dist[0],0));
while(!dijk.empty())
{
pair<int,int> top = *dijk.begin();
dijk.erase(top);
int v = top.second;
int d = top.first;
for (int i = 1; i < n; ++i)
{
int d2 = d+A[i];
int v2 = (v+A[i])%A[0];
if(d2 < dist[v2])
{
if(dist[v2] < INF)
dijk.erase(make_pair(dist[v2],v2));
dist[v2] = d2;
dijk.insert(make_pair(dist[v2],v2));
}
}
}
int k;
scanf("%d", &k);
while(k--)
{
int x;
scanf("%d", &x);
if(dist[x%A[0]] <= x)
printf("TAK\n");
else
printf("NIE\n");
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBJTkYgPSAyMDAwMDAwMDAwLEFbNTAwNV0sZGlzdFs1MDAwNV07CnNldCA8IHBhaXI8aW50LGludD4gPiBkaWprOwppbnQgbWFpbigpCnsKCS8vIGZyZW9wZW4oImlucHV0LnR4dCIsICJyIiwgc3RkaW4pOwoJaW50IG47CglzY2FuZigiJWQiLCAmbik7Cglmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkKCXsKCQlzY2FuZigiJWQiLCAmQVtpXSk7Cgl9Cglmb3IgKGludCBpID0gMDsgaSA8IEFbMF07ICsraSkKCXsKCQlkaXN0W2ldID0gSU5GOwoJfQoJZGlzdFswXSA9IDA7CglkaWprLmluc2VydChtYWtlX3BhaXIoZGlzdFswXSwwKSk7Cgl3aGlsZSghZGlqay5lbXB0eSgpKQoJewoJCXBhaXI8aW50LGludD4gdG9wID0gKmRpamsuYmVnaW4oKTsKCQlkaWprLmVyYXNlKHRvcCk7CgkJaW50IHYg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