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 <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <assert.h>
using namespace std;
#define int long long
int MOD = 1000000007;
class biconnected {
private:
	void dfs(int u, int p, int &k, int q)
	{
		visit[u] = true;
		ord[u] = k++;
		low[u] = ord[u];
		for (int i = 0; i < (int)G[u].size(); i++) {
			int v = G[u][i];
			if (!visit[v]) {
				dfs(v, u, k, i);
				low[u] = min(low[u], low[v]);
				if (ord[u] < low[v]) {
					bridge.emplace_back(u, v);
					check[u][i].second = 1;
					check[v][check[u][i].first].second = 1;
				}
			}
			else if (v != p || q != check[u][i].first) {
				low[u] = min(low[u], ord[v]);
			}
		}
	}
	void restrict_dfs(int u, int p, int kind, queue<int>& que)
	{
		visit[u] = true;
		cmp[u] = kind;
		for (int i = 0; i < (int)G[u].size(); i++) {
			int v = G[u][i];
			if (check[u][i].second) {
				if (!visit[v]) {
					que.push(v);
				}
			}
			else if (!visit[v]) {
				restrict_dfs(v, u, kind, que);
			}
		}
	}
	void rebuild()
	{
		kind = 0;
		fill(visit, visit + V, false);
		for (int i = 0; i < V; i++) {
			if (!visit[i]) {
				queue<int> que;
				que.push(i);
				while (!que.empty()) {
					int p = que.front();
					que.pop();
					restrict_dfs(p, -1, kind, que);
					kind++;
				}
			}
		}
	}
public:
	int V, kind;
	vector<vector<int> > G, tree;
	vector<vector<pair<int, int> > > check;
	vector<pair<int, int> > bridge;
	vector<int> ord, low, cmp;
	bool *visit;
	biconnected(int node_size)
		: V(node_size), kind(0), G(V), check(V), ord(V), low(V)
		, cmp(V), visit(new bool[V]()) {}
	// ~biconnected(){ delete[] visit; }
	void add_edge(int u, int v)
	{
		G[u].push_back(v), G[v].push_back(u);
		check[u].emplace_back((int)check[v].size(), 0);
		check[v].emplace_back((int)check[u].size() - 1, 0);
	}
	// 橋を検出する.
	void detect_bridge() {
		int id = 0;
		for (int i = 0; i < V; i++) {
			if (!visit[i]) {
				dfs(i, -1, id, -1);
			}
		}
	}
	// 2(辺)連結成分を頂点とする木(tree) を作る(事前に detect_bridge() を呼んでおく必要がある).
	// 木の頂点数を返す.
	// cmp[i] は元の頂点 i の含まれる頂点(2(辺)連結成分) を表す.
	int make_bctree()
	{
		rebuild();
		tree.resize(kind);
		for (int i = 0; i < (int)bridge.size(); i++) {
			int a = cmp[bridge[i].first], b = cmp[bridge[i].second];
			tree[a].push_back(b), tree[b].push_back(a);
		}
		return kind;
	}
};
vector<vector<int> > tree;
vector<vector<int> > XX;
vector<vector<int> > YY;
map<pair<int, int>, int> dir;
bool ok = true;
void dfs(int a, int p, set<int> &st1, set<int> &st2) {



	for (int i : tree[a]) {
		if (i != p) {
			set<int> B1;
			set<int> B2;
			dfs(i, a, B1, B2);
			if (!ok)break;
			if (st1.size() < B1.size()) {
				swap(st1, B1);
			}
			if (st2.size() < B2.size()) {
				swap(st2, B2);
			}
			for (const int &s : B1) {
				if (st2.count(s) == 0) {
					st1.insert(s);
				}
				else {
					st2.erase(s);
				}
			}
			for (const int &s : B2) {
				if (st1.count(s) == 0) {
					st2.insert(s);
				}
				else {
					st1.erase(s);
				}
			}
		}
	}

	


	for (int i = 0; i < XX[a].size(); i++) {
		if (st2.count(XX[a][i]) == 0) {
			st1.insert(XX[a][i]);
		}
		else {
			st2.erase(XX[a][i]);
		}
	}
	for (int i = 0; i < YY[a].size(); i++) {
		if (st1.count(YY[a][i]) == 0) {
			st2.insert(YY[a][i]);
		}
		else {
			st1.erase(YY[a][i]);
		}
	}

	if (st1.size() > 0 && st2.size() > 0) {
		ok = false;
	}

	if (st1.size() > 0) {
		dir[make_pair(a, p)] = 0;
		dir[make_pair(p, a)] = 1;
	}
	else {
		dir[make_pair(a, p)] = 1;
		dir[make_pair(p, a)] = 0;
	}


}
vector<pair<int, int> > res;
vector<vector<int> > g;
vector<int> V;

void dfs2(int a, int p = -1) {
	//cerr << a << endl;
	V[a] = 1;

	for (int i : g[a]) {
		if (i != p) {
			if (V[i] == 0) {
				dfs2(i, a);
				res.emplace_back(a + 1, i + 1);
			}
			else if (V[i] == 1) {
				res.emplace_back(a + 1, i + 1);
			}
		}
	}
	V[a] = 2;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<pair<int, int> > vp(M);
	biconnected G(N);
	for (int i = 0; i < M; i++) {
		cin >> vp[i].first >> vp[i].second;
		vp[i].first--;
		vp[i].second--;
		G.add_edge(vp[i].first, vp[i].second);
	}
	G.detect_bridge();
	G.make_bctree();
	tree = G.tree;
	int S = tree.size();

	int K;
	cin >> K;
	int a, b;
	vector<pair<int, int> > A;
	XX.resize(S);
	YY.resize(S);
	for (int i = 0; i < K; i++) {
		cin >> a >> b;
		a--; b--;
		if (G.cmp[a] == G.cmp[b])continue;
		A.emplace_back(G.cmp[a], G.cmp[b]);
		XX[G.cmp[a]].push_back(i);
		YY[G.cmp[b]].push_back(i);
	}
	set<int> st1, st2;
	dfs(0, -1, st1, st2);
	if (!ok) {
		cout << "No" << endl;
		return 0;
	}
	g.resize(N);
	V.resize(N, 0);
	for (int i = 0; i < vp.size(); i++) {
		a = vp[i].first;
		b = vp[i].second;
		if (G.cmp[a] == G.cmp[b]) {
			g[a].push_back(b);
			g[b].push_back(a);
		}
		else {
			int d = dir[make_pair(G.cmp[a], G.cmp[b])];
			if (d == 0) {
				res.emplace_back(a + 1, b + 1);
			}
			else {
				res.emplace_back(b + 1, a + 1);
			}
		}
	}

	for (int i = 0; i < N; i++) {
		if (V[i] == 0) {
			dfs2(i);
		}
	}
	cout << "Yes" << endl;
	assert(res.size() == M);
	for (int i = 0; i < res.size(); i++) {
		cout << res[i].first << " " << res[i].second << endl;
	}
}