#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int maxn=3e5+10;
vector<int>v[maxn];
int in[maxn], ja[maxn];
map<pii,int>nope;
set<int>s;
vector<pii>resp;
void dfs(int u){
s.erase(u);
auto f=s.begin();
while(f!=s.end()){
int viz=*f;
if(nope[{u,viz}]){
f=s.upper_bound(viz);
continue;
}
resp.push_back({viz,u});
dfs(viz);
f=s.upper_bound(viz);
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n, m, k; cin >> n >> m >> k;
for(int i=1;i<=m;i++){
int a, b; cin >> a >> b;
v[a].push_back(b);
in[b]++;
resp.push_back({a,b});
}
auto topo_sort=[&](){
queue<int>q;
for(int i=0;i<n;i++){
if(v[i].size()>1) return false;
if(!in[i]) q.push(i);
if(v[i].size()) ja[i]++;
}
while(!q.empty()){
int u=q.front(); q.pop();
for(int viz : v[u]){
in[viz]--;
if(!in[viz]) q.push(viz);
}
}
for(int i=0;i<n;i++) if(in[i]) return false;
return true;
};
if(!topo_sort()){
cout << "NO\n";
return 0;
}
for(int i=1;i<=k;i++){
int a, b; cin >> a >> b;
nope[{b,a}]=1;
}
auto get_root=[&](){
for(int i=0;i<n;i++) if(!ja[i]) s.insert(i);
int ret=0;
for(int i=0;i<n;i++){
if(s.find(i)!=s.end()){
ret=i;
dfs(i);
}
}
return ret;
};
auto test=[&](int x){
s.clear();
for(int i=0;i<n;i++) if(!ja[i]) s.insert(i);
dfs(x);
if(s.empty()) for(pii p : resp) cout << p.fi << ' ' << p.se << '\n';
else cout << "NO\n";
};
int r=get_root();
test(r);
}