#K58517. Equalizing Strings with One Substitution

    ID: 30660 Type: Default 1000ms 256MiB

Equalizing Strings with One Substitution

Equalizing Strings with One Substitution

You are given two strings of equal length. You can rearrange the characters in the first string arbitrarily. Additionally, you are allowed to perform at most one substitution operation on the first string; that is, you may replace one character with any other character.

Your task is to determine whether it is possible to transform the first string into an anagram of the second string with at most one substitution.

Recall that two strings are anagrams if one string can be rearranged to form the other. In other words, if the frequency counts of their characters are identical, then they are anagrams. If they differ, you may make at most one substitution in the first string to fix the discrepancy.

inputFormat

The first line contains an integer T denoting the number of test cases.

Each of the following T lines contains two space-separated strings s1 and s2.

outputFormat

For each test case, output a single line containing YES if it is possible to transform s1 into an anagram of s2 with at most one substitution; otherwise, output NO.

## sample
4
abc bca
aabb abac
abc def
abcd abce
YES

YES NO YES

</p>