#include <bits/stdc++.h>
using namespace std;
int main() {
ifstream fin("distante.in");
ofstream fout("distante.out");
int T;
fin >> T;
while (T--) {
int n, m, S;
fin >> n >> m >> S;
vector<int> d(n + 1);
for (int i = 1; i <= n; i++) {
fin >> d[i];
}
vector<vector<pair<int, int>>> graf(n + 1);
for (int i = 1; i <= m; i++) {
int x, y, cost;
fin >> x >> y >> cost;
graf[x].push_back({y, cost});
graf[y].push_back({x, cost});
}
bool corect = true;
if (d[S] != 0)
corect = false;
for (int i = 1; i <= n; i++) {
if (i == S)
continue;
bool gasit = false;
for (auto muchie : graf[i]) {
int vecin = muchie.first;
int cost = muchie.second;
if (d[vecin] + cost == d[i]) {
gasit = true;
break;
}
}
if (!gasit)
corect = false;
}
for (int i = 1; i <= n; i++) {
for (auto muchie : graf[i]) {
int vecin = muchie.first;
int cost = muchie.second;
if (abs(d[i] - d[vecin]) > cost) {
corect = false;
}
}
}
if (corect)
fout << "DA\n";
else
fout << "NU\n";
}
return 0;
}