/*
author: kartik8800
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(int i = a; i < b; i++)
#define rep(i,a,b) for(int i = a; i < b; i++)
#define mod 1000000007
#define inf (1LL<<60)
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
ll dp[500001][2];
vector<int> tree[500001];
void whatsWithThisOPFormat(){
static int tno = 1;
cout << "Case #" <<tno++ <<": ";
}
void solve(int src, int par, vector<int>& ancestors, int& dis, bool aOrb){
dp[src][aOrb] = 1;
ancestors.push_back(src);
for(int child : tree[src])
{
if(child != par)
solve(child, src, ancestors, dis, aOrb);
}
ancestors.pop_back();
int totalAncestors = ancestors.size();
if(totalAncestors >= dis){
dp[ancestors[totalAncestors - dis]][aOrb] += dp[src][aOrb];
}
}
int main() {
fast_io;
ll t,n,m,x,i,j,k,q;
cin >> t;
//t = 1;
while(t--)
{
int a,b;
cin >> n >> a >> b;
fr(1,n+1)tree[i].clear();
fr(0,n-1)
{
cin >> x;
tree[i+2].push_back(x);
tree[x].push_back(i+2);
}
vector<int> dfsOfTree;
solve(1,0,dfsOfTree, a, 0);
solve(1,0,dfsOfTree, b, 1);
double ans = 0;
for(int i = 1; i <= n; i++){
ans = (ans + 1ll*n*(dp[i][0] + dp[i][1]));
ans = (ans - 1ll*dp[i][0]*dp[i][1]);
}
whatsWithThisOPFormat();
prDouble (((double)ans/(double)(n*n)));
cout << '\n';
}
return 0;
}
LyoKICAgIGF1dGhvcjoga2FydGlrODgwMAoqLwoKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBmcihhLGIpIGZvcihpbnQgaSA9IGE7IGkgPCBiOyBpKyspCiNkZWZpbmUgcmVwKGksYSxiKSBmb3IoaW50IGkgPS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bYU9yYl0gKz0gZHBbc3JjXVthT3JiXTsKICAgIH0KfQoKaW50IG1haW4oKSB7CiAgIGZhc3RfaW87CiAgIGxsIHQsbixtLHgsaSxqLGsscTsKICAgY2luID4+IHQ7CiAgIC8vdCA9IDE7CiAgIHdoaWxlKHQtLSkKICAgewogICAgICAgIGludCBhLGI7CiAgICAgICAgY2luID4+IG4gPj4gYSA+PiBiOwogICAgICAgIGZyKDEsbisxKXRyZWVbaV0uY2xlYXIoKTsKCiAgICAgICAgZnIoMCxuLTEpCiAgICAgICAgewogICAgICAgICAgICBjaW4gPj4geDsKICAgICAgICAgICAgdHJlZVtpKzJdLnB1c2hfYmFjayh4KTsKICAgICAgICAgICAgdHJlZVt4XS5wdXNoX2JhY2soaSsyKTsKICAgICAgICB9CgogICAgICAgIHZlY3RvcjxpbnQ+IGRmc09mVHJlZTsKCiAgICAgICAgc29sdmUoMSwwLGRmc09mVHJlZSwgYSwgMCk7CiAgICAgICAgc29sdmUoMSwwLGRmc09mVHJlZSwgYiwgMSk7CgogICAgICAgIGRvdWJsZSBhbnMgPSAwOwoKICAgICAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47IGkrKyl7CiAgICAgICAgICAgIGFucyA9IChhbnMgKyAxbGwqbiooZHBbaV1bMF0gKyBkcFtpXVsxXSkpOwogICAgICAgICAgICBhbnMgPSAoYW5zIC0gMWxsKmRwW2ldWzBdKmRwW2ldWzFdKTsKICAgICAgICB9CgoKICAgICAgICB3aGF0c1dpdGhUaGlzT1BGb3JtYXQoKTsKICAgICAgICBwckRvdWJsZSAoKChkb3VibGUpYW5zLyhkb3VibGUpKG4qbikpKTsKICAgICAgICBjb3V0IDw8ICdcbic7CiAgIH0KICAgcmV0dXJuIDA7Cn0=