#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, r, m;
bool ok = true;
cin >> n >> r >> m;
vector<vector<int> > adj(n + 10);
vector<bool> vis(n + 10, false);
vector<bool> done(n + 10, false);
vector<int> dist(n + 10, 0);
vector<pair<int, int>> soldiers;
while (r--) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
while (m--) {
int u, v;
cin >> u >> v;
soldiers.push_back({u, v});
}
for (auto it : soldiers) {
int c = it.first;
int s = it.second;
queue<int> q;
q.push(c);
vis[c] = true; dist[c] = 0;
while (!q.empty()) {
int cur = q.front();
q.pop();
vis[cur] = true;
if (s < dist[cur]) break;
if (done[cur]) {
ok = false; break;
}
for (int v : adj[cur]) {
if (!vis[v]) {
dist[v] = dist[cur] + 1;
if (dist[v] <= s) vis[v] = true;
q.push(v);
}
}
done[cur] = true;
}
if (!ok) break;
}
for (int i = 1; i <= n; i++) {
if (!done[i]) {
ok = false; break;
}
}
cout << (ok ? "YES\n" : "NO\n");
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T;
cin >> T;
while (T--) {
solve();
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBzb2x2ZSgpIHsKICAgIGludCBuLCByLCBtOwogICAgYm9vbCBvayA9IHRydWU7CiAgICBjaW4gPj4gbiA+PiByID4+IG07CiAgICAKICAgIHZlY3Rvcjx2ZWN0b3I8aW50PiA+IGFkaihuICsgMTApOwogICAgdmVjdG9yPGJvb2w+IHZpcyhuICsgMTAsIGZhbHNlKTsKICAgIHZlY3Rvcjxib29sPiBkb25lKG4gKyAxMCwgZmFsc2UpOwogICAgdmVjdG9yPGludD4gZGlzdChuICsgMTAsIDApOwogICAgdmVjdG9yPHBhaXI8aW50LCBpbnQ+PiBzb2xkaWVyczsKCiAgICB3aGlsZSAoci0tKSB7CiAgICAgICAgaW50IHUsIHY7CiAgICAgICAgY2luID4+IHUgPj4gdjsKICAgICAgICBhZGpbdV0ucHVzaF9iYWNrKHYpOwogICAgICAgIGFkalt2XS5wdXNoX2JhY2sodSk7CiAgICB9CiAgICB3aGlsZSAobS0tKSB7CiAgICAgICAgaW50IHUsIHY7CiAgICAgICAgY2luID4+IHUgPj4gdjsKICAgICAgICBzb2xkaWVycy5wdXNoX2JhY2soe3UsIHZ9KTsKICAgIH0KCiAgICBmb3IgKGF1dG8gaXQgOiBzb2xkaWVycykgewogICAgICAgIGludCBjID0gaXQuZmlyc3Q7CiAgICAgICAgaW50IHMgPSBpdC5zZWNvbmQ7CgogICAgICAgIHF1ZXVlPGludD4gcTsKICAgICAgICBxLnB1c2goYyk7CiAgICAgICAgdmlzW2NdID0gdHJ1ZTsgZGlzdFtjXSA9IDA7CgogICAgICAgIHdoaWxlICghcS5lbXB0eSgpKSB7CiAgICAgICAgICAgIGludCBjdXIgPSBxLmZyb250KCk7CiAgICAgICAgICAgIHEucG9wKCk7CiAgICAgICAgICAgIHZpc1tjdXJdID0gdHJ1ZTsKICAgICAgICAgICAgaWYgKHMgPCBkaXN0W2N1cl0pIGJyZWFrOwogICAgICAgICAgICBpZiAoZG9uZVtjdXJdKSB7CiAgICAgICAgICAgICAgICBvayA9IGZhbHNlOyBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBmb3IgKGludCB2IDogYWRqW2N1cl0pIHsKICAgICAgICAgICAgICAgIGlmICghdmlzW3ZdKSB7CiAgICAgICAgICAgICAgICAgICAgZGlzdFt2XSA9IGRpc3RbY3VyXSArIDE7CiAgICAgICAgICAgICAgICAgICAgaWYgKGRpc3Rbdl0gPD0gcykgdmlzW3ZdID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICBxLnB1c2godik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZG9uZVtjdXJdID0gdHJ1ZTsKICAgICAgICB9CgogICAgICAgIGlmICghb2spIGJyZWFrOwogICAgfQoKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgewogICAgICAgIGlmICghZG9uZVtpXSkgewogICAgICAgICAgICBvayA9IGZhbHNlOyBicmVhazsKICAgICAgICB9CiAgICB9CgogICAgY291dCA8PCAob2sgPyAiWUVTXG4iIDogIk5PXG4iKTsKfQoKaW50IG1haW4oKSB7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CgogICAgaW50IFQ7CiAgICBjaW4gPj4gVDsKICAgIHdoaWxlIChULS0pIHsKICAgICAgICBzb2x2ZSgpOwogICAgfQp9