Problem: One-Way Conveyors

You are working at a factory manufacturing many different products. Products have to be processed on a number of different machine tools. Machine shops with these machines are connected with conveyor lines to exchange unfinished products. Each unfinished product is transferred from a machine shop to another through one or more of these conveyors.

As the orders of the processes required are not the same for different types of products, the conveyor lines are currently operated in two-way. This may induce inefficiency as conveyors have to be completely emptied before switching their directions. Kaizen (efficiency improvements) may be found here!

Adding more conveyors is too costly. If all the required transfers are possible with currently installed conveyors operating in fixed directions, no additional costs are required. All the required transfers, from which machine shop to which, are listed at hand. You want to know whether all the required transfers can be enabled with all the conveyors operated in one-way, and if yes, directions of the conveyor lines enabling it.

Input

The input consists of a single test case of the following format.


$n$ $m$
$x_1$ $y_1$
.
.
.
$x_m$ $y_m$
$k$
$a_1$ $b_1$
.
.
.
$a_k$ $b_k$


The first line contains two integers $n$ ($2 \leq n \leq 10 000$) and $m$ ($1 \leq m \leq 100 000$), the number of machine shops and the number of conveyors, respectively. Machine shops are numbered $1$ through $n$. Each of the following $m$ lines contains two integers $x_i$ and $y_i$ ($1 \leq x_i < y_i \leq n$), meaning that the $i$-th conveyor connects machine shops $x_i$ and $y_i$. At most one conveyor is installed between any two machine shops. It is guaranteed that any two machine shops are connected through one or more conveyors. The next line contains an integer $k$ ($1 \leq k \leq 100 000$), which indicates the number of required transfers from a machine shop to another. Each of the following $k$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i \leq n$, $1 \leq b_i \leq n$, $a_i \ne b_i$), meaning that transfer from the machine shop $a_i$ to the machine shop $b_i$ is required. Either $a_i \ne a_j$ or $b_i \ne b_j$ holds for $i \ne j$.

Output

Output “No” if it is impossible to enable all the required transfers when all the conveyors are operated in one-way. Otherwise, output “Yes” in a line first, followed by $m$ lines each of which describes the directions of the conveyors. All the required transfers should be possible with the conveyor lines operated in these directions. Each direction should be described as a pair of the machine shop numbers separated by a space, with the start shop number on the left and the end shop number on the right. The order of these $m$ lines do not matter as far as all the conveyors are specified without duplicates or omissions. If there are multiple feasible direction assignments, whichever is fine.

Sample Input 1


3 2
1 2
2 3
3
1 2
1 3
2 3


Sample Output 1


Yes
1 2
2 3


Sample Input 2


3 2
1 2
2 3
3
1 2
1 3
3 2


Sample Output 2


No


Sample Input 3


4 4
1 2
1 3
1 4
2 3
7
1 2
1 3
1 4
2 1
2 3
3 1
3 2


Sample Output 3


Yes
1 2
2 3
3 1
1 4






Example

Input

3 2
1 2
2 3
3
1 2
1 3
2 3


Output

Yes
1 2
2 3

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define N 10050
using namespace std;
clock_t st;
int n, m, K, e = 2, head[N], dfn[N], low[N], tot, tim, bo[N * 20], ok[N * 20], be[N], Dp[N];
int fa[N][18], rt[N], dep[N], pp[N], a[N], b[N], dta[N], dtb[N];
struct edge{int u, v, next;}ed[N * 20];
void add(int u, int v){ed[e].u = u; ed[e].v = v; ed[e].next = head[u]; head[u] = e++;}
vector<pair<int, int> > V[N];
vector<int> vr;
int cnt = 0;
void tarjan(int x, int fa){
	++cnt;
	if(cnt > 100000) assert(0);
	dfn[x] = low[x] = ++tim;
	for(int i = head[x]; i; i = ed[i].next){
		int v = ed[i].v;
		if(!dfn[v]){
			tarjan(v, x);
			low[x] = min(low[x], low[v]);
			if(low[v] > dfn[x]) bo[i] = bo[i ^ 1] = 1;
		}
		else if(dfn[v] < dfn[x] && v != fa)
			low[x] = min(low[x], dfn[v]);
	}
}
void dfs(int x, int d, int fa){
	be[x] = tot; Dp[x] = d;
	for(int i = head[x]; i; i = ed[i].next){
		if(bo[i]) continue;
		int v = ed[i].v;
		if(!be[v]) {ok[i] = 1; dfs(v, d + 1, x);}
		else if(v != fa && Dp[v] < Dp[x]) {ok[i] = 1;}
	}
}
void dfs(int x, int root){
	rt[x] = root;
	for(int i = 1; (1 << i) <= dep[x]; i++)
		fa[x][i] = fa[fa[x][i - 1]][i - 1];
	for(int i = 0; i < (int)V[x].size(); i++){
		int v = V[x][i].first;
		if(v == fa[x][0]) continue;
		pp[v] = V[x][i].second;
		fa[v][0] = x;
		dep[v] = dep[x] + 1;
		dfs(v, root);
	}
}
int getlca(int x, int y){
	if(dep[x] < dep[y]) swap(x, y);
	for(int i = 14; ~i; i--)
		if(dep[fa[x][i]] >= dep[y]) x = fa[x][i];
	if(x == y) return x;
	for(int i = 14; ~i; i--)
		if(fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
	return fa[x][0];
}
void dfs(int x){
	a[x] = dta[x];
	b[x] = dtb[x];
	for(int i = 0; i < (int)V[x].size(); i++){
		int v = V[x][i].first;
		if(v == fa[x][0]) continue;
		dfs(v);
		a[x] += a[v];
		b[x] += b[v];
	}
	if(a[x] && b[x]){puts("No"); exit(0);}
	else if(a[x]) ok[pp[x] ^ 1] = 1;
	else ok[pp[x]] = 1;
}
int main(){
	st = clock();
	scanf("%d%d", &n, &m);
	for(int i = 1, u, v; i <= m; i++){
		scanf("%d%d", &u, &v);
		add(u, v); add(v, u);
	}
	for(int i = 1; i <= n; i++)
		if(!dfn[i]) tarjan(i, 0);
	for(int i = 1; i <= n; i++){
		if(!be[i]){
			++tot;
			dfs(i, 1, 0);
		}
	}
	for(int i = 2; i < e; i++) if(bo[i])
		V[be[ed[i].u]].push_back(make_pair(be[ed[i].v], i));
	for(int i = 1; i <= tot; i++){
		if(!rt[i]){
			fa[i][0] = 0;
			dep[i] = 1;
			dfs(i, i);
			vr.push_back(i);
		}
	}
	scanf("%d", &K);
	for(int i = 1, s, t, lca; i <= K; i++){
		scanf("%d%d", &s, &t);
		s = be[s]; t = be[t];
		if(rt[s] != rt[t]) {puts("No"); return 0;}
		lca = getlca(s, t);
		dta[s]++; dta[lca]--;
		dtb[t]++; dtb[lca]--;
	}
	for(int i = 0; i < (int)vr.size(); i++)
		dfs(vr[i]);
	puts("Yes");
	for(int i = 2; i < e; i++) if(ok[i])
		printf("%d %d\n", ed[i].u, ed[i].v);
	return 0;
}