#include <cstdio>
const int NMAX = 50005;
const int MMAX = 100005;
const int BUFSIZE = 1 << 16;
FILE *fin = fopen("distante.in", "r");
FILE *fout = fopen("distante.out", "w");
char buf[BUFSIZE];
int bufPos = BUFSIZE;
char readChar() {
if (bufPos == BUFSIZE) {
fread(buf, 1, BUFSIZE, fin);
bufPos = 0;
}
return buf[bufPos++];
}
int readInt() {
char c = readChar();
while (c < '0' || c > '9')
c = readChar();
int x = 0;
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = readChar();
}
return x;
}
int n, m, s;
int dist[NMAX];
int ea[MMAX], eb[MMAX], ec[MMAX];
int head[NMAX], nxt[2 * MMAX], to[2 * MMAX];
int edgeCount;
bool seen[NMAX];
int bfsQueue[NMAX];
void addEdge(int x, int y) {
to[++edgeCount] = y;
nxt[edgeCount] = head[x];
head[x] = edgeCount;
}
int main() {
int t = readInt();
while (t--) {
n = readInt();
m = readInt();
s = readInt();
for (int i = 1; i <= n; i++) {
dist[i] = readInt();
head[i] = 0;
seen[i] = false;
}
edgeCount = 0;
bool ok = dist[s] == 0;
for (int i = 0; i < m; i++) {
int x = readInt();
int y = readInt();
int c = readInt();
if (dist[x] + c < dist[y] || dist[y] + c < dist[x])
ok = false;
if (dist[x] + c == dist[y])
addEdge(x, y);
if (dist[y] + c == dist[x])
addEdge(y, x);
}
if (ok) {
int qHead = 0, qTail = 0;
bfsQueue[qTail++] = s;
seen[s] = true;
while (qHead < qTail) {
int node = bfsQueue[qHead++];
for (int e = head[node]; e; e = nxt[e])
if (!seen[to[e]]) {
seen[to[e]] = true;
bfsQueue[qTail++] = to[e];
}
}
ok = qTail == n;
}
fputs(ok ? "DA\n" : "NU\n", fout);
}
return 0;
}