#P10945. [2015杭电多校]Yet Another XYZ Problem

[2015杭电多校]Yet Another XYZ Problem

Yet Another XYZ Problem

Problem Description

You have two strings AA and BB which consist of x,y,zx,y,z. Every time, you can do one of the following three operations:

  1. Change all the xx in A into yy. This operation costs Cost0Cost0.
  2. Change all the yy in A into zz. This operation costs Cost1Cost1.
  3. Change all the zz in A into xx. This operation costs Cost2Cost2. One extra restriction is that when you operate any of these operations, the string AA needs to be changed. More specifically, when you operate the first operation, there should be at least one xx in string AA, etc. Please calculate how many different ways there are to change the string AA into string BB, while using not more than macCostmacCost total cost. The answer could be very large, so please print the actual answer module 109+710^9+7.

Input

The first line of the input is a single integer T (T1000)T\ (T \le 1000), indicating the number of testcases. For each of the testcases, the first line contains four integers $Cost0, Cost1, Cost2, maxCost(1 \le Cost0, Cost1, Cost2 \le 1e18, 0 \le maxCost \le 1e18)$. The second line contains the string AA, and the third line contains the string BB. It is guaranteed that the length of AA is the same with that of BB. The size of the input file is less than 5050 KB.

Output

For each testcase, print one integer indicating the answer.

Sample Input

3
1 1 1 0
x
x
1 1 1 0
x
y
1 1 1 10
x
x

Sample Output

1
0
4

Author

XJZX

Source

2015 Multi-University Training Contest 4