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>

using namespace std;

#define For(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define sz(a) ((int)a.size())
#define Rep(i, n) for (int i = 0, _n = (n); i < _n; i++)

const int maxn = 100000 + 123;
int n, m, k;
vector<int> V[maxn];
const int maxm = 100000 + 123;

struct edge {
	int u, v; 
	void read() {
		cin >> u >> v;
	}
} e[maxm];
int color[maxn];
int other(int id, int x) {
	return x ^ e[id].u ^ e[id].v;
}

void readData() {
	cin >> n >> m ;
	
	For(i,1,m) {
		e[i].read();
		V[e[i].u].push_back(i);
		V[e[i].v].push_back(i);
	}
	cin >> k;
}

int low[maxn], num[maxn], timer = 0;
int ess[maxm];
int scc, belong[maxn];

void dfs(int u, int prevId) {
	low[u] = num[u] = ++timer;
	for (auto id: V[u]) if (prevId != id) {
		int v = other(id, u);
		
		if (num[v]) {
			low[u] = min(low[u], num[v]);
		} else {
			dfs(v, id);
			low[u] = min(low[u], low[v]);
		}
 	}
 	if (prevId != -1 && low[u] >= num[u]) {
		//cout << "cau: " <<  prevId << endl;
		ess[prevId] = 1;
	}
	//cout << "low num "  << u << " " << low[u] << " " << num[u] << endl; 
}

int ord[maxm]; /// = v => (u -> v)

vector<pair<int, int> > G[maxn]; ///tree
int papa[maxn];
void findComponent(int u) {
	belong[u] = scc;
	for (auto id: V[u]) if (!ess[id]) {
		int v = other(id, u);
		if (!belong[v]) {
			ord[id] = v;
			findComponent(v);
		} else {
			ord[id] = u;
		}
	}
}

void buildTree() {
	memset(low, 0, sizeof(low));
	memset(num, 0, sizeof(num));
	memset(ess, 0, sizeof(ess));
	timer = 0;
	scc = 0;
	
	For(u, 1, n) if (!num[u]) {
		dfs(u, -1);
	}
	
	memset(papa, 0, sizeof(papa));
	memset(belong, 0, sizeof(belong));
	memset(ord, 0, sizeof(ord));
	
	For(u, 1, n) if (!belong[u]) {
		++scc;
		findComponent(u);
	}
	
	For(i,1,m) {
		int u = e[i].u, v = e[i].v;
		if (belong[u] != belong[v]) {
			G[belong[u]].push_back({belong[v], i});
			G[belong[v]].push_back({belong[u], i});
		}
	}

}

int parentEdge[maxn];
int tin[maxn], tout[maxn];

int col[maxn][2];
int lv[maxn];
int a[maxn][2], pa[maxn][20];
void dfsInit(int u, int prev) {
	tin[u] = ++timer;
	for (auto nxt: G[u]) if (nxt.first != prev) {
		int v, id; tie(v, id) = nxt;
		parentEdge[v] = id;
		papa[v] = u;
		
		dfsInit(v, u);
	}
	tout[u] = timer;
}
void dfsCheck(int u, int prev) {
	for (auto nxt: G[u]) if (nxt.first != prev) {
		int v, id; tie(v, id) = nxt;
		lv[v] = lv[u] + 1; 
		col[v][0] = col[u][0];
		col[v][1] = col[u][1];
		
		col[v][color[v] - 1]++;
		dfsCheck(v, u);
	}
}
bool anc(int u, int v) {
	return tin[u] <= tin[v] && tout[u] <= tout[v];
}


struct DSU{
	int lab[maxn];
	
	void init() {
		lab[0] = 0;
		For(u,1,scc) lab[u] = u;
	}
	
	int f(int u) {
		return lab[u] == u ? u : lab[u] = f(lab[u]);
	}
	
	///connect u->v
	void join(int u, int v) {
		lab[u] = v;
	}
} dsu;

void fail() {
	cout << "No" << endl;
	exit(0);
}
///color = 1 thi la di xuong duoi, color = 2 thi la di len tren

void To(int p, int q) {
	if (p == q) return;
	///cout << "dang to" << p << " " << q << endl;
	///to tu p den LCA mau 2
	///to tu q den LCA mau 1
	
	int z = dsu.f(p);
	while (z && !anc(z, q)) {
		color[z] = 2;
		dsu.join(z, dsu.f(papa[z]));
		z = dsu.f(z);
	}
	z = dsu.f(q);
	while (z && !anc(z, p)) { 
		color[z] = 1;
		dsu.join(z, dsu.f(papa[z]));
		z = dsu.f(z);
	}
}

int LCA(int u, int v) {
	if (lv[u] < lv[v]) swap(u, v);
	for(int i = 0, diff = lv[u] - lv[v]; diff; i++, diff >>= 1)
		if (diff & 1) u = pa[u][i];
	if (u == v) return u;
	for(int i = 19; i >= 0; i--) 
		if (pa[u][i] != pa[v][i]) 
			u = pa[u][i], v = pa[v][i];
	return pa[u][0];
}

void tomau() {
	//For(u,1,n)  cout << belong[u] << endl;
	memset(papa,0,sizeof(papa));
	
	For(u,1,scc) if (!papa[u]) {
		dfsInit(u, -1);
	}
	
	memset(color, 0, sizeof(color));
	dsu.init();
	
	For(i,1,k) {
		int p, q; cin >> p >> q;
		p = belong[p], q = belong[q];
		a[i][0] = p, a[i][1] = q;
		To(p, q);
	}
	
	//cout << "." << color[2] << endl;
	For(u,1,scc) if (papa[u]) {
		int id = parentEdge[u];
		if (color[u] == 1) {
			///di tu papa[u] den u
			int x = e[id].u, y = e[id].v;
			//cout << "zz " << x << " " << y << endl;
			if (belong[x] == u) {
				ord[id] = x;
			} else {
				ord[id] = y;
			}
		} else {
			///di tu u den papa[u]
			///di tu papa[u] den u
			int x = e[id].u, y = e[id].v;
			if (belong[x] == papa[u]) {
				ord[id] = x;
			} else {
				ord[id] = y;
			}
		}
	}
	dfsCheck(1, -1);
	for(int i = 1; i <= scc; i++) pa[i][0] = papa[i];
	
	for(int j = 1; j < 20; j++)
		for(int i = 1; i <= scc; i++) pa[i][j] = pa[pa[i][j - 1]][j - 1];
	for(int i = 1; i <= k; i++) {
		int u = a[i][0], v = a[i][1];
		int z = LCA(u, v);
		
		if (col[u][1] - col[z][1] != lv[u] - lv[z])
			return fail();
		if (col[v][0] - col[z][0] != lv[v] - lv[z]) 
			return fail();
	}
}

void process() {
	buildTree();
	tomau();
	for (int i = 1; i <= m; i++) {
		if (!ord[i]) ord[i] = e[i].u;
	}
	
	cout << "Yes" << endl;
	For(i,1,m) {
		cout << other(i, ord[i]) << " " << ord[i] << "\n";
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
//	freopen("input.txt", "r", stdin);
	readData();
	process();
	
	return 0;
}