#P1383C. String Transformation 2
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 Koa selects can be any letter from the first lowercase letters of English alphabet (read statement for better understanding). You can make hacks in these problems independently.
Koa the Koala has two strings and of the same length () consisting of the first lowercase English alphabet letters (ie. from a to t).
In one move Koa:
- selects some subset of positions ( if ) of such that (ie. all letters on this positions are equal to some letter ).
- selects any letter (from the first lowercase letters in English alphabet).
- sets each letter in positions to letter . More formally: for each () Koa sets .
Note that you can only modify letters in string .
Koa wants to know the smallest number of moves she has to do to make strings equal to each other () or to determine that there is no way to make them equal. Help her!
Each test contains multiple test cases. The first line contains () — the number of test cases. Description of the test cases follows.
The first line of each test case contains one integer () — the length of strings and .
The second line of each test case contains string ().
The third line of each test case contains string ().
Both strings consists of the first lowercase English alphabet letters (ie. from a to t).
It is guaranteed that the sum of over all test cases does not exceed .
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 () or if there is no way to make them equal.
Input
Each test contains multiple test cases. The first line contains () — the number of test cases. Description of the test cases follows.
The first line of each test case contains one integer () — the length of strings and .
The second line of each test case contains string ().
The third line of each test case contains string ().
Both strings consists of the first lowercase English alphabet letters (ie. from a to t).
It is guaranteed that the sum of over all test cases does not exceed .
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 () or if there is no way to make them equal.
Samples
Note
- In the -st test case Koa:
- selects positions and and sets b ().
- selects positions and and sets c ().
- In the -nd test case Koa:
- selects positions and and sets a ().
- selects positions and and sets b ().
- selects position and sets c ().
- In the -rd test case Koa:
- selects position and sets t ().
- selects position and sets s ().
- selects position and sets r ().