#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("distante.in", "r", stdin);
freopen("distante.out", "w", stdout);
cin.tie(0); ios_base::sync_with_stdio(false);
int T;
cin >> T;
while(T--) {
int N, M, S;
cin >> N >> M >> S;
vector<long long>D(N + 3);
for(int i = 1; i <= N; i++) cin >> D[i];
bool ok = (D[S] == 0);
vector<vector<int>>g(N + 3);
for(int i = 0; i < M; i++) {
int a, b, c;
cin >> a >> b >> c;
if(D[a] + c < D[b] || D[b] + c < D[a]) ok = false;
if(D[a] + c == D[b]) g[a].push_back(b);
if(D[b] + c == D[a]) g[b].push_back(a);
}
if(!ok) {
cout << "NU\n";
continue;
}
vector<int>vis(N + 3);
queue<int>q;
q.push(S);
vis[S] = 1;
int cnt = 0;
while(!q.empty()) {
int u = q.front();
q.pop();
cnt++;
for(int v : g[u]) {
if(!vis[v]) {
vis[v] = 1;
q.push(v);
}
}
}
if(cnt == N) cout << "DA\n";
else cout << "NU\n";
}
}