#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream f("distante.in");
ofstream g("distante.out");
vector< pair<int, int> > a[50001];
int D[50001], d[50001];
int main()
{
int t, n, m, s, i, x, y, c, ok, nod, vec, cost, k;
f >> t;
while (t--)
{
f >> n >> m >> s;
for (i = 1; i <= n; i++)
{
f >> D[i];
a[i].clear();
d[i] = 2000000000;
}
for (i = 1; i <= m; i++)
{
f >> x >> y >> c;
a[x].push_back(make_pair(y, c));
a[y].push_back(make_pair(x, c));
}
priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > q;
d[s] = 0; //nodul de pornire
q.push(make_pair(0, s));
while (!q.empty())
{
int dist = q.top().first;
nod = q.top().second;
q.pop();
if (dist > d[nod])
continue;
for (k = 0; k < a[nod].size(); k++)
{
vec = a[nod][k].first;
cost = a[nod][k].second;
if (d[nod] + cost < d[vec])//relaxarea
{
d[vec] = d[nod] + cost;
q.push(make_pair(d[vec], vec));
}
}
}
ok = 1;
for (i = 1; i <= n; i++)
if (d[i] != D[i])
ok = 0;
if (ok == 1)
g << "DA\n";
else
g << "NU\n";
}
return 0;
}