#include <bits/stdc++.h>
using namespace std;
long double dp[6005], ndp[6005];
class BeatTheStar {
public:
double doesItMatter( int n, int g )
{
long long sum = n*(n+1)/2;
for(int j=0;j<6005;j++)
dp[j] = ndp[j] = 0;
dp[0] = 1;
for(int num=1;num<=n;num++)
{
// only consider elements other than g
if( num == g )
continue;
// transitions ( knapsack )
for(int s=0;s+num<=sum;s++)
{
// don't take num
ndp[s] += 0.5*dp[s];
// take num
ndp[num+s] += 0.5*dp[s];
}
// copy new layer to old layer, and reset new layer
for(int j=0;j<6005;j++)
{
dp[j] = ndp[j];
ndp[j] = 0;
}
}
long double ans = 0;
for(int s=0;s<=sum;s++)
{
// if s is the sum of a good subset
if( 2*s < sum && 2*(s + g) > sum )
{
// add probability of making s, without using g
ans += dp[s];
}
}
return ans;
}
};
int main()
{
BeatTheStar b;
int test;
cin>>test;
for(int i=0;i<test;i++)
{
int n,g;
cin>>n>>g;
cout<<fixed<<setprecision(4)<<b.doesItMatter(n,g)<<"\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpsb25nIGRvdWJsZSBkcFs2MDA1XSwgbmRwWzYwMDVdOwoKY2xhc3MgQmVhdFRoZVN0YXIgewoJcHVibGljOgoJZG91YmxlIGRvZXNJdE1hdHRlciggaW50IG4sIGludCBnICkgCgl7CgkJbG9uZyBsb25nIHN1bSA9IG4qKG4rMSkvMjsKCgkJZm9yKGludCBqPTA7ajw2MDA1O2orKykKCQkJZHBbal0gPSBuZHBbal0gPSAwOwoKCQlkcFswXSA9IDE7CgkJZm9yKGludCBudW09MTtudW08PW47bnVtKyspCgkJewoJCQkvLyBvbmx5IGNvbnNpZGVyIGVsZW1lbnRzIG90aGVyIHRoYW4gZwoJCQlpZiggbnVtID09IGcgKQoJCQkJY29udGludWU7CgoJCQkvLyB0cmFuc2l0aW9ucyAoIGtuYXBzYWNrICkKCQkJZm9yKGludCBzPTA7cytudW08PXN1bT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