P8892 "UOI-R1" Magnet

Description

There are two magnet strings $a, 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 $a$. Each operation can be one of the following two: 1. Delete the first several characters. For example, after deleting the first $3$ characters of $\texttt{91987}$, the string becomes $\texttt{87}$. 2. Move the last several characters to the front. For example, after moving the last $3$ characters of $\texttt{91987}$ to the front, the string becomes $\texttt{98791}$. Ask whether, after operations, magnet $a$ can be made equal to $b$. $a$ and $b$ 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 $t$. Then there are $t$ test cases. Each test case contains two lines, each being a string, representing the magnet strings $a, b$.

Output Format

Output $t$ lines. For each line, output `Y` or `N` to indicate whether it is possible or impossible to make $a$ and $b$ equal after operations.

Explanation/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 $\left| a \right|$ denote the length of magnet $a$ in each test case, and $\left| b \right|$ denote the length of magnet $b$ in each test case. For $20\%$ of the testdata, it is guaranteed that $\left| a \right| = 1$. For another $20\%$ of the testdata, it is guaranteed that $\left| b \right| = 1$. For $100\%$ of the testdata, it is guaranteed that $1 \leq \left| a \right|, \left| b \right| \leq 1000$, and $1 \leq t \leq 10$. It is guaranteed that $a$ and $b$ are non-empty and contain only uppercase and lowercase English letters or digits. Translated by ChatGPT 5