#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
inline int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int maxn=310;
int n,k,size[maxn],cnt,v[maxn],vis[maxn];
double f[maxn][maxn],C[maxn][maxn];
int main() {
int T=read();
C[0][0]=1;
rep(i,0,300) rep(j,0,i) C[i+1][j+1]+=C[i][j],C[i+1][j]+=C[i][j];
while(T--) {
n=read();k=read();cnt=0;
memset(size,0,sizeof(size));
memset(vis,0,sizeof(vis));
rep(i,1,n) v[i]=read();
rep(i,1,n) if(!vis[i]) {
cnt++;int j=i;
do size[cnt]++,vis[j]=1,j=v[j];while(j!=i);
}
memset(f,0,sizeof(f));
f[1][0]=1.0;int cur=0;
rep(i,1,cnt) {
rep(j,0,cur) rep(k0,1,size[i]) f[i+1][j+k0]+=f[i][j]*C[size[i]][k0];
cur+=size[i];
}
printf("%.6lf\n",f[cnt+1][k]/C[n][k]);
}
return 0;
}