#include <bits/stdc++.h>
using namespace std;
long long 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] += dp[s];
// take num
ndp[num+s] += 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 )
{
// count ways of making s, without using g
ans += dp[s];
}
}
// divide by total outcomes ( number of subsets of 1..n without g )
ans /= pow(2,n-1);
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+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpsb25nIGxvbmcgZHBbNjAwNV0sIG5kcFs2MDA1XTsKCmNsYXNzIEJlYXRUaGVTdGFyIHsKCXB1YmxpYzoKCWRvdWJsZSBkb2VzSXRNYXR0ZXIoIGludCBuLCBpbnQgZyApIAoJewoJCWxvbmcgbG9uZyBzdW0gPSBuKihuKzEpLzI7CgoJCWZvcihpbnQgaj0wO2o8NjAwNTtqKyspCgkJCWRwW2pdID0gbmRwW2pdID0gMDsKCgkJZHBbMF0gPSAxOwoJCWZvcihpbnQgbnVtPTE7bnVtPD1uO251bSsrKQoJCXsKCQkJLy8gb25seSBjb25zaWRlciBlbGVtZW50cyBvdGhlciB0aGFuIGcKCQkJaWYoIG51bSA9PSBnICkKCQkJCWNvbnRpbnVlOwoKCQkJLy8gdHJhbnNpdGlvbnMgKCB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