#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream f("distante.in");
ofstream o("distante.out");
int t, n, m, s, D[50001], dist[50001];
vector<pair<int,int> > g[50001];
int main() {
f >> t;
while (t--) {
f >> n >> m >> s;
for (int i = 1; i <= n; i++) {
f >> D[i];
g[i].clear();
dist[i] = 1 << 30;
}
for (int i = 0; i < m; i++) {
int a, b, c;
f >> a >> b >> c;
g[a].push_back(make_pair(b, c));
g[b].push_back(make_pair(a, c));
}
priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > pq;
dist[s] = 0;
pq.push(make_pair(0, s));
while (!pq.empty()) {
int d = pq.top().first;
int u = pq.top().second;
pq.pop();
if (d > dist[u]) continue;
for (int i = 0; i < (int)g[u].size(); i++) {
int v = g[u][i].first;
int c = g[u][i].second;
if (dist[u] + c < dist[v]) {
dist[v] = dist[u] + c;
pq.push(make_pair(dist[v], v));
}
}
}
bool ok = true;
for (int i = 1; i <= n; i++)
if (dist[i] != D[i]) ok = false;
if (ok) o << "DA\n";
else o << "NU\n";
}
}//
// Created by daria on 12/2/2026.
//