#include <stdio.h>
#include <string.h>
#define MAXN 50000
#define MAXM 100000
int ut[MAXN], nd[2 * MAXM], nxt[2 * MAXM], cost[2 * MAXM], dr;
int dist[MAXN], q[MAXN], sq, dq;
char bun[MAXN];
inline void add(int x, int y, int z){
nd[dr] = y;
nxt[dr] = ut[x];
ut[x] = dr;
cost[dr] = z;
dr++;
}
inline int verif(int s, int n){
if(dist[s] != 0)
return 0;
memset(bun, 0, sizeof bun);
bun[s] = 1;
q[0] = s;
dq = 1;
sq = 0;
int poz, nod;
while(sq < dq){
nod = q[sq];
sq++;
poz = ut[nod];
while(poz != -1){
if(dist[nod] + cost[poz] < dist[nd[poz]])
return 0;
if(!bun[nd[poz]] && dist[nod] + cost[poz] == dist[nd[poz]]){
bun[nd[poz]] = 1;
q[dq] = nd[poz];
dq++;
}
poz = nxt[poz];
}
}
int i;
for(i = 0; i < n; i++)
if(!bun[i])
return 0;
return 1;
}
int main(){
FILE *in = fopen("distante.in", "r");
FILE *out = fopen("distante.out", "w");
int t, n, m, s, x, y, z, i;
char rez;
fscanf(in, "%d", &t);
for(; t > 0; t--){
fscanf(in, "%d%d%d", &n, &m, &s);
s--;
memset(ut, -1, sizeof ut);
for(i = 0; i < n; i++)
fscanf(in, "%d", &dist[i]);
dr = 0;
for(i = 0; i < m; i++){
fscanf(in, "%d%d%d", &x, &y, &z);
x--; y--;
add(x, y, z);
add(y, x, z);
}
rez = verif(s, n);
if(rez == 0)
fprintf(out, "NU\n");
else
fprintf(out, "DA\n");
}
fclose(in);
fclose(out);
return 0;
}