Color Length

No attempts yetTime limit10sMemory limit128 MB

Problem

Several cars are driving down a road in a single line. Each car's color is written as a single uppercase letter, and the distance between two neighboring cars is always 11. So, counting from the front, the kk-th car is at position kk.

For a color cc, let location(c)\text{location}(c) be the set of positions of all cars whose color is cc. The length L(c)L(c) of color cc is defined as

L(c)=max{location(c)}min{location(c)}.L(c) = \max\{\text{location}(c)\} - \min\{\text{location}(c)\}.

For example, if the cars stand in the order G,Y,B,R,G,G,Y,RG, Y, B, R, G, G, Y, R from the front, their positions are 11 through 88, so location(G)={1,5,6}\text{location}(G) = \{1, 5, 6\}, location(Y)={2,7}\text{location}(Y) = \{2, 7\}, location(B)={3}\text{location}(B) = \{3\}, and location(R)={4,8}\text{location}(R) = \{4, 8\}. The length of each color and their total are as follows.

ColorGYBRSum
L(c)L(c)550414

Now a single road with four lanes (two lanes in each direction) is to be repaired. Traffic cannot be blocked completely, so the two lanes in one direction are merged into a single lane. The cars from the two lanes merge into one lane, and the front-to-back order within each lane is preserved during the merge. In other words, the two lines of cars are interleaved into one line, each keeping its own order. One line does not have to finish entering before the other begins; the two lines may also take turns entering. After merging, the distance between neighboring cars is still 11.

Even for the same two lines, the total color length cL(c)\sum_{c} L(c) depends on how they are merged. Given the color information of the two lines before merging, write a program that finds a way to merge the two lines into one so that the total color length is minimized, and outputs that minimum value.

Input

The first line contains the number of test cases TT. Each test case consists of two lines. The first line gives the colors of the cars in one lane, and the second line gives the colors of the cars in the other lane, each as a string of uppercase letters listed from the front with no spaces. Each color is an uppercase letter (from 'A' to 'Z'), so there are at most 26 colors. The number of cars in one lane is at least 1 and at most 5,000.

Output

For each test case, print on its own line the minimum possible total color length after merging the two lanes into one.