#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/ typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair< ll,ll> pl;
typedef pair< int ,int > pii;
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&y)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define F first
#define S second
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
const ll mod = 1000000007 ;
const ll inf = ( ll) 1e17 ;
const ld eps = 1e-12 ;
const ll N = ( int ) 1e5 + 2 ;
const ll LOGN = 19 ;
const ld PI = 3.14159265358979323846 ;
ll mul( ll a, ll b, ll m = mod) { return ( ll) ( a * b) % m; }
ll add( ll a, ll b, ll m = mod) { a + = b; if ( a >= m) a - = m; if ( a < 0 ) a + = m; return a; }
ll power( ll a, ll b, ll m = mod) { if ( b == 0 ) return 1 ; if ( b == 1 ) return ( a % m) ; ll x = power( a, b / 2 , m) ; x = mul( x, x, m) ; if ( b % 2 ) x = mul( x, a, m) ; return x; }
ll n,a,b;
vector< ll> adj[ N] ;
ll sz[ N] ;
ll par[ N] ;
void dfs( ll src,ll parent)
{
sz[ src] = 1 ;
for ( ll i : adj[ src] ) {
if ( i ! = parent) {
par[ i] = src;
dfs( i, src) ;
sz[ src] + = sz[ i] ;
}
}
}
int main( ) {
ios_base:: sync_with_stdio ( false ) ;
cin .tie ( NULL ) ;
if ( LOCAL) {
freopen ( "C:\\ Users\\ Dishant\\ Desktop\\ Collection-DEV c++\\ input.txt" , "r" , stdin ) ;
freopen ( "C:\\ Users\\ Dishant\\ Desktop\\ Collection-DEV c++\\ output.txt" , "w" , stdout ) ;
}
int t;
cin >> t;
while ( t-- )
{
cin >> n>> a>> b;
f( i,n+ 1 ) {
par[ i] = - 1 ;
sz[ i] = 0 ;
adj[ i] .clear ( ) ;
}
f( i,n- 1 )
{
ll u,v;
cin >> u>> v;
adj[ u] .pb ( v) ;
adj[ v] .pb ( u) ;
}
par[ a] = a;
dfs( a,a) ;
// rep(i,1,n+1)
// cout<<sz[i]<<" ";
// cout<<endl;
ll ver = par[ b] ;
ll child = b;
ll ans = 0 ;
while ( ver ! = a) {
ans + = ( ll) ( ( ll) ( sz[ ver] - sz[ child] ) * ( ll) ( sz[ a] - sz[ ver] ) ) ;
child = ver;
ver = par[ ver] ;
}
//ll ans = ((ll)(sz[a] - sz[ver]) * (ll)(sz[ver] - sz[b]));
ans + = ( ll) ( ( ll) ( sz[ a] - sz[ b] ) * ( ll) sz[ b] ) ;
cout << ans<< endl;
}
return 0 ;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKLyojaW5jbHVkZTxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KI2luY2x1ZGU8ZXh0L3BiX2RzL3RyZWVfcG9saWN5LmhwcD4KdXNpbmcgbmFtZXNwYWNlIF9fZ251X3BiZHM7Ci8qdGVtcGxhdGUgPHR5cGVuYW1lIFQ+CnVzaW5nIG9yZGVyZWRfc2V0ID0gdHJlZTxULCBudWxsX3R5cGUsIGxlc3M8VD4sIHJiX3RyZWVfdGFnLCB0cmVlX29yZGVyX3N0YXRpc3RpY3Nfbm9kZV91cGRhdGU+OwoqL3R5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGV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xcRGlzaGFudFxcRGVza3RvcFxcQ29sbGVjdGlvbi1ERVYgYysrXFxvdXRwdXQudHh0IiwgInciLCBzdGRvdXQpOwogICAgfQogICAgaW50IHQ7CiAgICBjaW4+PnQ7CiAgICB3aGlsZSh0LS0pCiAgICB7CiAgICAgICAgY2luPj5uPj5hPj5iOwogICAgICAgIGYoaSxuKzEpewogICAgICAgICAgICBwYXJbaV0gPSAtMTsKICAgICAgICAgICAgc3pbaV0gPSAwOwogICAgICAgICAgICBhZGpbaV0uY2xlYXIoKTsKICAgICAgICB9CiAgICAgICAgZihpLG4tMSkKICAgICAgICB7CiAgICAgICAgICAgIGxsIHUsdjsKICAgICAgICAgICAgY2luPj51Pj52OwogICAgICAgICAgICBhZGpbdV0ucGIodik7CiAgICAgICAgICAgIGFkalt2XS5wYih1KTsKICAgICAgICB9CiAgICAgICAgcGFyW2FdID0gYTsKICAgICAgICBkZnMoYSxhKTsKLy8gICAgICAgIHJlcChpLDEsbisxKQovLyAgICAgICAgICAgIGNvdXQ8PHN6W2ldPDwiICI7Ci8vICAgICAgICBjb3V0PDxlbmRsOwogICAgICAgIGxsIHZlciA9IHBhcltiXTsKICAgICAgICBsbCBjaGlsZCA9IGI7CiAgICAgICAgbGwgYW5zID0gMDsKICAgICAgICB3aGlsZSh2ZXIgIT0gYSkgewogICAgICAgICAgICBhbnMgKz0gKGxsKSgobGwpKHN6W3Zlcl0gLSBzeltjaGlsZF0pICogKGxsKShzelthXSAtIHN6W3Zlcl0pKTsKICAgICAgICAgICAgY2hpbGQgPSB2ZXI7CiAgICAgICAgICAgIHZlciA9IHBhclt2ZXJdOwogICAgICAgIH0KICAgICAgICAvL2xsIGFucyA9ICgobGwpKHN6W2FdIC0gc3pbdmVyXSkgKiAobGwpKHN6W3Zlcl0gLSBzeltiXSkpOwogICAgICAgIGFucyArPSAobGwpKChsbCkoc3pbYV0gLSBzeltiXSkgKiAobGwpc3pbYl0pOwogICAgICAgIGNvdXQ8PGFuczw8ZW5kbDsKICAgIH0KICAgIHJldHVybiAwOwp9