P8270 [USACO22OPEN] Subset Equality S

Description

The cows are trying a new way to exchange coded information. They mix irrelevant letters into the relevant letters, making the message hard to decode. The cows transmit two strings $s$ and $t$. Each string has length at most $10^5$ and consists only of lowercase letters from 'a' to 'r'. To try to understand this coded message, you are given $Q$ queries ($1 \leq Q \leq 10^5$). Each query gives a subset of the lowercase letters from 'a' to 'r'. For each query, you need to determine whether $s$ and $t$ are equal when keeping only the letters given in the query.

Input Format

The first line contains $s$. The second line contains $t$. The third line contains $Q$. The next $Q$ lines each contain one query string. In a query string, all letters are distinct. Also, all query strings are already sorted, and no query string appears more than once.

Output Format

For each query, output 'Y' if $s$ and $t$ are equal when keeping only the letters given in the query; otherwise output 'N'.

Explanation/Hint

[Sample Explanation] For the first query, when keeping only the character 'a', both strings become "aa". For the second query, the first string becomes "aac" while the second string becomes "caa". [Testdata Properties] - Test point 2 satisfies $|s|,|t|,Q\le 1000$. - Test points 3-11 have no additional constraints. Translated by ChatGPT 5