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;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

struct LCA {
    const int n = 0;
    const int log2_n = 0;
    vector<vector<int>> g;
    vector<vector<int>> par;  // par[2^i上][頂点v]
    vector<int> dep;

    void dfs(int v, int p, int d) {
        par[0][v] = p;
        dep[v] = d;
        for(auto to: g[v]) {
            if(to == p) continue;
            dfs(to, v, d+1);
        }
    }

    LCA() {}
    LCA(int n) : n(n), log2_n(log2(n)+1), g(n),
        par(log2_n, vector<int>(n)), dep(n) {}

    void add_edge(int u, int v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }

    void build(ll root=0) {
        dfs(root, -1, 0);
        for(int i=0; i+1 < log2_n; ++i) {
            for(int j = 0; j < n; ++j) {
                if(par[i][j] < 0) par[i+1][j] = -1;
                else par[i+1][j] = par[i][par[i][j]];
            }
        }
    }

    int get(int u, int v) {
        if(dep[u] > dep[v]) swap(u, v);
        REP(i, log2_n) {
            if((dep[v] - dep[u]) >> i & 1) {
                v = par[i][v];
            }
        }
        if(u == v) return u;
        for(int i=log2_n-1; i>=0; --i) {
            if(par[i][u] != par[i][v]) {
                u = par[i][u];
                v = par[i][v];
            }
        }
        return par[0][u];
    }
};

class twoEdgeComponent {
private:
    void dfs(ll v, ll p, ll &k) {
        used[v] = true;
        ord[v] = k++;
        low[v] = ord[v];
        for(auto to: g[v]) {
            if(!used[to]) {
                dfs(to, v, k);
                chmin(low[v], low[to]);
                if(ord[v] < low[to]) bridge.emplace_back(v, to);
            } else if(to != p) {
                chmin(low[v], ord[to]);
            }
        }
    }
    void dfs2(ll v, ll p, ll &k) {
        if(~p && ord[p] >= low[v]) cmp[v] = cmp[p];
        else cmp[v] = k++;
        for(auto to: g[v]) if(cmp[to] == -1) dfs2(to, v, k);
    }
public:
    vector<bool> used;
    vector<vector<ll>> g;
    vector<ll> ord, low, cmp;
    vector<PII> bridge;

    twoEdgeComponent() {}
    twoEdgeComponent(ll n) : used(n), g(n), ord(n), low(n), cmp(n, -1) {}

    void add_edge(ll u, ll v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }

    using P = pair<ll,PII>;
    vector<vector<P>> build() {
        ll k = 0;
        REP(i, g.size()) if(!used[i]) dfs(i, -1, k);
        k = 0;
        REP(i, g.size()) if(cmp[i]==-1) dfs2(i, -1, k);
        // ret[i] = {(iの行き先, (つぶす前のi, つぶす前のiの行き先))}
        vector<vector<P>> ret(k);
        for(auto e: bridge) {
            ll x = cmp[e.first], y = cmp[e.second];
            ret[x].push_back({y, {e.first, e.second}});
            ret[y].push_back({x, {e.second, e.first}});
        }
        return ret;
    }
};

int main(void) {
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> g(n);
    twoEdgeComponent graph(n);
    REP(i, m) {
        ll u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
        g[v].push_back(u);
        graph.add_edge(u, v);
    }
    auto tree = graph.build();
    auto ord = graph.ord;
    auto low = graph.low;
    auto cmp = graph.cmp;

    dump(cmp);

    vector<PII> ans;
    // 二重辺連結成分の全頂点対を行き来できるように
    {
        vector<bool> visit(n);
        function<void(ll,ll)> dfs = [&](ll v, ll p) {
            visit[v] = true;
            for(auto to: g[v]) {
                if(!visit[to]) {
                    if(ord[v] >= low[to]) ans.emplace_back(v, to);
                    dfs(to, v);
                } else if(ord[v] > ord[to] && to!=p) {
                    ans.emplace_back(v, to);
                }
            }
        };
        REP(i, n) if(!visit[i]) dfs(i, -1);
    }

    dump(tree);

    LCA lca(tree.size());
    REP(i, tree.size()) {
        for(auto j: tree[i]) {
            if(i < j.first) lca.add_edge(i, j.first);
        }
    }
    lca.build();

    vector<ll> up(tree.size()), down(tree.size());
    ll q;
    cin >> q;
    while(q--) {
        ll u, v;
        cin >> u >> v;
        u--, v--;

        u = cmp[u], v = cmp[v];
        if(u == v) continue;
        ll l = lca.get(u, v);
        dump(u, v, l);
        up[u]++;
        up[l]--;
        down[v]++;
        down[l]--;
    }

    dump(up);
    dump(down);

    function<void(ll,ll)> dfs = [&](ll v, ll p) {
        for(auto to: tree[v]) {
            if(to.first == p) continue;
            dfs(to.first, v);

            down[v] += down[to.first];
            up[v] += up[to.first];
            if(down[to.first] > 0 && up[to.first] > 0) {
                cout << "No" << endl;
                exit(0);
            } else if(down[to.first] > 0) {
                ans.push_back(to.second);
            } else {
                ans.push_back({to.second.second, to.second.first});
            }
        }
    };
    dfs(0, -1);

    cout << "Yes" << endl;
    for(auto p: ans) cout << p.first+1 << " " << p.second+1 << endl;

    return 0;
}