{"problem":{"name":"[USACO23JAN] Find and Replace S","description":{"content":"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 in","description_type":"Markdown"},"platform":"Luogu","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":{"LuoguStyle":"P5"},"is_remote":true,"is_sync":true,"sync_url":null,"sign":"LGP9013"},"statements":[{"statement_type":"Markdown","content":"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 `aAbBa`, if Bessie selects $c_1$ as `a` and $c_2$ as `B`, the given string transforms into `BAbBB`.\n\nBessie is a busy cow, so for each of $T\n(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. \n\n## Input\n\nThe first line contains $T$, the number of independent test cases.\n\nThe 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$. \n\n## Output\n\nFor 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. \n\n[samples]\n\n## Note\n\n### Explanation for Sample 1\n\nThe first input string is the same as its output string, so no keystrokes are required.\n\nThe second input string cannot be changed into its output string because Bessie cannot change one `B`' to `A` while keeping the other as `B`.\n\nThe third input string can be changed into its output string by changing `a` to `b`.\n\nThe last input string can be changed into its output string like so: $\\texttt{ABCD} \\rightarrow \\texttt{EBCD} \\rightarrow \\texttt{EACD} \\rightarrow \\texttt{BACD}$.\n\n### Scoring\n\n - Inputs $2-6$: Every string has a length at most $50$.\n - Inputs $7-9$: All strings consist only of lowercase letters `a` through `e`\n - Inputs $10-15$: No additional constraints.","is_translate":false,"language":"English"}],"meta":{"iden":"LGP9013","tags":["USACO","2023","图论建模","基环树"],"sample_group":[["4\nabc\nabc\nBBC\nABC\nabc\nbbc\nABCD\nBACD","0\n-1\n1\n3"]],"created_at":"2026-03-03 11:09:25"}}