#include<iostream>
#include<queue>
#include<vector>
#include<fstream>
using namespace std;
ifstream fin("distante.in");
ofstream fout("distante.out");
const int INF=1000000000;
int main(){
int nrGrafuri;
fin>>nrGrafuri;
while(nrGrafuri){
int n,m,s;
fin>>n>>m>>s;
vector<int>distante(n+1);
for(int i=1; i<=n; i++)
fin >> distante[i];
vector<vector<pair<int,int>>>graf(n+1);
for(int i=1;i<=m;i++){
int x,y,z;
fin>>x>>y>>z;
graf[x].push_back({y,z});
graf[y].push_back({x,z});
}
vector<int>dist(n+1,INF);
dist[s] = 0;
priority_queue<pair<int,int>,
vector<pair<int,int>>,
greater<pair<int,int>>
>pq;
pq.push({0,s});
while(!pq.empty()){
auto[d,x]=pq.top();
pq.pop();
if(d != dist[x])
continue;
for(auto[y,cost]:graf[x]){
if(dist[y]>dist[x]+cost){
dist[y]=dist[x]+cost;
pq.push({dist[y],y});
}
}
}
bool corect = true;
for(int i=1;i<=n;i++){
if(dist[i]!=distante[i]){
corect=false;
break;
}
}
if(corect)
fout<<"DA\n";
else
fout<<"NU\n";
nrGrafuri--;
}
}