#include <cstdio>
#include <fstream>
#include <vector>
using namespace std;
FILE *fin = fopen("distante.in", "r");
ofstream fout("distante.out");
const int DIM = 1 << 16;
char buffer[DIM + 1];
int pozitie = DIM;
char caracter(){
if (pozitie == DIM){
int citite = fread(buffer, 1, DIM, fin);
buffer[citite] = 0;
pozitie = 0;
}
return buffer[pozitie++];
}
int citeste(){
char c = caracter();
while (c < '0' || c > '9'){
c = caracter();
}
int numar = 0;
while (c >= '0' && c <= '9'){
numar = numar * 10 + (c - '0');
c = caracter();
}
return numar;
}
vector <int> tata;
int gaseste(int x){
int radacina = x;
while (tata[radacina] != radacina){
radacina = tata[radacina];
}
while (tata[x] != radacina){
int aux = tata[x];
tata[x] = radacina;
x = aux;
}
return radacina;
}
int main(){
int T = citeste();
for (int t = 0; t < T; t++){
int N = citeste(), M = citeste(), S = citeste();
vector <int> distanta(N + 1);
for (int i = 1; i <= N; i++){
distanta[i] = citeste();
}
bool corect = (distanta[S] == 0);
tata.resize(N + 1);
for (int i = 1; i <= N; i++){
tata[i] = i;
}
vector <bool> arePredecesor(N + 1, false);
for (int i = 0; i < M; i++){
int a = citeste(), b = citeste(), c = citeste();
if (distanta[a] + c < distanta[b] || distanta[b] + c < distanta[a]){
corect = false;
}
if (c == 0 && distanta[a] == distanta[b]){
tata[gaseste(a)] = gaseste(b);
}
else if (distanta[a] + c == distanta[b]){
arePredecesor[b] = true;
}
else if (distanta[b] + c == distanta[a]){
arePredecesor[a] = true;
}
}
vector <bool> grupBun(N + 1, false);
for (int i = 1; i <= N; i++){
if (arePredecesor[i]){
grupBun[gaseste(i)] = true;
}
}
grupBun[gaseste(S)] = true;
for (int i = 1; i <= N; i++){
if (!grupBun[gaseste(i)]){
corect = false;
}
}
fout << (corect ? "DA" : "NU") << "\n";
}
return 0;
}