#P8892. 「UOI-R1」磁铁
「UOI-R1」磁铁
Problem Description
There are two magnet strings , both of which can be seen as strings made up of lowercase or uppercase letters or digits.
You can perform infinitely many operations on magnet . Each operation can be one of the following two:
- Delete the first several characters. For example, after deleting the first characters of , the string becomes .
- Move the last several characters to the front. For example, after moving the last characters of to the front, the string becomes .
Ask whether, after operations, magnet can be made equal to . and are equal if and only if they have the same length and every character is the same.
To prevent the situation of "no, Commander-in-Chief", you need to answer multiple queries.
Input Format
The first line contains the number of test cases .
Then there are test cases. Each test case contains two lines, each being a string, representing the magnet strings .
Output Format
Output lines. For each line, output Y or N to indicate whether it is possible or impossible to make and equal after operations.
1
12341234
1234
Y
1
6012739810910020338452
12345678
Y
1
123456789
465
N
见文件附件的 magnets4.in
见文件附件的 magnets4.ans
Hint
Sample Explanation #1.
$$\texttt{12341234}\\ \to \texttt{1234}\\ = \texttt{1234}$$Sample Explanation #2.
$$\texttt{6012739810910020338452}\\ \to \texttt{2601273981091002033845}\\ \to \texttt{601273981091002033845}\\ \to \texttt{384560127398109100203}\\ \to \texttt{4560127398109100203}\\ \to \texttt{0345601273981091002}\\ \to \texttt{345601273981091002}\\ \to \texttt{091002345601273981}\\ \to \texttt{2345601273981}\\ \to \texttt{3981234560127}\\ \to \texttt{81234560127}\\ \to \texttt{01278123456}\\ \to \texttt{78123456}\\ \to \texttt{12345678} \\ =\texttt{12345678}$$Constraints
Let denote the length of magnet in each test case, and denote the length of magnet in each test case.
For of the testdata, it is guaranteed that .
For another of the testdata, it is guaranteed that .
For of the testdata, it is guaranteed that $1 \leq \left| a \right|, \left| b \right| \leq 1000$, and .
It is guaranteed that and are non-empty and contain only uppercase and lowercase English letters or digits.
Translated by ChatGPT 5