P14187 [ICPC 2024 Hangzhou R] AUS

Description

Pigeland University will host the 2224 Animal Collegiate Programming Contest (ACPC 2224). Unlike previous years, where teams from the host institution were marked as unofficial, Pigeland will send official teams to compete in the contest with three workstations for each team. Nevertheless, Pig-head, the coach of Pigeland University, remains uncertain about his teams' chances of securing gold medals. As a result, he decides to acquire the contest problems in advance from the AUS problem-setting group, using the excuse of needing to upload data to the online judge. To prevent cheating, AUS attempts to encrypt the problems using a special cipher. Specifically, problems are represented by strings consisting of lowercase English letters. AUS wants to design a cipher function $f(x)$ that maps lowercase English letters to lowercase English letters. For a problem $S = s_1s_2\ldots s_{n}$, the encrypted version of the problem is another string given by $F(S) = f(s_1)f(s_2)\ldots f(s_{n})$. For example, when $S = \texttt{abcabc}$ and $f(\texttt{a}) = \texttt{a}$, $f(\texttt{b}) = \texttt{k}$, $f(\texttt{c}) = \texttt{a}$, the encrypted version is $F(S) = \texttt{akaaka}$. As a member of AUS, your task is to design the cipher function $f$. The leader of AUS believes that the function is $\textit{strong}$ if and only if there exists at least one problem that can be encrypted into the same encrypted version as another, while not all problems produce the same encrypted output. To validate this, he will give you three problems $S_1$, $S_2$, and $S_3$, and you need to find a cipher function $f$ such that $F(S_1) = F(S_2)$ and $F(S_1) \neq F(S_3)$. Since AUS has several experienced members, your task is simply to determine whether such a cipher function exists.

Input Format

There are multiple test cases. The first line contains an integer $T$ ($1 \leq T \leq 10^4$) indicating the number of test cases. For each test case: The first line contains a string $S_1$ ($1 \leq |S_1| \leq 10^3$) consisting of only lowercase English letters. The second line contains a string $S_2$ ($1 \leq |S_2| \leq 10^3$) consisting of only lowercase English letters. The third line contains a string $S_3$ ($1 \leq |S_3| \leq 10^3$) consisting of only lowercase English letters. It is guaranteed that the sum of $|S_1|+|S_2|+|S_3|$ of all test cases does not exceed $3 \times 10^4$.

Output Format

For each test case, if such cipher function exists, output $\texttt{YES}$ in one line. Otherwise, output $\texttt{NO}$ instead.

Explanation/Hint

For the first and third sample test cases, one valid cipher function can be $f(\texttt{a}) = f(\texttt{b}) = f(\texttt{c}) = f(\texttt{d}) = \texttt{a}$ and $f(\texttt{e}) = \texttt{b}$.