#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n,m,k;
cin>>n>>m>>k;
vector<vector<ll>>e(n,vector<ll>(m));
for(ll j=0;j<m;j++)
{
for(ll i=0;i<n;i++)
{
cin>>e[i][j];
e[i][j]--;
}
}
vector<ll>c(n,-1);
for(ll i=0;i<n;i++)
{
if(c[i]!=-1)
{
continue;
}
queue<ll>q({i});
while(!q.empty())
{
ll x=q.front();
q.pop();
if(c[x]==i)
{
continue;
}
c[x]=i;
for(ll y:e[x])
{
q.push(y);
}
}
}
while(k--)
{
ll x,y;
cin>>x>>y;
x--;
y--;
if(c[x]==c[y])
{
cout<<"DA"<<endl;
}
else
{
cout<<"NE"<<endl;
}
}
return 0;
}