#P1383C. String Transformation 2

    ID: 5472 Type: RemoteJudge 3000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>bitmasksdpgraphstrees*3100

String Transformation 2

No submission language available for this problem.

Description

Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter yy Koa selects can be any letter from the first 2020 lowercase letters of English alphabet (read statement for better understanding). You can make hacks in these problems independently.

Koa the Koala has two strings AA and BB of the same length nn (A=B=n|A|=|B|=n) consisting of the first 2020 lowercase English alphabet letters (ie. from a to t).

In one move Koa:

  1. selects some subset of positions p1,p2,,pkp_1, p_2, \ldots, p_k (k1;1pin;pipjk \ge 1; 1 \le p_i \le n; p_i \neq p_j if iji \neq j) of AA such that Ap1=Ap2==Apk=xA_{p_1} = A_{p_2} = \ldots = A_{p_k} = x (ie. all letters on this positions are equal to some letter xx).

  2. selects any letter yy (from the first 2020 lowercase letters in English alphabet).

  3. sets each letter in positions p1,p2,,pkp_1, p_2, \ldots, p_k to letter yy. More formally: for each ii (1ik1 \le i \le k) Koa sets Api=yA_{p_i} = y.

    Note that you can only modify letters in string AA.

Koa wants to know the smallest number of moves she has to do to make strings equal to each other (A=BA = B) or to determine that there is no way to make them equal. Help her!

Each test contains multiple test cases. The first line contains tt (1t101 \le t \le 10) — the number of test cases. Description of the test cases follows.

The first line of each test case contains one integer nn (1n1051 \le n \le 10^5) — the length of strings AA and BB.

The second line of each test case contains string AA (A=n|A|=n).

The third line of each test case contains string BB (B=n|B|=n).

Both strings consists of the first 2020 lowercase English alphabet letters (ie. from a to t).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

For each test case:

Print on a single line the smallest number of moves she has to do to make strings equal to each other (A=BA = B) or 1-1 if there is no way to make them equal.

Input

Each test contains multiple test cases. The first line contains tt (1t101 \le t \le 10) — the number of test cases. Description of the test cases follows.

The first line of each test case contains one integer nn (1n1051 \le n \le 10^5) — the length of strings AA and BB.

The second line of each test case contains string AA (A=n|A|=n).

The third line of each test case contains string BB (B=n|B|=n).

Both strings consists of the first 2020 lowercase English alphabet letters (ie. from a to t).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

Output

For each test case:

Print on a single line the smallest number of moves she has to do to make strings equal to each other (A=BA = B) or 1-1 if there is no way to make them equal.

Samples

Sample Input 1

5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda

Sample Output 1

2
3
3
2
4

Note

  • In the 11-st test case Koa:
    1. selects positions 11 and 22 and sets A1=A2=A_1 = A_2 = b (aabbbb\color{red}{aa}b \rightarrow \color{blue}{bb}b).
    2. selects positions 22 and 33 and sets A2=A3=A_2 = A_3 = c (bbbbccb\color{red}{bb} \rightarrow b\color{blue}{cc}).

  • In the 22-nd test case Koa:
    1. selects positions 11 and 44 and sets A1=A4=A_1 = A_4 = a (cabcaaba\color{red}{c}ab\color{red}{c} \rightarrow \color{blue}{a}ab\color{blue}{a}).
    2. selects positions 22 and 44 and sets A2=A4=A_2 = A_4 = b (aabaabbba\color{red}{a}b\color{red}{a} \rightarrow a\color{blue}{b}b\color{blue}{b}).
    3. selects position 33 and sets A3=A_3 = c (abbbabcbab\color{red}{b}b \rightarrow ab\color{blue}{c}b).

  • In the 33-rd test case Koa:
    1. selects position 11 and sets A1=A_1 = t (abctbc\color{red}{a}bc \rightarrow \color{blue}{t}bc).
    2. selects position 22 and sets A2=A_2 = s (tbctsct\color{red}{b}c \rightarrow t\color{blue}{s}c).
    3. selects position 33 and sets A3=A_3 = r (tsctsrts\color{red}{c} \rightarrow ts\color{blue}{r}).