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 ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define N 100005
#define MXN 2000005
vector<int> v[100005];
int vis[100005],lwn[100005];
vector<int> stk;
int f[100005];
int bln[100005];
int Find(int a){
    if(bln[a]==a)return a;
    return bln[a]=Find(bln[a]);
}
int t;
void dfs(int a,int p){
    stk.pb(a);
    bln[a]=a;
    vis[a]=lwn[a]=++t;
    for(auto x:v[a]){
        if(x!=p){
            if(vis[x]==0){
                dfs(x,a);
                if(lwn[x]>vis[a]){
                    int fa=Find(x);
                    f[x]=Find(a);
                    while(stk.back()!=x){
                        bln[stk.back()]=fa;
                        stk.pop_back();
                    }
                    bln[stk.back()]=fa;
                    stk.pop_back();
                }
                lwn[a]=min(lwn[a],lwn[x]);
            }
            else{
                lwn[a]=min(lwn[a],vis[x]);
            }
        }
    }
}
vector<int> tv[100005];
vector<pii> mystk;
vector<pii> seg[100005];
int in[100005];
int p[100005][20];
int dis[100005];
void dfs2(int x,int f){
    in[x]=++t;
    p[x][0]=f;
    dis[x]=dis[f]+1;
    if(mystk.empty()||mystk.back().y+1!=t){
        mystk.pb(mp(t,t));
    }
    else{
        mystk.back().y++;
    }
    seg[x]=mystk;
    for(auto it:tv[x]){
        if(it!=f){
            dfs2(it,x);
        }
    }
    mystk.back().y--;
    if(mystk.back().y<mystk.back().x)mystk.pop_back();
}
void build(int n){
    for(int i = 1;i<20;i++){
        for(int j=1;j<=n;j++){
            p[j][i]=p[p[j][i-1]][i-1];
        }
    }
}
int lca(int x,int y){
    if(dis[x]>dis[y])swap(x,y);
    int b=dis[y]-dis[x];
    for(int j=0;j<20;j++){
        if(b&(1<<j))y=p[y][j];
    }
    if(x==y)return x;
    for(int i =19;i>=0;i--){
        if(p[x][i]!=p[y][i]){
            x=p[x][i];
            y=p[y][i];
        }
    }
    return p[x][0];
}
struct node{
    node *l,*r;
    int cnt[2];
    int a,b;
    node(int _a,int _b):l(NULL),r(NULL),a(_a),b(_b){
        cnt[0]=cnt[1]=0;
    }
}*root;
void push(node *n){
    for(int i = 0;i<2;i++){
        n->l->cnt[i]+=n->cnt[i];
        n->r->cnt[i]+=n->cnt[i];
        n->cnt[i]=0;
    }
}
void build(node *n){
    if(n->a==n->b)return ;
    int mid=(n->a+n->b)/2;
    n->l=new node(n->a,mid);
    n->r=new node(mid+1,n->b);
    build(n->l);
    build(n->r);
}
void add(node *n,int l,int r,int op,int k){
  //  printf("%d\n",n);
    //printf("%d %d %d %d\n",n->a,n->b,l,r);
    if(n->a>=l&&n->b<=r){
        n->cnt[op]+=k;
        return;
    }
    if(n->b<l||n->a>r)return;
    push(n);
    add(n->l,l,r,op,k);
    add(n->r,l,r,op,k);
}
pii query(node *n,int k){
    if(n->a==n->b)return mp(n->cnt[0],n->cnt[1]);
    int mid=(n->a+n->b)/2;
    push(n);
    if(k<=mid)return query(n->l,k);
    else return query(n->r,k);
}
vector<pii> ans;
void dfs3(int x,int f){
 //   printf("%d\n",x);
    vis[x]=++t;
    for(auto it:v[x]){
        if(Find(it)!=Find(x))continue;
        if(it!=f){
            if(!vis[it]){
                ans.pb(mp(x,it));
                dfs3(it,x);
            }
            else if(vis[it]<vis[x]){
                ans.pb(mp(x,it));
            }
        }    
    }
}
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    pii p[100005];
    for(int i = 0;i<m;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        v[x].pb(y);
        v[y].pb(x);
        p[i]=mp(x,y);
    }
    v[0].pb(1);
    v[1].pb(0);
    dfs(0,0);
   // for(int i = 1;i<=n;i++)
  //  printf("%d ",Find(i));
    for(int i = 0;i<m;i++){
        if(Find(p[i].x)!=Find(p[i].y)){
            tv[Find(p[i].x)].pb(Find(p[i].y));
            tv[Find(p[i].y)].pb(Find(p[i].x));
        }
    }
    t=0;
    dfs2(Find(1),0);
    build(n);
    root=new node(1,t);
    build(root);
    int q;
    scanf("%d",&q);
    while(q--){
        int x,y;
        scanf("%d %d",&x,&y);
        if(Find(x)!=Find(y)){
            int a=Find(x),b=Find(y);
            int ca=lca(a,b);
            for(auto it:seg[a]){
         //       printf("!1 %d %d\n",it.x,it.y);
                add(root,it.x,it.y,1,1);
            }
            for(auto it:seg[b]){
                add(root,it.x,it.y,0,1);
             //   printf("!!2 %d %d\n",it.x,it.y);
            }
            for(auto it:seg[ca]){
            //    printf("!!!3 %d %d\n",it.x,it.y);
                add(root,it.x,it.y,0,-1);
                add(root,it.x,it.y,1,-1);
            }
        }
    }
    for(int i = 1;i<=t;i++){
        pii p=query(root,i);
        if(p.x&&p.y){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    MEM(vis);
    t=0;
    for(int i = 1;i<=n;i++)
    if(!vis[i])
    dfs3(i,0);
    for(int i = 0;i<m;i++){
        int x=Find(p[i].x);
        int y=Find(p[i].y);
        if(x!=y){
            if(in[x]<in[y]){
                pii pp=query(root,in[y]);
                if(pp.y)swap(p[i].x,p[i].y);
            }
            else{
                pii pp=query(root,in[x]);
                if(pp.x)swap(p[i].x,p[i].y);
            }
          //  printf("?%d %d %d %d\n",p[i].x,p[i].y,x,y);
            ans.pb(p[i]);
        }
    }
    for(auto it:ans)printf("%d %d\n",it.x,it.y);
    return 0;
}