#P8892. 「UOI-R1」磁铁

「UOI-R1」磁铁

Problem Description

There are two magnet strings a,ba, b, 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 aa. Each operation can be one of the following two:

  1. Delete the first several characters. For example, after deleting the first 33 characters of 91987\texttt{91987}, the string becomes 87\texttt{87}.
  2. Move the last several characters to the front. For example, after moving the last 33 characters of 91987\texttt{91987} to the front, the string becomes 98791\texttt{98791}.

Ask whether, after operations, magnet aa can be made equal to bb. aa and bb 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 tt.

Then there are tt test cases. Each test case contains two lines, each being a string, representing the magnet strings a,ba, b.

Output Format

Output tt lines. For each line, output Y or N to indicate whether it is possible or impossible to make aa and bb 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 a\left| a \right| denote the length of magnet aa in each test case, and b\left| b \right| denote the length of magnet bb in each test case.

For 20%20\% of the testdata, it is guaranteed that a=1\left| a \right| = 1.

For another 20%20\% of the testdata, it is guaranteed that b=1\left| b \right| = 1.

For 100%100\% of the testdata, it is guaranteed that $1 \leq \left| a \right|, \left| b \right| \leq 1000$, and 1t101 \leq t \leq 10.

It is guaranteed that aa and bb are non-empty and contain only uppercase and lowercase English letters or digits.

Translated by ChatGPT 5