URI Online Judge | 1756
# Genetic Algorithm

**Timelimit: 1**

By Victor Marcilio Peixoto, UNIVASF Brazil

Some computer science courses are too much theorical and sometimes boring. In an attempt to raise the students' interest in some topics, the Artificial Intelligence professor, always when possible, propose a challenging contemplating the topics seen in class that day.

Today's lecture was about genetic algorithms and the professor explained the following procedure:

From 2 individuals (two sequences of N bits: x_{0}x_{1}...x_{N-1}) A and B, we choose a cut position Y ( 1 ≤ Y < N) and the crossover process happens, creating 2 new individuals: the first one is the concatenation of bits x_{0}...x_{Y-1} from individual A followed by bits x_{Y}..x_{N-1} from individual B, the second one is the concatenation of bits x_{0}...x_{Y-1} from individual B followed by bits x_{Y}..x_{N-1} from individual A.

The following image shows the result of a crossover with Y = 5.

After the crossover, each bit from the brand-new individuals may suffer mutation (change its value) according to a specified mutation probability **P**.

The challenge's statement left by the professor was the following:

"Write a program that takes as input 3 individuals, the cutting position and the mutation probability. The program must calculate the probability of obtaining the third individual as a result of a crossover between the other two."

The first line of input contains an integer **T **(1 ≤** T** ≤ 50), the number of test cases.

Each test case takes 5 lines.

The first line contains an integer **N** (2 ≤ **N** ≤ 8), the number of bits in each individual.

The second line contains an integer **Y** (1 ≤ **Y** < **N**) followed by a floating-point number **P **(0 ≤** P** ≤ 1), the cut position and the mutation probability, respectively.

The third line contains the first individual to be crossedover.

The fourth line contains the second individual to be crossedover.

The fifth line contains the individual that will be compared to the possible crossover results.

For each test case output a single line containing the answer with 7 digits after the decimal point.

Input Sample | Output Sample |

4 |
1.0000000 |