#63202. [USACO 2023 Jan Silver]Find and Replace

[USACO 2023 Jan Silver]Find and Replace

暂无测试数据。

英文题面

Bessie is using the latest and greatest 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 $\texttt{aAbBa}$, if Bessie selects $c_1$ as 'a' and $c_2$ as 'B', the given string transforms into $\texttt{BAbBB}$.

Bessie is a busy cow, so for each of $T$ ($1\le T\le 10$) independent test cases, output the minimum number of keystrokes required to transform her input string into her desired output string.

译文

Bessie 正在使用世界上最先进最伟大的文本编辑器:miV!她想将一个仅由大写和小写英文字母组成的字符串转换为一个新的字符串。每一次操作,miV 可以将字符串中所有的字母 $c_1$ 替换成另一种字母 $c_2$。例:对于字符串aAbBa, 如果将其中的 a 替换成 B, 那么字符串会变为BAbBB

Bessie 非常地忙碌, 所以对于给出的 $T(1 \le T \le 10)$ 组测试数据, 请输出她至少需要多少次操作才能把原字符串转换为新字符串。

输入格式

The first line contains $T$, the number of independent test cases.

The following $T$ pairs of lines contain an input and output string of equal length. All characters are upper or lowercase English letters (either A through Z or a through z). The sum of the lengths of all strings does not exceed $10^5$.

第一行是一个整数 $T$, 表示测试数据的数量。

接下来有 $T$ 对长度相等的字符串。字符串中所有的字符都是大写或小写的字母。字符串的长度不会超过 $10^5$。

输出格式

For each test case, output the minimum number of keystrokes required to change the input string into the output string, or $-1$ if it is impossible to do so.

对于每组测试数据,输出转换字符串需要的最小操作数。

如果这不可能做到,输出 $-1$。

数据范围

Inputs 2-6: Every string has a length at most 50.

Inputs 7-9: All strings consist only of lowercase letters '

4
abc
abc
BBC
ABC
abc
bbc
ABCD
BACD
0
-1
1
3