//EGOI 2023 Sopsug
//https://qoj.ac/contest/1355/problem/7160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
const ll MAXN = 3e5+5;
vll g[MAXN], uf(MAXN,-1); set<ll> notCan[MAXN], notVis;
ll ufind(ll v){
if(uf[v]<0) return v;
return uf[v]=ufind(uf[v]);
}
bool unite(ll v,ll u){
v=ufind(v); u=ufind(u);
if(v==u) return false;
uf[v]=u; return true;
}
void dfs(ll v, vector<pair<ll,ll>> &ans){
notVis.erase(v); vll childs;
for(auto u:notVis) if(!notCan[u].count(v)) childs.push_back(u);
for(auto u:g[v]) childs.push_back(u);
for(auto u:childs) notVis.erase(u), ans.push_back({u,v});
for(auto u:childs) dfs(u,ans);
}
int main(){
ll n, m, k, a, b, root=-1;
cin >> n >> m >> k;
vll cand; vector<pair<ll,ll>> ans, temp;
for(int i=0; i<m; i++){
cin >> a >> b; g[b].push_back(a);
if(ufind(a)!=a || !unite(a,b)){cout << "NO\n"; return 0;}
}
for(int i=0; i<k; i++) cin >> a >> b, notCan[a].insert(b);
for(int i=0; i<n; i++) if(ufind(i)==i) cand.push_back(i);
for(auto v:cand) notVis.insert(v);
for(auto v:cand) if(notVis.count(v)) root=v, dfs(v,temp);
for(auto v:cand) notVis.insert(v);
dfs(root,ans);
if((ll)ans.size()!=n-1){cout << "NO\n"; return 0;}
for(auto [a,b]:ans) cout << a << " " << b << "\n";
}