#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
const int N_MAX = 50005;
const int INF = 1e9;
vector<pair<int, int>> adj[N_MAX];
int dist[N_MAX];
int D[N_MAX];
void dijkstra(int start, int N) {
for (int i = 1; i <= N; i++) {
dist[i] = INF;
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
dist[start] = 0;
pq.push({0, start});
while (!pq.empty()) {
int d = pq.top().first;
int u = pq.top().second;
pq.pop();
if (d > dist[u]) {
continue;
}
for (auto muchie : adj[u]) {
int v = muchie.first;
int cost = muchie.second;
if (dist[u] + cost < dist[v]) {
dist[v] = dist[u] + cost;
pq.push({dist[v], v});
}
}
}
}
int main() {
freopen("distante.in", "r", stdin);
freopen("distante.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
if (!(cin >> T)) return 0;
while (T--) {
int N, M, S;
cin >> N >> M >> S;
for (int i = 1; i <= N; i++) {
adj[i].clear();
cin >> D[i];
}
for (int i = 0; i < M; i++) {
int a, b, c;
cin >> a >> b >> c;
adj[a].push_back({b, c});
adj[b].push_back({a, c});
}
dijkstra(S, N);
bool ok = true;
for (int i = 1; i <= N; i++) {
if (dist[i] != D[i]) {
ok = false;
break;
}
}
if (ok) {
cout << "DA\n";
} else {
cout << "NU\n";
}
}
return 0;
}