#C8549. Minimum Replacements Transformation

    ID: 52543 Type: Default 1000ms 256MiB

Minimum Replacements Transformation

Minimum Replacements Transformation

You are given two strings, S and T. In one operation, you can replace any character in S with any other character. The goal is to transform S into T with the minimum number of such replacement operations. Note that the order of characters does not matter; only their frequency matters.

Formally, let \(freq_X(c)\) denote the frequency of character \(c\) in string \(X\). The answer is given by: \[ \sum_{c} \max(0, freq_T(c) - freq_S(c)) \] where the sum is taken over all characters that appear in T.

For example:

  • For S = "abc" and T = "bca", no replacements are needed.
  • For S = "a" and T = "b", one replacement is needed.
  • For S = "abc" and T = "xyz", three replacements are needed.

inputFormat

The input is read from standard input (stdin) and has the following format:

T
S₁
T₁
S₂
T₂
... (repeated for T test cases)

where T is the number of test cases. For each test case, the first line contains string S and the second line contains string T.

outputFormat

For each test case, print the minimum number of replacements required to transform string S into string T on a separate line. The output should be written to standard output (stdout).

## sample
3
abc
bca
a
b
abc
xyz
0

1 3

</p>