#include <fstream>
#include <vector>
#include <queue>
#define INF (1LL<<31)-1
using namespace std;
ifstream f("distante.in"); ofstream g("distante.out");
int t,n,m,s,db[50001],dist[50001],viz[50001],a,b,c;
vector <pair<int,int> > G[50001];
struct cmp
{ bool operator()(int x,int y)
{ return dist[x]>dist[y]; }
};
priority_queue<int,vector<int>,cmp> pq;
bool dijkstra()
{ for(int i=1;i<=n;i++)
{ dist[i]=INF;
viz[s]=0;
}
dist[s]=0;
pq.push(s);
viz[s]=1;
while(!pq.empty())
{ int aux=pq.top();
pq.pop();
viz[aux]=0;
for(size_t i=0;i<G[aux].size();i++){
if(dist[aux]+G[aux][i].second<dist[G[aux][i].first])
{ dist[G[aux][i].first]=dist[aux]+G[aux][i].second;
if(!viz[G[aux][i].first])
{ viz[G[aux][i].first]=1;
pq.push(G[aux][i].first);
}
}
}
}
for(int i=1;i<=n;i++)
if(dist[i]!=db[i]) return false;
return true;
}
int main()
{ f>>t;
while(t--)
{ f>>n>>m>>s;
for(int i=1;i<=n;i++)
{ f>>db[i];
G[i].clear();
}
for(int i=1;i<=m;i++)
{ f>>a>>b>>c;
G[a].push_back(make_pair(b,c));
G[b].push_back(make_pair(a,c));
}
if(dijkstra()) g<<"DA"<<'\n';
else g<<"NU"<<'\n';
}
g.close(); return 0;
}