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 ll long long
#define forn(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
#define IO ios::sync_with_stdio(false);cin.tie(0)

const int maxn = 1e4 + 5;
const int maxm = 1e5 + 5;

vector<pair<int,int> >G[maxn];
struct edage{
    int u, v, nex;
}e[maxm << 1];
int tim, tot = 1, bccnt, sccnt;
int dfn[maxn], low[maxn], Dp[maxn], head[maxn], bcc[maxn], scc[maxn], fa[maxn][20], deep[maxn], st[maxn], ed[maxn], pp[maxn], a[maxn], b[maxn];
bool bri[maxm << 1], ok[maxm << 1], vis[maxn];
inline void add(int u, int v) {
    e[++tot] = {u, v, head[u]}, head[u] = tot;
    e[++tot] = {v, u, head[v]}, head[v] = tot;
}
inline void tarjan(int u, int pre) {
    dfn[u] = low[u] = ++tim;
    for(int i = head[u]; i; i = e[i].nex) {
        int v = e[i].v;
        if(v == pre) continue;
        if(!dfn[v]) {
            tarjan(v, u);
            low[u] = min(low[u], low[v]);
            if(low[v] > dfn[u]) bri[i]  = bri[i ^ 1] = 1;
        }else low[u] = min(low[u], dfn[v]);
    }
}
inline void dfs(int u, int pre, int d) {
    bcc[u] = bccnt, Dp[u] = d;
    for(int i = head[u]; i; i = e[i].nex) {
        int v = e[i].v;
        if(v == pre) continue;
        if(bri[i]) continue;
        if(!bcc[v]) {
            ok[i] = 1;
            dfs(v, u, d + 1);
        }else if(Dp[u] > Dp[v])ok[i] = 1;
    }
}
inline void dfs2(int u, int pre, int d) {
    scc[u] = sccnt, deep[u] = d, fa[u][0] = pre;
    for(int i = 1; deep[u] - (1 << i) >= 0; ++i) {
        fa[u][i] = fa[fa[u][i - 1]][i - 1];
    }
    for(auto &x : G[u]) {
        int v = x.first;
        if(scc[v]) continue;
        pp[v] = x.second;
        dfs2(v, u, d + 1);
    }
}
inline int LCA(int u, int v) {
    if(deep[u] < deep[v]) swap(u, v);
    for(int i = 14; i >= 0; --i) {
        if(deep[fa[u][i]] >= deep[v]) {
            u = fa[u][i]; 
        }
    }
    if(u == v) return u;
    for(int i = 14; i >= 0; --i) {
        if(fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i]; 
    }
    return fa[u][0];
}

inline void getans(int u) { 
    vis[u] = 1;
    a[u] = st[u], b[u] = ed[u];
    for(auto &x : G[u]) {
        int v = x.first;
        if(vis[v]) continue;
        getans(v);
        a[u] += a[v], b[u] += b[v];
    }
    if(a[u] && b[u]) {
        cout << "No" << '\n';
        exit(0);
    }
    else if(a[u]) ok[pp[u] ^ 1] = 1;
    else ok[pp[u]] = 1;
}
int main() {
    IO;
    int n, m; cin >> n >> m;
    forn(i, m) {
        int u, v; cin >> u >> v;
        add(u, v);
    }
    for1(i, n) if(!dfn[i]) tarjan(i, i);
    for1(i, n) if(!bcc[i]) ++bccnt, dfs(i, i, 1);
    for(int i = 2; i <= tot; ++i)  if(bri[i]) {
        int u = bcc[e[i].u], v = bcc[e[i].v];
        G[u].push_back({v, i});
    }
    vector<int> root;
    for1(i, bccnt) if(!scc[i]) ++sccnt, dfs2(i, i, 1), root.push_back(i);
    int q; cin >> q;
    forn(i, q) {
        int u, v; cin >> u >> v;
        u = bcc[u], v = bcc[v];
        int lca = LCA(u, v);
        if(scc[u] != scc[v]) return cout <<"No\n", 0;
        ++st[u], --st[lca];
        ++ed[v], --ed[lca];
    } 
    for(auto x : root) getans(x);    
    cout << "Yes" << '\n';
    for(int i = 2; i <= tot; ++i) {
        if(!ok[i]) continue;
        cout << e[i].u << ' ' << e[i].v << '\n';     
    }
    return 0;
}