|
The far-off land of Tamriel is brimming with opportunity! Opportunity for |
|
adventure, politics, romance... and, perhaps most importantly of all, |
|
commerce. |
|
|
|
A group of Khajiit merchants, traditionally known for roaming the countryside |
|
selling their wares, have recently set up permanent bazaars in a number of |
|
towns. Having gotten their cat-like paws on a large supply of raw amber and |
|
bronze, they're prepared to strategically work together to maximize their |
|
profits selling it! |
|
|
|
One bazaar has been set up in each of **N*****M**+1 towns. The towns are |
|
numbered from 0 to **N*****M**, inclusive, and are connected by roads in a |
|
hub-and-spokes arrangement, with town 0 in the center and **N** lines of **M** |
|
towns each arranged around it. The _i_th such line consists of towns |
|
**M***(_i_-1)+1 to **M***_i_, inclusive, connected together in order by |
|
**M**-1 roads (with one between towns **M***(_i_-1)+1 and **M***(_i_-1)+2, |
|
another between towns **M***(_i_-1)+2 and **M***(_i_-1)+3, and so on). For |
|
each line _i_, there is furthermore a road connecting its first town |
|
(**M***(_i_-1)+1) to town 0. Note that each of the **N*****M** roads may be |
|
travelled in either direction, and that each town may be reached from each |
|
other town by following a sequence of roads. |
|
|
|
For example, if **N**=4 and **M**=2, the arrangement of towns and roads would |
|
look as follows: |
|
|
|
 |
|
|
|
Initially, the bazaar in each town _i_ is stocked with either amber (if **Xi** |
|
= "A") or bronze (if **Xi** = "B"). However, in order to satisfy demand, it |
|
should end up stocked with a potentially different ware, either amber (if |
|
**Yi** = "A") or bronze (if **Yi** = "B"). It's guaranteed that the number of |
|
bazaars initially stocked with amber is equal to the number of bazaars which |
|
should end up stocked with amber (consequently, the same holds true for |
|
bronze). |
|
|
|
In order to accomplish their goal, the Khajiit merchants may repeatedly select |
|
a pair of towns which are directly connected by a road, and swap their |
|
bazaars' wares. Please help them determine the minimum number of such swaps |
|
required for all **N*****M**+1 bazaars to end up stocked with the required |
|
wares! This is guaranteed to be possible for every possible valid input. |
|
|
|
### Input |
|
|
|
Input begins with an integer **T**, the number of Khajiit groups. |
|
For each group, there is first a line containing the space-separated integers |
|
**N** and **M**. |
|
Then follows a line with the length-(**N** * **M** \+ 1) string **X**, the |
|
characters **X0** through **XN*M**. |
|
Then follows a line with the length-(**N** * **M** \+ 1) string **Y**, the |
|
characters **Y0** through **YN*M**. |
|
|
|
### Output |
|
|
|
For the _i_th group, print a line containing "Case #_i_: " followed by one |
|
integer, the minimum number of swaps required to stock all of the bazaars with |
|
the required wares. |
|
|
|
### Constraints |
|
|
|
1 ≤ **T** ≤ 80 |
|
1 ≤ **N**, **M** ≤ 1,000,000 |
|
1 ≤ **N** * **M** ≤ 1,000,000 |
|
|
|
The sum of **N** * **M** across all **T** test cases is no greater than |
|
10,000,000. |
|
|
|
### Explanation of Sample |
|
|
|
In the first case, no swaps are required. |
|
|
|
In the second case, bazaars 1 and 2 should swap their goods. |
|
|
|
In the third case, the bazaars are initially set up as follows (with ones |
|
carrying amber marked in yellow, and ones carrying bronze marked in orange): |
|
|
|
 |
|
|
|
The following sequence of 3 swaps could then be performed to arrive at the |
|
required configuration: |
|
|
|
 |
|
 |
|
 |
|
|
|
|