// 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}, /** GREATEST ERROR tr[5][2] should have been 3 instead of 7 **/
{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+IHBvc2l0aW9uIG9mIChhcltpXSBYT1IgaykgaW4gYXJbXQppbnQgdHJbOF1bM109ewogICAgezAsIDcsIDd9LAogICAgezIsIDMsIDZ9LAogICAgezIsIDcsIDR9LAogICAgezcsIDMsIDV9LAogICAgezQsIDcsIDJ9LAogICAgezAsIDMsIDN9LCAvKiogR1JFQVRFU1QgRVJST1IgdHJbNV1bMl0gc2hvdWxkIGhhdmUgYmVlbiAzIGluc3RlYWQgb2YgNyAqKi8KICAgIHs0LCAzLCAxfSwKICAgIHs3LCA3LCAwfQp9OwoKaW50IG1haW4oKQp7CiAgICAvL2ZyZW9wZW4oImluLnR4dCIsInIiLHN0ZGluKTsKICAgIC8vZnJlb3BlbigidG8xLnR4dCIsInciLHN0ZG91dCk7CiAgICBpbnQgdCwgdGMsIG4sIGksIGosIGlhLCBpYiwgaWM7CiAgICB1aW50IHgsIG07CgogICAgc2NhbmYoIiVkIiwmdCk7CiAgICByZXAodGMsIHQpCiAgICB7CiAgICAgICAgcHJpbnRmKCJDYXNlICMlZDpcbiIsdGMrMSk7CiAgICAgICAgc2NhbmYoIiVkJXUldSVkJWQlZCIsICZuLCAmeCwgJmssICZpYSwgJmliLCAmaWMpOwogICAgICAgIGE9LjAxKmlhOyBiPS4wMSppYjsgYz0uMDEqaWM7CiAgICAgICAgCiAgICAgICAgLy8gQXJyYXkgb2YgYWxsIDggcG9zc2libGUgbnVtYmVycwogICAgICAgIHVpbnQgYXJbOF0gPSB7MCwgeCwgeCZrLCB4fGssICh+eCkmaywgeCYofmspLCB4XmssIGt9OwogICAgICAgIAogICAgICAgIC8vIENhbGN1bGF0aW5nIG15IGFuc3dlcgogICAgICAgIC8vIGhbaV1bal0gcmVwcmVzZW50cyBwcm9iYWJpbHR5IG9mIG51bWJlciBpIHVwdG8ganRoIG1hY2hpbmUKICAgICAgICBoWzFdWzBdPTEuMDAwMDAwMDA7CiAgICAgICAgZm9yKGo9MDsgajxuOyBqKyspCiAgICAgICAgewogICAgICAgICAgICBmb3IobT0wOyBtPDg7IG0rKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaFt0clttXVswXV1baisxXSs9YSpoW21dW2pdOwogICAgICAgICAgICAgICAgaFt0clttXVsxXV1baisxXSs9YipoW21dW2pdOwogICAgICAgICAgICAgICAgaFt0clttXVsyXV1baisxXSs9YypoW21dW2pdOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIAogICAgICAgIC8vIGcgc3RvcmVzIG15IGFuc3dlcgogICAgICAgIGZvcihqPTA7IGo8ODsgaisrKQogICAgICAgIHsKICAgICAgICAgICAgZys9YXJbal0qaFtqXVtuXTsKICAgICAgICB9CgoJCS8vIENhbGN1bGF0aW5nIGNvcnJlY3QgYW5zd2VyIChzb21lb25lIGVsc2UncyBjb2RlIGZvciByZWZlcmVuY2UpCiAgICAgICAgbTFbeF09MS4wMDAwMDAwMDsKICAgICAgICBmb3IoaW50IGk9MTtpPD1uO2krKykKICAgICAgICB7CiAgICAgICAgICAgIG0yLmNsZWFyKCk7CiAgICAgICAgICAgIGZvcihpdD1tMS5iZWdpbigpO2l0IT1tMS5lbmQoKTtpdCsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB1aW50IGo9aXQtPmZpcnN0OwogICAgICAgICAgICAgICAgZG91YmxlIGFiPWl0LT5zZWNvbmQ7CiAgICAgICAgICAgICAgICB1aW50IHA9aiZrOwogICAgICAgICAgICAgICAgbTJbcF0rPShkb3VibGUpKGEqYWIpOwogICAgICAgICAgICAgICAgcD1qfGs7CiAgICAgICAgICAgICAgICBtMltwXSs9KGRvdWJsZSkoYiphYik7CiAgICAgICAgICAgICAgICBwPWpeazsKICAgICAgICAgICAgICAgIG0yW3BdKz0oZG91YmxlKShjKmFiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBtMS5jbGVhcigpOwogICAgICAgICAgICBtMT1tMjsKICAgICAgICB9CiAgICAgICAgCgkJZG91YmxlIGFucz0wOwogICAgICAgIGZvcihpdD1tMS5iZWdpbigpOyBpdCE9bTEuZW5kKCk7IGl0KyspCiAgICAgICAgewogICAgICAgICAgICBhbnMrPWl0LT5maXJzdCppdC0+c2Vjb25kOwogICAgICAgIH0KCQkKCQkvKiogREVCVUcgT3V0cHV0IFNUQVJUICoqLwoJCXByaW50ZigiKipERUJVRyBPdXRwdXQgU3RhcnQqKlxuTnVtID0+ICU2cyAlOHNcbiIsICJteVByb2IiLCAiY29ycmVjdFByb2IiKTsKICAgICAgICBmb3Ioaj0wOyBqPDg7IGorKykKICAgICAgICB7CiAgICAgICAgICAgIHByaW50ZigiJXUgPT4gJS45bGYsICUuOWxmXG4iLCBhcltqXSwgbTFbYXJbal1dLCBoW2pdW25dKTsKICAgICAgICB9CiAgICAgICAgLy8gVGhlcmUgYXJlIG9ubHkgOCBwb3NzaWJsZSBudW1iZXJzIGFzIGNhbiBiZSBzZWVuIGZyb20gdGhlIG91dHB1dAogICAgICAgIHByaW50ZigiVG90YWwgbnVtYmVycz0ldSAiLCBtMS5zaXplKCkpOwogICAgICAgIHByaW50ZigiXG4qKkRFQlVHIE91dHB1dCBFTkQqKlxuIik7CiAgICAgICAgLyoqIERFQlVHIE91dHB1dCBFTkQgKiovCiAgICAgICAgCiAgICAgICAgcHJpbnRmKCJteS1hbnM9JS45bGYsIGNvcnJlY3QtYW5zPSUuOWxmXG5cbiIsIGcsIGFucyk7CiAgICAgICAgbTEuY2xlYXIoKTsKICAgICAgICBtMi5jbGVhcigpOwogICAgICAgIGZvcihqPTA7IGo8PW47IGorKykKICAgICAgICB7CiAgICAgICAgICAgIGZvcihrPTA7IGs8ODsgaysrKSBoW2tdW2pdPTA7CiAgICAgICAgfQogICAgICAgIGc9MDsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=
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