#P9013. miV Text Transformation

    ID: 22173 Type: Default 1000ms 256MiB

miV Text Transformation

miV Text Transformation

Bessie is using the latest innovation in text-editing software, miV! She starts with an input string consisting solely of upper and lowercase English letters and wishes to transform it into some output string. With just one keystroke, miV allows her to replace all occurrences of one English letter \(c_1\) in the string with another English letter \(c_2\). For example, given the string aAbBa, if Bessie selects \(c_1\) as a and \(c_2\) as B, the string transforms into BAbBB.

For each of \(T\) \((1 \le T \le 10)\) independent test cases, you are given an input string and a desired output string (both of equal length). In one keystroke, you may choose an English letter \(c_1\) and replace every occurrence of \(c_1\) in the current string with another letter \(c_2\) (\(c_1\) and \(c_2\) can be either uppercase or lowercase).

Your task is to determine the minimum number of keystrokes required to transform the input string into the output string. Note that if the transformation from a letter in the input to a different letter in the output forms a cycle (for example, transforming \(a\) to \(b\) and \(b\) to \(a\)), an extra keystroke is required to break the cycle using an intermediary letter.

The optimal strategy is to first count the number of required direct letter transformations (i.e. where the input letter differs from the output letter) and then add one extra keystroke for each cycle present in the transformation mapping (a cycle is defined as a sequence \(a_1 \to a_2 \to \cdots \to a_k \to a_1\) with \(k \ge 2\)).

inputFormat

The first line contains an integer \(T\) \((1 \le T \le 10)\) indicating the number of test cases. Each test case consists of two lines:

  • The first line contains the input string.
  • The second line contains the desired output string.

Both strings will consist solely of English uppercase and lowercase letters and have the same length.

outputFormat

For each test case, output a single integer representing the minimum number of keystrokes required to transform the input string into the output string.

sample

2
abc
bcd
ab
ba
3

3

</p>