#include <vector>
#include <fstream>
using namespace std;
ifstream fin("distante.in");
ofstream fout("distante.out");
struct muchie {
int x, y, c;
muchie() = default;
muchie(int x, int y, int c) : x(x), y(y), c(c) {}
};
int main() {
int T, N, M, S, X, Y, C;
fin >> T;
for (int t = 1; t <= T; t++) {
fin >> N >> M >> S;
vector<int> D(N+1);
vector<muchie> E(N+1);
for (int i = 1; i <= N; i++) {
fin >> D[i];
}
for (int i = 1; i <= M; i++) {
fin >> X >> Y >> C;
E[i] = muchie(X, Y, C);
}
bool ok = (D[S] == 0);
vector<bool> drum_scurt_gasit(N + 1, false);
drum_scurt_gasit[S] = true;
for (muchie& m : E) {
if (D[m.x] > D[m.y] + m.c || D[m.y] > D[m.x] + m.c) {
ok = false;
break;
}
if (D[m.y] == D[m.x] + m.c) drum_scurt_gasit[m.y] = true;
if (D[m.x] == D[m.y] + m.c) drum_scurt_gasit[m.x] = true;
}
for (int i = 1; i <= N; i++) {
if (!drum_scurt_gasit[i]) {
ok = false;
break;
}
}
fout << (ok ? "DA" : "NU") << '\n';
}
}