// https://code.google.com/codejam/contest/8264486/dashboard#s=p2
#include<bits/stdc++.h>
#define uint unsigned int
#define ll long long
#define rep(i, n) for(i=0; i<n; i++)
using namespace std;
uint k;
double a, b, c, g;
map<uint,double> m1,m2;
map<uint,double>::const_iterator it;
double h[8][100001];
// Transition table tr[8][3]
// tr[i][0] => position of (ar[i] AND k) in ar[]
// tr[i][1] => position of (ar[i] OR k) in ar[]
// tr[i][2] => position of (ar[i] XOR k) in ar[]
int tr[8][3]={
{0, 7, 7},
{2, 3, 6},
{2, 7, 4},
{7, 3, 5},
{4, 7, 2},
{0, 3, 3},
{4, 3, 1},
{7, 7, 0}
};
int main()
{
//freopen("in.txt","r",stdin);
//freopen("to1.txt","w",stdout);
int t, tc, n, i, j, ia, ib, ic;
uint x, m;
scanf("%d",&t);
rep(tc, t)
{
printf("Case #%d:\n",tc+1);
scanf("%d%u%u%d%d%d", &n, &x, &k, &ia, &ib, &ic);
a=.01*ia; b=.01*ib; c=.01*ic;
// Array of all 8 possible numbers
uint ar[8] = {0, x, x&k, x|k, (~x)&k, x&(~k), x^k, k};
// Calculating my answer
// h[i][j] represents probabilty of number i upto jth machine
h[1][0]=1.00000000;
for(j=0; j<n; j++)
{
for(m=0; m<8; m++)
{
h[tr[m][0]][j+1]+=a*h[m][j];
h[tr[m][1]][j+1]+=b*h[m][j];
h[tr[m][2]][j+1]+=c*h[m][j];
}
}
// g stores my answer
for(j=0; j<8; j++)
{
g+=ar[j]*h[j][n];
}
// Calculating correct answer (someone else's code for reference)
m1[x]=1.00000000;
for(int i=1;i<=n;i++)
{
m2.clear();
for(it=m1.begin();it!=m1.end();it++)
{
uint j=it->first;
double ab=it->second;
uint p=j&k;
m2[p]+=(double)(a*ab);
p=j|k;
m2[p]+=(double)(b*ab);
p=j^k;
m2[p]+=(double)(c*ab);
}
m1.clear();
m1=m2;
}
double ans=0;
for(it=m1.begin(); it!=m1.end(); it++)
{
ans+=it->first*it->second;
}
/** DEBUG Output START **/
printf("**DEBUG Output Start**\nNum => %6s %8s\n", "myProb", "correctProb");
for(j=0; j<8; j++)
{
printf("%u => %.9lf, %.9lf\n", ar[j], m1[ar[j]], h[j][n]);
}
// There are only 8 possible numbers as can be seen from the output
printf("Total numbers=%u ", m1.size());
printf("\n**DEBUG Output END**\n");
/** DEBUG Output END **/
printf("my-ans=%.9lf, correct-ans=%.9lf\n\n", g, ans);
m1.clear();
m2.clear();
for(j=0; j<=n; j++)
{
for(k=0; k<8; k++) h[k][j]=0;
}
g=0;
}
return 0;
}
Ly8gaHR0cHM6Ly9jb2RlLmdvb2dsZS5jb20vY29kZWphbS9jb250ZXN0LzgyNjQ0ODYvZGFzaGJvYXJkI3M9cDIKCiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIHVpbnQgdW5zaWduZWQgaW50CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgcmVwKGksIG4pIGZvcihpPTA7IGk8bjsgaSsrKQoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnVpbnQgazsKZG91YmxlIGEsIGIsIGMsIGc7Cm1hcDx1aW50LGRvdWJsZT4gbTEsbTI7Cm1hcDx1aW50LGRvdWJsZT46OmNvbnN0X2l0ZXJhdG9yIGl0OwoKZG91YmxlIGhbOF1bMTAwMDAxXTsKCi8vIFRyYW5zaXRpb24gdGFibGUgdHJbOF1bM10KLy8gdHJbaV1bMF0gPT4gcG9zaXRpb24gb2YgKGFyW2ldIEFORCBrKSBpbiBhcltdCi8vIHRyW2ldWzFdID0+IHBvc2l0aW9uIG9mIChhcltpXSBPUiBrKSBpbiBhcltdCi8vIHRyW2ldWzJdID0+IHBvc2l0aW9uIG9mIChhcltpXSBYT1IgaykgaW4gYXJbXQppbnQgdHJbOF1bM109ewogICAgezAsIDcsIDd9LAogICAgezIsIDMsIDZ9LAogICAgezIsIDcsIDR9LAogICAgezcsIDMsIDV9LAogICAgezQsIDcsIDJ9LAogICAgezAsIDMsIDN9LAogICAgezQsIDMsIDF9LAogICAgezcsIDcsIDB9Cn07CgppbnQgbWFpbigpCnsKICAgIC8vZnJlb3BlbigiaW4udHh0IiwiciIsc3RkaW4pOwogICAgLy9mcmVvcGVuKCJ0bzEudHh0IiwidyIsc3Rkb3V0KTsKICAgIGludCB0LCB0YywgbiwgaSwgaiwgaWEsIGliLCBpYzsKICAgIHVpbnQgeCwgbTsKCiAgICBzY2FuZigiJWQiLCZ0KTsKICAgIHJlcCh0YywgdCkKICAgIHsKICAgICAgICBwcmludGYoIkNhc2UgIyVkOlxuIix0YysxKTsKICAgICAgICBzY2FuZigiJWQldSV1JWQlZCVkIiwgJm4sICZ4LCAmaywgJmlhLCAmaWIsICZpYyk7CiAgICAgICAgYT0uMDEqaWE7IGI9LjAxKmliOyBjPS4wMSppYzsKICAgICAgICAKICAgICAgICAvLyBBcnJheSBvZiBhbGwgOCBwb3NzaWJsZSBudW1iZXJzCiAgICAgICAgdWludCBhcls4XSA9IHswLCB4LCB4JmssIHh8aywgKH54KSZrLCB4Jih+ayksIHheaywga307CiAgICAgICAgCiAgICAgICAgLy8gQ2FsY3VsYXRpbmcgbXkgYW5zd2VyCiAgICAgICAgLy8gaFtpXVtqXSByZXByZXNlbnRzIHByb2JhYmlsdHkgb2YgbnVtYmVyIGkgdXB0byBqdGggbWFjaGluZQogICAgICAgIGhbMV1bMF09MS4wMDAwMDAwMDsKICAgICAgICBmb3Ioaj0wOyBqPG47IGorKykKICAgICAgICB7CiAgICAgICAgICAgIGZvcihtPTA7IG08ODsgbSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBoW3RyW21dWzBdXVtqKzFdKz1hKmhbbV1bal07CiAgICAgICAgICAgICAgICBoW3RyW21dWzFdXVtqKzFdKz1iKmhbbV1bal07CiAgICAgICAgICAgICAgICBoW3RyW21dWzJdXVtqKzFdKz1jKmhbbV1bal07CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgCiAgICAgICAgLy8gZyBzdG9yZXMgbXkgYW5zd2VyCiAgICAgICAgZm9yKGo9MDsgajw4OyBqKyspCiAgICAgICAgewogICAgICAgICAgICBnKz1hcltqXSpoW2pdW25dOwogICAgICAgIH0KCgkJLy8gQ2FsY3VsYXRpbmcgY29ycmVjdCBhbnN3ZXIgKHNvbWVvbmUgZWxzZSdzIGNvZGUgZm9yIHJlZmVyZW5jZSkKICAgICAgICBtMVt4XT0xLjAwMDAwMDAwOwogICAgICAgIGZvcihpbnQgaT0xO2k8PW47aSsrKQogICAgICAgIHsKICAgICAgICAgICAgbTIuY2xlYXIoKTsKICAgICAgICAgICAgZm9yKGl0PW0xLmJlZ2luKCk7aXQhPW0xLmVuZCgpO2l0KyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHVpbnQgaj1pdC0+Zmlyc3Q7CiAgICAgICAgICAgICAgICBkb3VibGUgYWI9aXQtPnNlY29uZDsKICAgICAgICAgICAgICAgIHVpbnQgcD1qJms7CiAgICAgICAgICAgICAgICBtMltwXSs9KGRvdWJsZSkoYSphYik7CiAgICAgICAgICAgICAgICBwPWp8azsKICAgICAgICAgICAgICAgIG0yW3BdKz0oZG91YmxlKShiKmFiKTsKICAgICAgICAgICAgICAgIHA9al5rOwogICAgICAgICAgICAgICAgbTJbcF0rPShkb3VibGUpKGMqYWIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG0xLmNsZWFyKCk7CiAgICAgICAgICAgIG0xPW0yOwogICAgICAgIH0KICAgICAgICAKCQlkb3VibGUgYW5zPTA7CiAgICAgICAgZm9yKGl0PW0xLmJlZ2luKCk7IGl0IT1tMS5lbmQoKTsgaXQrKykKICAgICAgICB7CiAgICAgICAgICAgIGFucys9aXQtPmZpcnN0Kml0LT5zZWNvbmQ7CiAgICAgICAgfQoJCQoJCS8qKiBERUJVRyBPdXRwdXQgU1RBUlQgKiovCgkJcHJpbnRmKCIqKkRFQlVHIE91dHB1dCBTdGFydCoqXG5OdW0gPT4gJTZzICU4c1xuIiwgIm15UHJvYiIsICJjb3JyZWN0UHJvYiIpOwogICAgICAgIGZvcihqPTA7IGo8ODsgaisrKQogICAgICAgIHsKICAgICAgICAgICAgcHJpbnRmKCIldSA9PiAlLjlsZiwgJS45bGZcbiIsIGFyW2pdLCBtMVthcltqXV0sIGhbal1bbl0pOwogICAgICAgIH0KICAgICAgICAvLyBUaGVyZSBhcmUgb25seSA4IHBvc3NpYmxlIG51bWJlcnMgYXMgY2FuIGJlIHNlZW4gZnJvbSB0aGUgb3V0cHV0CiAgICAgICAgcHJpbnRmKCJUb3RhbCBudW1iZXJzPSV1ICIsIG0xLnNpemUoKSk7CiAgICAgICAgcHJpbnRmKCJcbioqREVCVUcgT3V0cHV0IEVORCoqXG4iKTsKICAgICAgICAvKiogREVCVUcgT3V0cHV0IEVORCAqKi8KICAgICAgICAKICAgICAgICBwcmludGYoIm15LWFucz0lLjlsZiwgY29ycmVjdC1hbnM9JS45bGZcblxuIiwgZywgYW5zKTsKICAgICAgICBtMS5jbGVhcigpOwogICAgICAgIG0yLmNsZWFyKCk7CiAgICAgICAgZm9yKGo9MDsgajw9bjsgaisrKQogICAgICAgIHsKICAgICAgICAgICAgZm9yKGs9MDsgazw4OyBrKyspIGhba11bal09MDsKICAgICAgICB9CiAgICAgICAgZz0wOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==
Case #1:
**DEBUG Output Start**
Num => myProb correctProb
0 => 0.159577678, 0.159577678
4229 => 0.000004827, 0.000004827
4224 => 0.132621082, 0.132621082
4813 => 0.001114026, 0.001114026
584 => 0.110461547, 0.110461547
5 => 0.000425951, 0.000425951
589 => 0.000000000, 0.000000000
4808 => 0.595794889, 0.595794889
Total numbers=8
**DEBUG Output END**
my-ans=3494.667167506, correct-ans=3494.667167506
Case #2:
**DEBUG Output Start**
Num => myProb correctProb
0 => 0.293991079, 0.293991079
1230 => 0.000000000, 0.000000000
198 => 0.045475601, 0.045475601
7630 => 0.031269674, 0.031269674
6400 => 0.044691959, 0.044691959
1032 => 0.016968964, 0.016968964
7432 => 0.000783642, 0.000783642
6598 => 0.566819082, 0.566819082
Total numbers=8
**DEBUG Output END**
my-ans=4296.828615594, correct-ans=4296.828615594
Case #3:
**DEBUG Output Start**
Num => myProb correctProb
0 => 0.000000000, 0.000000000
5978 => 0.000000000, 0.000000000
1096 => 0.064575353, 0.064575353
8190 => 0.000050025, 0.000050025
2212 => 0.000000000, 0.000000000
4882 => 0.000000000, 0.000000000
7094 => 0.000000000, 0.000000000
3308 => 0.935374622, 0.935374622
Total numbers=8
**DEBUG Output END**
my-ans=3165.403539187, correct-ans=3165.403539187
Case #4:
**DEBUG Output Start**
Num => myProb correctProb
0 => 0.160126190, 0.160126190
7081 => 0.000000000, 0.000000000
4137 => 0.224320856, 0.224320856
8175 => 0.000000755, 0.000000755
1094 => 0.203608933, 0.203608933
2944 => 0.000000442, 0.000000442
4038 => 0.000000011, 0.000000011
5231 => 0.411942813, 0.411942813
Total numbers=8
**DEBUG Output END**
my-ans=3305.643927519, correct-ans=3305.643927519