//
// Created by Irina Manea on 01.12.2026.
//
#include <bits/stdc++.h>
using namespace std;
int main() {
ifstream fin("distante.in");
ofstream fout("distante.out");
int T;
fin >> T;
while (T--) {
int N, M, S;
fin >> N >> M >> S;
vector<long long> D(N + 1);
for (int i = 1; i <= N; i++) fin >> D[i];
bool ok = (D[S] == 0);
vector<int> a(M), b(M), c(M);
for (int i = 0; i < M; i++) {
fin >> a[i] >> b[i] >> c[i];
if (D[a[i]] + c[i] < D[b[i]]) ok = false;
if (D[b[i]] + c[i] < D[a[i]]) ok = false;
}
vector<char> areSuport(N + 1, 0);
areSuport[S] = 1;
for (int i = 0; i < M; i++) {
if (D[a[i]] + c[i] == D[b[i]]) areSuport[b[i]] = 1;
if (D[b[i]] + c[i] == D[a[i]]) areSuport[a[i]] = 1;
}
for (int i = 1; i <= N; i++)
if (!areSuport[i]) ok = false;
fout << (ok ? "DA" : "NU") << "\n";
}
return 0;
}