#include <bits/stdc++.h>
int lst[400005], to[2000005], pre[2000005], tot;
int dir[400005], fa[400005], fae[400005], que[400005];
int node[400005], dep[400005], son[400005];
std::vector<int> cyc[400005];
bool vis[400005];
inline void add_edge(int u, int v) {
  to[tot] = v;
  pre[tot] = lst[u];
  lst[u] = tot++;
}
void dfs(int u, int f = -1) {
  fa[u] = f;
  for (int i = lst[u]; ~i; i = pre[i]) {
    if (~f && i == (fae[u] ^ 1)) continue;
    int v = to[i];
    if (!dep[v]) {
      son[u] = v;
      fae[v] = i;
      dep[v] = dep[u] + 1;
      dfs(v, u);
    } else if (dep[v] < dep[u])
      cyc[son[v]].push_back(i);
  }
}
void solve(int n, int m, int s, int t) {
  memset(vis, false, n);
  memset(lst, -1, n << 2);
  memset(dir, -1, m << 2);
  memset(dep, 0, n << 2);
  tot = 0;
  for (int i = 0; i < n; i++) cyc[i].clear();
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(--u, --v);
    add_edge(v, u);
  }
  dep[s] = 1;
  dfs(s);
  if (!dep[t]) {
    puts("No");
    return;
  }
  int he = 0, ta = 0;
  vis[t] = true;
  que[ta++] = t;
  while (he < ta) {
    int x = que[he++], u = x < 0 ? ~x : x, d = x < 0 ? 1 : 0;
    dir[fae[u] >> 1] = d;
    for (auto e : cyc[u]) {
      int v = to[e] ^ to[e ^ 1] ^ fa[u];
      dir[e >> 1] = d;
      if (!vis[v]) {
        vis[v] = true;
        que[ta++] = d ? v : ~v;
      }
    }
    if (fa[u] != s && !vis[fa[u]]) {
      vis[fa[u]] = true;
      que[ta++] = d ? ~fa[u] : fa[u];
    }
  }
  for (int i = 0; i < m; i++) {
    if (-1 == dir[i]) {
      puts("No");
      return;
    }
  }
  puts("Yes");
  for (int i = 0; i < m; i++) {
    if (dir[i] ^ (dep[to[i << 1]] > dep[to[i << 1 | 1]]))
      printf("%d %d\n", to[i << 1 | 1] + 1, to[i << 1] + 1);
    else
      printf("%d %d\n", to[i << 1] + 1, to[i << 1 | 1] + 1);
  }
}
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    int n, m, s, t;
    scanf("%d%d%d%d", &n, &m, &s, &t);
    solve(n, m, --s, --t);
  }
  return 0;
}
