Not So Random (Large)

N machines each apply AND, OR, or XOR with K at given probabilities, and the expected output after chaining them must be computed.

Medium5Bit manipulationProbabilityMathNo attempts yetTime limit10sMemory limit512 MB

Problem

A "random number generator" (RNG) takes one nonnegative integer as input and returns one nonnegative integer as output. This machine is not very random. It uses a fixed number KK, and every time it performs exactly one of these three operations:

  • with probability A/100A/100, return the bitwise AND of the input and KK.
  • with probability B/100B/100, return the bitwise OR of the input and KK.
  • with probability C/100C/100, return the bitwise XOR of the input and KK.

The machine picks the operation according to AA, BB, and CC, and that choice is truly random and independent every time.

You have NN of these machines, wired in series so that the output of one machine is the input of the next. If you feed XX to the first machine, what is the expected value of the output of the last machine?

Input

The first line contains the number of test cases TT. Each of the next TT lines contains six integers NN, XX, KK, AA, BB, and CC, separated by spaces. In order, these are the number of machines, the initial input, the fixed number every machine uses for its bitwise operation, and 100 times the probabilities of choosing AND, OR, and XOR.

Limits

  • 1T501 \le T \le 50
  • 0A1000 \le A \le 100
  • 0B1000 \le B \le 100
  • 0C1000 \le C \le 100
  • A+B+C=100A + B + C = 100
  • 1N1051 \le N \le 10^5
  • 0X1090 \le X \le 10^9
  • 0K1090 \le K \le 10^9

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting from 1 and yy is the expected value of the output of the last machine, rounded to four decimal places. Always print exactly four digits after the decimal point, including trailing zeros.

In every test case the answer sits far from a rounding boundary, so double precision arithmetic gives the same output.

Hint

In the first test case of the sample, the final output is 5 if AND or OR happens and 0 if XOR happens. The probability of getting 5 is 0.1+0.5=0.60.1 + 0.5 = 0.6 and the probability of getting 0 is 0.40.4, so the expected value is 5×0.6+0×0.4=35 \times 0.6 + 0 \times 0.4 = 3.

In the second test case, the final output is 5 with probability 0.720.72 and 0 otherwise.