#include <bits/stdc++.h>
using namespace std;
const int N = 2001000;
int dp[N], fa[N], sub[N], tf[N], to[N], tag[N], n, m, S, T, cas;
vector<int> vec[N], g[N];
void dfs(int x) {
  dp[x] = dp[fa[x]] + 1;
  for (int i : g[x])
    if (to[i] != fa[x]) {
      if (!dp[to[i]]) {
        fa[to[i]] = x;
        tf[to[i]] = i;
        sub[x] = to[i];
        dfs(to[i]);
      } else if (dp[to[i]] < dp[x])
        vec[sub[to[i]]].push_back(i);
    }
}
void clear() {
  for (int i = 1; i <= n; ++i)
    dp[i] = fa[i] = tf[i] = 0, g[i].clear(), vec[i].clear();
}
pair<int, int> q[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (cin >> cas; cas--;) {
    cin >> n >> m >> S >> T;
    for (int i = 0; i < m; ++i) {
      cin >> to[2 * i] >> to[2 * i + 1];
      tag[i] = -1;
      g[to[2 * i]].push_back(2 * i + 1);
      g[to[2 * i + 1]].push_back(2 * i);
    }
    dfs(S);
    int t = -1, w = 0;
    q[0] = make_pair(T, 0);
    for (; t < w;) {
      ++t;
      int i = q[t].first, op = q[t].second;
      for (; fa[i] && tag[tf[i] / 2] == -1; i = fa[i]) {
        tag[tf[i] / 2] = op;
        for (int j : vec[i])
          tag[j / 2] = op, q[++w] = make_pair(to[j ^ 1], !op);
      }
    }
    int flag = 1;
    for (int i = 0; i < m; ++i)
      if (tag[i] == -1) flag = 0;
    if (!flag)
      cout << "No\n";
    else {
      cout << "Yes\n";
      for (int i = 0; i < m; ++i)
        if (tag[i] ^ (dp[to[2 * i]] < dp[to[2 * i + 1]]))
          cout << to[2 * i] << ' ' << to[2 * i + 1] << '\n';
        else
          cout << to[2 * i + 1] << ' ' << to[2 * i] << '\n';
    }
    clear();
  }
  return 0;
}
