#C6382. Alphabetically Similar Strings

    ID: 50136 Type: Default 1000ms 256MiB

Alphabetically Similar Strings

Alphabetically Similar Strings

You are given two strings A and B. Two strings are considered alphabetically similar if they have the same length and their sorted characters are identical. In other words, after sorting both strings in lexicographical order, if they match exactly, then they are considered similar.

For example:

  • "abc" and "bca" are similar because sorting both yields "abc".
  • "abcd" and "dcba" are similar.
  • "abc" and "abcd" are not similar because their lengths differ.
  • "aabbcc" and "bbaacc" are similar.

Your task is to process multiple test cases and determine for each case whether the two strings provided are alphabetically similar.

The formal condition can be expressed in LaTeX as follows:

\(\text{If } |A| \neq |B| \text{ then answer is } \texttt{NO}. \text{ Otherwise, if } \text{sorted}(A) = \text{sorted}(B) \text{ then answer is } \texttt{YES}, \text{ else } \texttt{NO}.\)

inputFormat

The first line of input contains an integer T (\(1 \le T \le 10^4\)), the number of test cases. Each of the following T lines contains two space-separated strings.

For each test case, the two strings A and B are provided. It is guaranteed that the strings contain only lowercase English letters.

outputFormat

For each test case, output a single line containing either "YES" if the two strings are alphabetically similar, or "NO" otherwise.

## sample
4
abc bca
abcd dcba
aabbcc bbaacc
abc abcd
YES

YES YES NO

</p>