## Word equations

## POI V Stage 2 Problem 2## Word equations
Every non-empty sequence of elements 0 and 1 is called a binary
word. A word equation is an equation of the form
x For a given equation compute how many distinct solutions it has. ## ExampleLet a, b, c, d, e be variables and let 4,2,4,4,2 be their lengths (4 is the length of a, 2 is the length of b etc.). Consider the equation:1bad1 = acbeThis equation has 16 distinct solutions. ## TaskWrite a program, that- reads the number of equations and their descriptions from the text file PRO.IN;
- finds the number of solutions of every equation;
- writes the results to the text file ROW.OUT.
## InputIn the first line of the input file ROW.IN there is an integer x, 1 <= x <= 5, which denotes the number of equations. The following lines contain descriptions of x equations. Each description consists of 6 lines. There are no empty lines between descriptions. Each equation is described in the following way: in the first line of the description there is an integer k, 0 <= k <= 26, which denotes the number of distinct variables in the equation. We assume that variables are the first k small letters of English alphabet. In the second line there is a sequence of k positive integers separated by single spaces. These numbers denote the lengths of variables a,b,.. from the equation (the first number is the length of a, the second - b, etc.). There is an integer l in the third line of the description, which is the length of the left size of equation, i.e. the length of the word built of digits 0 or 1 and variables (single letters). The left side of the equation is written in the next line as a sequence of digits and variables with no spaces between them. The next two lines contain the description of the right side of the equation. The first of these lines contains a positive integer r, which is the length of the right side of the equation. The second line contains the right side of the equation which is encoded in the same way as the left side. The number of digits plus sum of the lengths of variables (we count all appearances of variables) on each side of the equation is not greater than 10000.## OutputFor every i, 1 <= i <= x, your program should write the number of distinct solutions of the i-th equation to the i-th line of the output file ROW.OUT.## Sample Input1 5 4 2 4 4 2 5 1bad1 4 acbe ## Sample Output16SubmitStatistics |