#include <fstream>
using namespace std;
ifstream fin("distante.in");
ofstream fout("distante.out");
const int MAXN = 50005;
int D[MAXN];
bool ok[MAXN];
int main()
{
int T;
if (!(fin >> T))
return 0;
while (T--)
{
int n, m, s;
fin >> n >> m >> s;
for (int i = 1; i <= n; ++i)
{
fin >> D[i];
ok[i] = false;
}
bool valid = true;
// Conditia 1: distanta pana la sursa trebuie sa fie 0
if (D[s] != 0)
{
valid = false;
}
ok[s] = true; // Sursa nu are nevoie de parinte
for (int i = 1; i <= m; ++i)
{
int x, y, c;
fin >> x >> y >> c;
// Conditia 2: nicio muchie nu trebuie sa ofere o scurtatura
if (D[x] > D[y] + c || D[y] > D[x] + c)
{
valid = false;
}
// Conditia 3: verificam daca muchia justifica distanta optima pentru x sau y
if (D[x] == D[y] + c)
{
ok[x] = true;
}
if (D[y] == D[x] + c)
{
ok[y] = true;
}
}
// Verificam daca toate nodurile au fost justificate de cel putin o muchie
for (int i = 1; i <= n; ++i)
{
if (!ok[i])
{
valid = false;
break;
}
}
if (valid)
{
fout << "DA\n";
}
else
{
fout << "NU\n";
}
}
return 0;
}