///O(T * (n + m) log n)
#include <fstream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;
int main() {
ifstream in("distante.in");
ofstream out("distante.out");
int T;
in >> T;
while (T--) {
int n, m, s;
in >> n >> m >> s;
vector<long long> claimed(n + 1);
for(int i = 1; i <= n; i++)
in >> claimed[i];
vector<vector<pair<int, int>>> adj(n + 1); ///(vecin, cost)
for(int i = 0; i < m; i++) {
int a, b, c;
in >> a >> b >> c;
adj[a].push_back({b, c});
adj[b].push_back({a, c});
}
///Dijkstra
vector<long long> dist(n + 1, LLONG_MAX);
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<>> pq;
dist[s] = 0;
pq.push({0, s});
while (!pq.empty()) {
auto [d, u] = pq.top();
pq.pop();
if (d > dist[u]) continue; ///intrare veche, ignor
for (auto [v, c] : adj[u])
if (dist[u] + c < dist[v]) {
dist[v] = dist[u] + c;
pq.push({dist[v], v});
}
}
///corect daca toate dist calculate coincid cu cele date
bool ok = true;
for (int i = 1; i <= n && ok; i++)
if (dist[i] != claimed[i])
ok = false;
out << (ok ? "DA" : "NU") << '\n';
}
return 0;
}