#C1013. Check if String is One Rotation Away

    ID: 39301 Type: Default 1000ms 256MiB

Check if String is One Rotation Away

Check if String is One Rotation Away

Given two strings s1 and s2, determine if s2 can be obtained by rotating s1 exactly once. A rotation can be performed in two ways:

  • Left Rotation: Move the first character of s1 to the end. Formally, if $$ s1 = a_1a_2\ldots a_n, $$ then after one left rotation it becomes $$ a_2a_3\ldots a_na_1. $$
  • Right Rotation: Move the last character of s1 to the beginning. That is, it becomes $$ a_na_1a_2\ldots a_{n-1}. $$

Your task is to check if s2 is equal to either the left-rotated or the right-rotated version of s1. Note that if s1 is identical to s2, then it is not considered a valid rotation.

inputFormat

The first line contains an integer T representing the number of test cases. Each of the following T lines contains two space-separated strings s1 and s2.

Example:

6
abcdef bcdefa
abcdef defabc
abc cab
abc bca
abc abc
a a

outputFormat

For each test case, output a single line containing Yes if s2 can be obtained by rotating s1 exactly once (either left or right), otherwise output No.

Example:

Yes
No
Yes
Yes
No
No
## sample
6
abcdef bcdefa
abcdef defabc
abc cab
abc bca
abc abc
a a
Yes

No Yes Yes No No

</p>