#include<bits/stdc++.h>
using namespace std;
#define mod 1000007
#define inf 0x3f
#define re register
#define maxn 100000
#define ll long long
int n,m,w,cnt,dist[10010][10010];
int h=1,t=1;
short q[50000010];
struct Edge
{
int to,c,next;
}edge[10010];
int head[10010];
void add(int s,int t)
{
edge[cnt].to=t;
edge[cnt].next=head[s];
head[s]=cnt++;
}
void pre()
{
memset(head,-1,sizeof(head));
cnt=0;
}
void sss(int s)
{
q[1]=s;
h=1;
t=1;
while(h<=t)
{
int x=q[h];
h++;
for(re int i=head[x];i!=-1;i=edge[i].next)
{
int j=edge[i].to;
if(!dist[s][j])
{
dist[s][j]=dist[s][x]+1;
q[++t]=j;
}
}
}
}
inline int read(){
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9') {if(ch=='-')f=-1; ch=getchar();}
while (ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0'; ch=getchar();}
return x*f;
}
int main()
{
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
// printf("%dM\n",(sizeof(dp) >> 20))
cin>>n>>m>>w;
pre();
memset(dist,0,sizeof(dist));
for(re int i=1;i<=m;++i)
{
int a,b;
a=read(),b=read();
add(a,b+n);
add(b,a+n);
}
for(re int i=1;i<=n;i++)
sss(i);
// cout<<dist[5][5]<<' '<<dist[5][5+n]<<endl;
for(re int i=1;i<=w;++i)
{
int a,b,c;
a=read(),b=read(),c=read();
if(c%2==1)
if(dist[a][b+n]&&c>=dist[a][b+n])
{
puts("TAK");
continue;
}
if(c%2==0)
if(dist[a][b]&&c>=dist[a][b])
{
puts("TAK");
continue;
}
puts("NIE");
}
return 0;
}