#K92957. Rearrange Original to Contain Pattern

    ID: 38312 Type: Default 1000ms 256MiB

Rearrange Original to Contain Pattern

Rearrange Original to Contain Pattern

Given two strings, original and pattern, determine if there exists a contiguous substring in original that is an anagram of pattern. In other words, decide whether it is possible to rearrange the characters of any contiguous segment of the original string such that it exactly matches the pattern string.

Formally, for a given original string and a pattern string, you should output Yes if there exists an index i such that the substring original[i ... i+|pattern|-1] is an anagram of pattern. Otherwise, output No. Note that an empty pattern is always considered to be a valid substring.

Example: For original = "cbad" and pattern = "abc", one possible contiguous substring is "cba", which is an anagram of "abc". Therefore, the answer is Yes.

inputFormat

The input is given via standard input (stdin) and consists of multiple test cases. The first line contains an integer T representing the number of test cases. Each of the following T lines contains two space-separated strings: the original string and the pattern string.

Note: The strings may contain any characters and might be empty (especially the pattern). In the case of empty strings, the input line will simply have an empty token for that string.

outputFormat

For each test case, print a single line to standard output (stdout) containing Yes if there exists a contiguous substring of the original string that is an anagram of the pattern string; otherwise, print No.

## sample
3
cbad abc
cbadxyz abcd
cbadx abcdz
Yes

Yes No

</p>