#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<dos.h>
#define NMAX 50010
#define oo 1000000
FILE *f=fopen("distante.in","r");
FILE *g=fopen("distante.out","w");
struct nod{
int nd;
int ct;
/*nod(){
nd=0;ct=0;
urm = NULL;
}*/
};
nod * G[NMAX];
int D[NMAX];
int t,S,n,m,lh;
int d[NMAX],h[NMAX],p[NMAX];
int gr[NMAX];
inline void swap(int &a, int &b){ int aux= a; a=b; b=aux; }
void up(int x){
int t;
while(x>1){
t = x>>1;
if(d[h[x]] < d[h[t]]){
swap(h[x],h[t]);
p[x]=t;
p[t]=x;
x=t;
}else return;
}
}
void down(int x){
int f;
while(x<=lh){
f=x<<1;
if(f<=lh){
if(f+1<=lh)
if(d[h[f]]>d[h[f+1]]) f++;
}else return;
if(d[h[x]]>d[h[f]]){
swap(h[x],h[f]);
p[h[x]]=f;
p[h[f]]=x;
x=f;
}else return;
}
}
inline void push(int x){
h[++lh] = x;
p[h[lh]] = lh;
up(lh);
}
inline void pop() {
swap(h[1],h[lh--]);
p[h[1]]=1;
down(1);
}
void dijkstra(){
memset(d,oo,sizeof(d));
memset(p,-1,sizeof(p));
memset(h,0,sizeof(h));
lh = 0;
d[S]=0;
push(S);
int min;
while(lh){
min = h[1];
pop();
int i;
for(i=1;i<=gr[min];i++){
if(d[G[min][i].nd] > d[min] + G[min][i].ct ){
d[G[min][i].nd] = d[min] + G[min][i].ct;
if(p[G[min][i].nd]==-1) push(G[min][i].nd);
else down(p[G[min][i].nd]);
}
}
}
}
int ok(){
for(int i=1;i<=n;i++) if(D[i]!=d[i]) return 0;
return 1;
};
inline void ADD(int p, int x, int c){
gr[p]++;
G[p] =(nod*)realloc(G[p],(gr[p]+1)*sizeof(nod));
G[p][gr[p]].nd=x;
G[p][gr[p]].ct=c;
}
void date_graf(){
int i,x,y,c;
memset(gr,0,sizeof(gr));
for(i=1;i<=n;i++){G[i]=(nod*)realloc(G[i],sizeof(int));G[i]=0;}
fscanf(f,"%d%d%d",&n,&m,&S);
for(i=1;i<=n;i++) fscanf(f,"%d",D+i);
for(i=1;i<=m;i++){
fscanf(f,"%d%d%d",&x,&y,&c);
ADD(x,y,c);
ADD(y,x,c);
}
}
int main(){
fscanf(f,"%d",&t);
for( ; t -- ; ){
date_graf();
dijkstra();
if(ok()) fprintf(g,"DA\n");
else fprintf(g,"NU\n");
}
return 0;
}