#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
char buf[(int)1e8], *ss = buf;
inline int readint() {
  int d = 0;
  while (!isdigit(*ss)) ++ss;
  while (isdigit(*ss)) d = d * 10 + (*ss++ & 15);
  return d;
}
int n, m, s, t, head[N], cnt, sta[N], top, fa[N], i_f[N], nson[N], dep[N];
int status[N];
vector<pair<int, int>> vG[N];
bool vis[N];
pair<int, int> Es[N];
struct edge {
  int to, nxt, id;
} e[N << 1];
void dfs(int now) {
  vis[now] = 1;
  for (int i = head[now]; i; i = e[i].nxt)
    if (!vis[e[i].to]) {
      nson[now] = e[i].to, fa[e[i].to] = now, i_f[e[i].to] = e[i].id;
      dep[e[i].to] = dep[now] + 1;
      dfs(e[i].to);
    } else if (i_f[now] != e[i].id && dep[e[i].to] < dep[now])
      vG[nson[e[i].to]].emplace_back(now, e[i].id);
}
int main() {
  buf[fread(buf, 1, (int)1e8 - 1, stdin)] = '\n', fclose(stdin);
  for (int T = readint(); T--;) {
    n = readint(), m = readint(), s = readint(), t = readint();
    for (int i = 1; i <= n; ++i) vis[i] = head[i] = 0, vG[i].clear();
    cnt = 0;
    for (int i = 1; i <= m; ++i) {
      int u = readint(), v = readint();
      Es[i] = make_pair(u, v);
      e[++cnt] = (edge){v, head[u], i}, head[u] = cnt;
      e[++cnt] = (edge){u, head[v], i}, head[v] = cnt;
    }
    fa[s] = i_f[s] = dep[s] = 0;
    dfs(s);
    for (int i = 1; i <= m; ++i) status[i] = -1;
    sta[top = 1] = t;
    status[i_f[t]] = 0;
    for (; top;) {
      int u = sta[top--];
      if (u == s) continue;
      int ns = status[i_f[u]];
      if (!~status[i_f[fa[u]]]) status[i_f[sta[++top] = fa[u]]] = ns;
      for (auto to : vG[u]) {
        status[to.second] = ns;
        if (!~status[i_f[to.first]]) status[i_f[sta[++top] = to.first]] = !ns;
      }
    }
    bool ok = 1;
    for (int i = 1; i <= m; ++i)
      if (status[i] == -1) ok = 0;
    if (ok) {
      puts("Yes");
      for (int i = 1; i <= m; ++i) {
        int u = Es[i].first, v = Es[i].second;
        if (dep[u] > dep[v]) u ^= v ^= u ^= v;
        if (status[i])
          printf("%d %d\n", v, u);
        else
          printf("%d %d\n", u, v);
      }
    } else
      puts("No");
  }
  return 0;
}
