/*
jai shree ram _/\_
A hacker from NITP
*/
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef set<string> ss;
typedef vector<int> vs;
typedef map<int,char> msi;
typedef pair<int,int> pa;
typedef long long int ll;
vector<ll> v;
map<ll,int> m;
ll k;
void dfs(ll s)
{
if(m[s]>0)
return;
v.push_back(s);
m[s]=v.size();
dfs(s&k);
dfs(s|k);
dfs(s^k);
}
ll n,x,s,i,j;
long double a,b,c,ans,f[2][1000004];
int main()
{
//freopen("C-large-practicea.in", "r", stdin);
//freopen("C-large-practiceao.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
memset(f,0,sizeof(f));
int t,p=1;
cin>>t;
while(t--)
{
cout<<"Case #"<<p++<<": ";
cin>>n>>x>>k>>a>>b>>c;
a/=100; b/=100; c/=100;
m.clear();
v.clear();
dfs(x);
s=v.size();
f[1][(m[x&k]-1)]+=a; f[1][(m[x|k]-1)]+=b; f[1][(m[x^k]-1)]+=c;
for(i=1;i<n;i++)
{
for(j=0;j<s;j++)
f[(i+1)&1][j]=0;
for(j=0;j<s;j++)
{
f[(i+1)&1][(m[v[j]&k]-1)]+=f[i&1][j]*a;
f[(i+1)&1][(m[v[j]|k]-1)]+=f[i&1][j]*b;
f[(i+1)&1][(m[v[j]^k]-1)]+=f[i&1][j]*c;
}
}
ans=0;
for(j=0;j<s;j++)
ans+=(long double)f[n&1][j]*v[j];
cout<<fixed<<setprecision(12)<<ans<<"\n";
for(i=0;i<2;i++)
for(j=0;j<s;j++)
f[i][j]=0;
}
return 0;
}
LyoKamFpIHNocmVlIHJhbSBfL1xfCkEgaGFja2VyIGZyb20gTklUUAoqLwoKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKdHlwZWRlZiBzZXQ8c3RyaW5nPiBzczsKdHlwZWRlZiB2ZWN0b3I8aW50PiB2czsKdHlwZWRlZiBtY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TU0IDg5IDIgOQo5IDQ2NDYgMTQ3NiA0MSA4IDUxCjMgNzg0MCA0MDQ2IDIyIDMzIDQ1CjkgMjcxMCA3MDYxIDEwMCAwIDAKNiA0NzY5IDk0NzcgMjggMCA3Mgo0IDkzMTAgOTU0MCAyMiAzMyA0NQo1IDkzNTYgMjM3MiA0NSA0NyA4CjUgNTg3MSA4MzA2IDU5IDE0IDI3CjEgMTY2NyA2OTYgMjIgMzMgNDUKOSA1MTE3IDE0OTUgMjkgMzkgMzIKNyA4MDgyIDU5NjcgMjcgMjcgNDYKNSA5MjE2IDg3MDQgOTggMSAxCjEgMCA4MTkxIDEwIDgwIDEwCjEgOTIxNiA4NzA0IDk4IDEgMQo5IDY3ODMgNjQyNyA1OCAxMiAzMAo5IDM3MDQgMTYwMyA2OCAyMiAxMAoxIDkyMTYgODcwNCAxIDEgOTgKOSAyNDc0IDY3OTIgNDAgMjggMzIKMiA5OTEgNTIxMCAyMiAzMyA0NQo1IDkyMTYgODcwNCAxIDk4IDEKNyA2MjIyIDc5NzEgNzggNSAxNwo5IDU1OTAgMjc0OSAzMiAxOCA1MAoxMCA5MjE2IDg3MDQgMSAxIDk4CjggMzM2NCAyMTQ4IDc4IDMgMTkKNSA0NjMzIDc0MDIgMzMgNjYgMQo5IDgwNzggNTQ5MiA1MSAxNiAzMw==
4
6 4229 4808 66 21 13
7 1230 6598 35 29 36
8 5978 3308 71 29 0
9 7081 5231 78 9 13
8 7552 3703 52 18 30
5 2822 2887 32 66 2
10 8191 0 10 30 60
1 9216 8704 1 98 1
10 0 8191 10 80 10
9 9888 5834 55 16 29
5 8191 0 10 30 60
5 8525 2059 1 78 21
7 4188 6772 65 23 12
1 8191 0 10 30 60
9 5973 7383 53 1 46
5 6973 7672 19 27 54
10 9216 8704 33 33 34
5 9216 8704 1 1 98
5 5945 2829 46 39 15
8 7608 3150 66 28 6
10 9216 8704 98 1 1
5 0 8191 10 80 10
8 6738 4672 77 8 15
10 9216 8704 1 98 1
8 4951 5554 89 2 9
9 4646 1476 41 8 51
3 7840 4046 22 33 45
9 2710 7061 100 0 0
6 4769 9477 28 0 72
4 9310 9540 22 33 45
5 9356 2372 45 47 8
5 5871 8306 59 14 27
1 1667 696 22 33 45
9 5117 1495 29 39 32
7 8082 5967 27 27 46
5 9216 8704 98 1 1
1 0 8191 10 80 10
1 9216 8704 98 1 1
9 6783 6427 58 12 30
9 3704 1603 68 22 10
1 9216 8704 1 1 98
9 2474 6792 40 28 32
2 991 5210 22 33 45
5 9216 8704 1 98 1
7 6222 7971 78 5 17
9 5590 2749 32 18 50
10 9216 8704 1 1 98
8 3364 2148 78 3 19
5 4633 7402 33 66 1
9 8078 5492 51 16 33