#include <bits/stdc++.h>
using namespace std;
ifstream f("distante.in");
ofstream g("distante.out");
int t, n, m, start, i, j, x, d[50002], dist[50002];
struct graf {
int nod, cost;
bool operator < (const graf &b) const {
return cost > b.cost;
}
};
vector <graf> a[50002];
void dijkstra(int nod) {
priority_queue <graf> pq;
pq.push({nod, 0});
d[nod] = 0;
while (!pq.empty()) {
int x = pq.top().nod;
pq.pop();
for (auto it : a[x]) {
if (d[x] + it.cost < d[it.nod]) {
d[it.nod] = d[x] + it.cost;
pq.push({it.nod, d[it.nod]});
}
}
}
}
int main()
{
f >> t;
while (t--) {
f >> n >> m >> start;
for (int i = 1; i <= n; i++)
f >> dist[i], d[i] = INT_MAX;
while (m--) {
f >> i >> j >> x;
a[i].push_back({j, x});
a[j].push_back({i, x});
}
dijkstra(start);
int ok = 1;
for (int i = 1; i <= n; i++) {
if (dist[i] != d[i]) {
ok = 0;
break;
}
}
if (ok)
g << "DA" << "\n";
else
g << "NU" << "\n";
}
return 0;
}