#include <fstream>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
struct muc{
int surs, dest, cost; };
bool check_dist(const vector<muc>& graf, const vector<int>& dist, const int surs){
const int n = dist.size();
vector<bool> ver(n, false);
if(dist[surs] != 0){
return false; }
ver[surs] = true;
for(const auto x : graf){
if(dist[x.surs] + x.cost == dist[x.dest]){
ver[x.dest] = true; }
if(dist[x.surs] + x.cost < dist[x.dest]){
return false; } }
for(const auto x : ver){
if(!x){
return false; } }
return true; }
void do_test(ifstream& f, ofstream& g){
int n, m, s;
f >> n >> m >> s;
--s;
vector<int> dist(n);
for(auto& x : dist){
f >> x; }
vector<muc> graf(2*m);
for(int i = 0; i < m; ++i){
f >> graf[i].surs >> graf[i].dest >> graf[i].cost;
--graf[i].surs, --graf[i].dest;
graf[i+m].surs = graf[i].dest;
graf[i+m].dest = graf[i].surs;
graf[i+m].cost = graf[i].cost; }
if(check_dist(graf, dist, s)){
g << "DA\n"; }
else{
g << "NU\n"; } }
int main(){
ifstream f("distante.in");
ofstream g("distante.out");
int t;
f >> t;
for(int i = 0; i < t; ++i){
do_test(f, g); }
return 0; }