#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) rep(i,n)
#define repn(i,n) for(int i=n;i>=0;i--);

void dfs1(vector<vector<pair<int,int>>> &graph, vector<int> &num, vector<int> &used, int node, int &con){

  if(used[node] ) return ;

  used[node] = true;

  for(pair<int,int> next : graph[node]){
    dfs1(graph, num, used, next.first, con);
  }

  num[con++] = node;
}

void dfs2(vector<vector<pair<int,int>>> &graph, vector<int>& scc, vector<int> &used, int node, int same){

  if(used[node] ) return ;

  used[node] = true;


 for(pair<int,int> next : graph[node]){
    dfs2(graph, scc, used, next.first, same);
  }

 scc[node] = same;

}


void SCC(vector<vector<pair<int,int>>> &graph, vector<int> &scc){
  vector<int> used(graph.size()), num(graph.size());
  vector<vector<pair<int,int>>> graph2(graph.size());
  int con = 0;

  scc.resize(graph.size());

  for(int i = 0; i < (int)graph.size(); i++){
    dfs1(graph, num, used, i, con);
  }

  for(int i = 0; i < (int)graph.size(); i++){
    for(int j = 0; j < (int)graph[i].size(); j++){
      graph2[graph[i][j].first].push_back(make_pair(i, graph[i][j].second));
    }
  }

  used.clear();
  used.resize(graph.size());

  for(int i = (int)graph.size()-1, same = 0; i >= 0; i--){
    if(!used[num[i]]){
      dfs2(graph2, scc, used, num[i], same);
      same++;
    }
  }
}

class union_find{
  vector<int> par, nume;
 public:

  union_find(){
  }

  void init(){
    for(int i = 0; i < (int)par.size(); i++){
      par[i] = i;
      nume[i] = 1;
    }
  }

  void resize(int x){
    par.resize(x);
    nume.resize(x);
    init();
  }

  int find(int x){
    return par[x] == x ? x : par[x] = find(par[x]);
  }

  void unite(int x, int y){
    x = find(x);
    y = find(y);

    if(x == y) return ;

    if(nume[x] > nume[y]) swap(x, y);

    par[x] = y;
    nume[y] += nume[x];
  }

  bool same(int x, int y){
    return find(x) == find(y);
  }

};


//map<pair<int,int>, int> used;
vector<vector<bool>> used;
union_find uf;

void dfs(vector<vector<pair<int,int>>>& G, vector<int> & scc, int num, int now,  int par){

  for(pair<int,int> next : G[now]){
    if(scc[next.first] != num) continue;
    if(used[now][next.first]) continue;
    if(used[next.first][now]) continue;
    used[now][next.first] = true;

    uf.unite(now, next.first);
    dfs(G, scc, num, next.first, now);
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  vector<int> scc, scc2;
  vector<pair<int,int>> in, in2;
  vector<vector<pair<int,int>>> G, G2, G3;

  int n, m, k;

  cin>>n>>m;

  uf.resize(n);
  G.resize(n);
  G2.resize(n);
  G3.resize(n);

  in2.resize(m);

  used.resize(n, vector<bool>(n));

  for(int i = 0; i < m; i++){
    int x, y;

    cin>>x>>y;

    x--, y--;

    in2[i] = {x, y};

    G2[x].push_back({y,0});
    G2[y].push_back({x,0});
  }

  // cout<<"<2>"<<endl;

  cin>>k;

  in.resize(k);
  for(int i = 0; i < k; i++){
    int a, b;

    cin>>a>>b;

    a--, b--;
    in[i] = {a,b};

    G[a].push_back({b,0});
  }


  //  cout<<"SCC b"<<endl;

  SCC(G, scc);

  //cout<<"SCC e"<<endl;

  for(int i = 0; i < n; i++){
    dfs(G2, scc, scc[i], i, -1);
  }

  //cout<<"dfs e"<<endl;

  for(int i = 0; i < n; i++){ //cout<<"i = "<<i<<" G2[i].size()"<<G2[i].size()<<endl;
    for(int j = 0; j < (int)G2[i].size(); j++){
      // cout<<"j = "<<j<<endl;
      if(used[i][G2[i][j].first]) continue;
      if(used[G2[i][j].first][i]) continue;

      uf.unite(i,G2[i][j].first );

      if(scc[i] <= scc[G2[i][j].first]){
        used[i][G2[i][j].first] = true;
      } else {
        used[G2[i][j].first][i] = true;
      }
    }
  }

  //cout<<"Xx"<<endl;

  // for(pair<pair<int,int>,int> edge : used){
  // if(edge.second) G3[edge.first.first].push_back({edge.first.second, 0});
  // }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(used[i][j]) G3[i].push_back({j,0});
    }
  }


  SCC(G3, scc2);

  bool flag = true;

  for(int i = 0; i < k; i++){
    if(uf.same(in[i].first, in[i].second)){
      if(scc2[in[i].first] <= scc2[in[i].second]){
      } else {
        flag = false;
      }
    } else {
      flag = false;
      break;
    }
  }

  if(flag == false) cout<<"No"<<endl;
  else {
    cout<<"Yes"<<endl;


    for(int i = 0; i < m; i++){
      if(used[in2[i].first][in2[i].second]){
        cout<<in2[i].first+1<<" "<<in2[i].second+1<<endl;
      } else {
        cout<<in2[i].second+1<<" "<<in2[i].first+1<<endl;
      }
    }



  }
  return 0;
}

