#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int m) {
  if (y == 0) return 1;
  long long int a = power(x, y / 2, m);
  if (y % 2) {
    return (a * ((a * x) % m)) % m;
  } else {
    return (a * a) % m;
  }
}
long long int mod_inverse(long long int x, long long int m) {
  return power(x, m - 2, m);
}
long long int fact(long long int n, long long int m) {
  if (n <= 1) return 1;
  return (fact(n - 1, m) * n) % m;
}
long long int ncr(long long int n, long long int r, long long int m) {
  if (r > n) return 0;
  long long int n1 = 1, d1 = 1, d2 = 1;
  n1 = fact(n, m);
  d1 = fact(r, m);
  d2 = fact(n - r, m);
  long long int ans = mod_inverse((d1 * d2) % m, m);
  ans = (ans * n1) % m;
  return ans;
}
int ispal(string s) {
  int len = s.size();
  int flag = 1;
  for (int i = 0; i < len; ++i) {
    if (s[i] != s[len - i - 1]) {
      flag = 0;
      break;
    }
  }
  return flag;
}
long long int sroot(long long int n, long long int low = 1,
                    long long int high = 1e9 + 1) {
  if (low == high) return low;
  if (low == high - 1) {
    if (high * high <= n)
      return high;
    else
      return low;
  }
  long long int mid = (low + high) / 2;
  long long int a = mid * mid;
  if (a > n)
    return sroot(n, low, mid - 1);
  else
    return sroot(n, mid, high);
}
long long int croot(long long int n, long long int low = 1,
                    long long int high = 1e6 + 1) {
  if (low == high) return low;
  if (low == high - 1) {
    if (high * high * high <= n)
      return high;
    else
      return low;
  }
  long long int mid = (low + high) / 2;
  long long int a = mid * mid * mid;
  if (a > n)
    return croot(n, low, mid - 1);
  else
    return croot(n, mid, high);
}
class solver {
 public:
  int n, m, a, b;
  vector<int> *g;
  vector<int> visa, visb;
  void dfs1(int u) {
    if (u != a && u != b) visa[u] = 1;
    if (u == b) return;
    int ln = g[u].size();
    for (int i = 0; i <= ln - 1; ++i) {
      int v = g[u][i];
      if (visa[v] == 1) continue;
      dfs1(v);
    }
  }
  void dfs2(int u) {
    if (u != a && u != b) visb[u] = 1;
    if (u == a) return;
    int ln = g[u].size();
    for (int i = 0; i <= ln - 1; ++i) {
      int v = g[u][i];
      if (visb[v] == 1) continue;
      dfs2(v);
    }
  }
  void solve() {
    cin >> n >> m >> a >> b;
    g = new vector<int>[n + 1];
    visa = vector<int>(n + 1, 0);
    visb = vector<int>(n + 1, 0);
    for (int i = 1; i <= m; ++i) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs1(a);
    dfs2(b);
    long long int t1 = 0, t2 = 0;
    for (int i = 1; i <= n; ++i) {
      if (visa[i] == 1 && visb[i] == 0) t1++;
      if (visb[i] == 1 && visa[i] == 0) t2++;
    }
    cout << t1 * t2 << '\n';
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test = 1;
  cin >> test;
  while (test--) {
    solver o;
    o.solve();
  }
  return 0;
}
