#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void upmax(T& first, T second) {
  first < second ? first = second : 0;
}
template <typename T>
inline void upmin(T& first, T second) {
  first > second ? first = second : 0;
}
template <typename T>
inline void read(T& first) {
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  for (first = c - '0'; (c = getchar()) >= '0' && c <= '9';
       first = first * 10 + c - '0')
    ;
}
const int inf = 0x3f3f3f3f;
const int N = 4e5 + 10, M = 1e6 + 10;
pair<int, int> edges[M];
vector<pair<int, int> > adj[N], aux[N];
int dir[M];
int fa[N], fae[N], dep[N], nxt[N];
bool vis[N];
int n, m, s, t;
stack<pair<int, int> > sta;
queue<pair<int, int> > que;
void work() {
  read(n), read(m);
  read(s), read(t);
  for (int i = (1), _ = (n); i <= _; ++i) {
    adj[i].clear();
    aux[i].clear();
    vis[i] = 0;
  }
  int first, second;
  for (int i = (1), _ = (m); i <= _; ++i) {
    read(edges[i].first), read(edges[i].second);
    adj[edges[i].first].push_back(make_pair(edges[i].second, i));
    adj[edges[i].second].push_back(make_pair(edges[i].first, i));
    dir[i] = -1;
  }
  dep[s] = 0;
  fa[s] = 0;
  vis[s] = 1;
  sta.push(make_pair(s, 0));
  while (!sta.empty()) {
    pair<int, int> u = make_pair(sta.top().first, sta.top().second++);
    if (u.second == adj[u.first].size()) {
      sta.pop();
      continue;
    }
    int to = adj[u.first][u.second].first;
    if (to == fa[u.first]) continue;
    if (!vis[to]) {
      vis[to] = 1;
      nxt[u.first] = to;
      dep[to] = dep[u.first] + 1;
      fa[to] = u.first;
      fae[to] = adj[u.first][u.second].second;
      sta.push(make_pair(to, 0));
    } else if (dep[to] < dep[u.first]) {
      aux[nxt[to]].push_back(make_pair(u.first, adj[u.first][u.second].second));
    }
  }
  if (!vis[t]) {
    puts("No");
    return;
  }
  que.push(make_pair(t, 1));
  while (!que.empty()) {
    pair<int, int> u = que.front();
    que.pop();
    while (fa[u.first] && dir[fae[u.first]] == -1) {
      dir[fae[u.first]] = u.second;
      for (auto p : aux[u.first]) {
        dir[p.second] = u.second;
        que.push(make_pair(p.first, u.second ^ 1));
      }
      u.first = fa[u.first];
    }
  }
  for (int i = (1), _ = (m); i <= _; ++i) {
    if (dir[i] == -1) {
      puts("No");
      return;
    }
  }
  puts("Yes");
  for (int i = (1), _ = (m); i <= _; ++i) {
    if ((dep[edges[i].first] < dep[edges[i].second]) != dir[i])
      swap(edges[i].first, edges[i].second);
    printf("%d %d\n", edges[i].first, edges[i].second);
  }
}
int main() {
  int kase;
  read(kase);
  while (kase--) work();
  return 0;
}
