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 Int = long long;
using ll = long long;
template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b){if(a < b) a = b;}


struct LowLink{
  int n, pos;
  vector<int> ord, low, par, blg, num;
  vector<vector<int> > G, C, T;
  vector<vector<pair<int, int> > > E;
  vector<int> ap;
  vector<pair<int, int> > bs, cand;
  LowLink(int n) : n(n), pos(0), ord(n, -1), low(n),
                   par(n,-1),blg(n, -1),num(n, 1), G(n){}
  void add_edge(int u, int v){
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }

  bool is_bridge(int u, int v){
    if(ord[u] > ord[v]) swap(u, v);
    return ord[u] < low[v];
  }

  void dfs(int v){
    ord[v] = low[v] = pos++;
    for(int u:G[v]){
      if(u == par[v]) continue;
      if(ord[u] < ord[v])
        cand.emplace_back(min(u, v), max(u, v));
      if(~ord[u]){
        low[v] = min(low[v], ord[u]);
        continue;
      }
      par[u] = v;
      dfs(u);
      num[v] += num[u];
      low[v] = min(low[v], low[u]);
      if(is_bridge(u, v)) bs.emplace_back(u, v);
      if(low[u] >= ord[v]){
        E.emplace_back();
        while(1){
          auto e=cand.back();
          cand.pop_back();
          E.back().emplace_back(e);
          if(make_pair(min(u, v), max(u, v)) == e) break;
        }
      }
    }
  }

  void fill_component(int v){
    C[blg[v]].emplace_back(v);
    for(int u:G[v]){
      if(~blg[u] || is_bridge(u, v)) continue;
      blg[u] = blg[v];
      fill_component(u);
    }
  }

  void add_component(int v, int &k){
    if(~blg[v]) return;
    blg[v] = k++;
    C.emplace_back();
    fill_component(v);
  }

  int build(){
    for(int i=0;i<n;i++)
      if(ord[i] < 0) dfs(i);

    vector<int> cnt(n, 0);
    for(int i=0;i<n;i++){
      int p = par[i];
      if(p < 0) continue;
      if(par[p] < 0) cnt[p]++;
      else if(ord[p] <= low[i]) ap.emplace_back(p);
    }

    for(int i=0;i<n;i++)
      if(cnt[i] > 1) ap.emplace_back(i);
    sort(ap.begin(), ap.end());
    ap.erase(unique(ap.begin(), ap.end()) , ap.end());
    int k = 0;
    for(int i=0;i<n;i++) add_component(i, k);
    T.assign(k, vector<int>());
    for(auto e:bs){
      int u = blg[e.first], v = blg[e.second];
      T[u].emplace_back(v);
      T[v].emplace_back(u);
    }
    return k;
  }
};


struct LowestCommonAncestor{
  int n, h;
  vector<vector<int> > G, par;
  vector<int> dep;
  LowestCommonAncestor(){}
  LowestCommonAncestor(int n):n(n), G(n), dep(n){
    h = 1;
    while((1<<h) <= n) h++;
    par.assign(h, vector<int>(n, -1));
  }

  void add_edge(int u, int v){
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }

  void dfs(int v,int p,int d){
    par[0][v] = p;
    dep[v] = d;
    for(int u:G[v])
      if(u != p) dfs(u, v, d+1);
  }

  void build(int r = 0){
    dfs(r, -1, 0);
    for(int k=0;k+1<h;k++)
      for(int v=0;v<n;v++)
        if(~par[k][v])
          par[k+1][v] = par[k][par[k][v]];
  }

  int lca(int u, int v){
    if(dep[u] > dep[v]) swap(u, v);
    for(int k=0;k<h;k++)
      if((dep[v] - dep[u]) >>k& 1)
        v = par[k][v];
    if(u == v) return u;
    for(int k=h-1;k>=0;k--)
      if(par[k][u] !=par[k][v])
        u = par[k][u], v = par[k][v];
    return par[0][u];
  }
  int distance(int u, int v){
    return dep[u] + dep[v] - dep[lca(u, v)] * 2;
  }
};


vector< vector<int> > T;
vector<int> up,dw;

// from -> to
using P = pair<int, int>;
set<P> sp,cmp_sp;

int cntU,cntD;
void dfs(int v,int p){
  for(int u:T[v]){
    if(u==p) continue;
    int preU=cntU,preD=cntD;
    dfs(u,v);
    if(cntU>preU&&cntD>preD){
      cout<<"No"<<endl;
      exit(0);
    }
    if(cntU>preU) cmp_sp.emplace(u,v);
    else cmp_sp.emplace(v,u);
  }
  cntU+=up[v];
  cntD+=dw[v];
}

vector< set<int> > S;

void add_edge(int p,int q){
  sp.emplace(p,q);
  S[p].erase(q);
  S[q].erase(p);
};

vector<int> used;
void dfs2(int v){
  used[v]=1;
  while(!S[v].empty()){
    int u=*S[v].begin();
    add_edge(v,u);
    if(used[u]) continue;
    dfs2(u);
  }
}

signed solve(){
  int n,m;
  cin>>n>>m;
  LowLink G(n);
  vector<int> xs,ys;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G.add_edge(x,y);
    xs.emplace_back(x);
    ys.emplace_back(y);
  }
  int sz=G.build();

  LowestCommonAncestor H(sz);
  for(int v=0;v<sz;v++)
    for(int u:G.T[v])
      if(u<v) H.add_edge(u,v);

  H.build();

  int q;
  cin>>q;

  up.assign(sz,0);
  dw.assign(sz,0);

  vector< vector<int> > C(n);
  for(int i=0;i<q;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    C[a].emplace_back(b);
    a=G.blg[a];
    b=G.blg[b];
    int c=H.lca(a,b);
    up[a]++;
    up[c]--;
    dw[b]++;
    dw[c]--;
  }

  cntU=cntD=0;
  T=H.G;
  dfs(0,-1);

  S.resize(n);
  for(int i=0;i<m;i++){
    int x=xs[i],y=ys[i];
    if(G.blg[x]!=G.blg[y]){
      if(cmp_sp.count(P(G.blg[x],G.blg[y])))
        sp.emplace(x,y);
      else
        sp.emplace(y,x);
      continue;
    }
    S[x].emplace(y);
    S[y].emplace(x);
  }

  used.assign(n,0);
  for(int i=0;i<n;i++){
    if(used[i]) continue;
    dfs2(i);
  }

  // not used (sonnamonon nai);
  for(int i=0;i<m;i++){
    int x=xs[i],y=ys[i];
    assert(sp.count(P(x,y))^sp.count(P(y,x)));
  }

  if(0){
    vector< vector<int> > U(n);
    for(auto p:sp)
      U[p.first].emplace_back(p.second);

    for(int x=0;x<n;x++){
      vector<int> used(n,0);
      queue<int> que;
      used[x]=1;
      que.emplace(x);
      while(!que.empty()){
        int v=que.front();que.pop();
        for(int u:U[v]){
          if(used[u]) continue;
          used[u]=1;
          que.emplace(u);
        }
      }

      for(int y=0;y<n;y++)
        if(G.blg[x]==G.blg[y])
          assert(used[y]);

      for(int y:C[x]) assert(used[y]);
    }
  }

  assert((int)sp.size()==m);
  cout<<"Yes"<<endl;
  for(auto p:sp)
    cout<<p.first+1<<" "<<p.second+1<<"\n";
  cout<<flush;

  return 0;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  solve();
  return 0;
}