QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#20818. Find and Replace

Statistics

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.

Input

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$.

Output

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.

Examples

Input 1

4
abc
abc
BBC
ABC
abc
bbc
ABCD
BACD

Output 1

0
-1
1
3

The first input string is the same as its output string, so no keystrokes are required.

The second input string cannot be changed into its output string because Bessie cannot change one '$\texttt{B}$' to '$\texttt{A}$' while keeping the other as '$\texttt{B}$'.

The third input string can be changed into its output string by changing '$\texttt{a}$' to '$\texttt{b}$'.

The last input string can be changed into its output string like so: $\texttt{ABCD} \rightarrow \texttt{EBCD} \rightarrow \texttt{EACD} \rightarrow \texttt{BACD}$.

Scoring

  • Inputs 2-6: Every string has a length at most $50$.
  • Inputs 7-9: All strings consist only of lowercase letters '$\texttt{a}$' through '$\texttt{e}$'
  • Inputs 10-15: No additional constraints.

Problem credits: Benjamin Qi

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.