F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Yet Another XYZ Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 220    Accepted Submission(s): 40


Problem Description
You have two strings $A$ and $B$ which consist of $x,y,z$. Every time, you can do one of the following three operations:

1. Change all the $x$ in A into $y$. This operation costs $Cost0$.
2. Change all the $y$ in A into $z$. This operation costs $Cost1$.
3. Change all the $z$ in A into $x$. This operation costs $Cost2$.

One extra restriction is that when you operate any of these operations, the string $A$ needs to be changed. More specifically, when you operate the first operation, there should be at least one $x$ in string $A$, etc. Please calculate how many different ways there are to change the string $A$ into string $B$, while using not more than $macCost$ total cost. The answer could be very large, so please print the actual answer module $10^9+7$.
 

Input
The first line of the input is a single integer $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 $A$, and the third line contains the string $B$. It is guaranteed that the length of $A$ is the same with that of $B$.

The size of the input file is less than $50$ 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
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 20:21:46, Gzip enabled