#P8270. [USACO22OPEN] Subset Equality S

[USACO22OPEN] Subset Equality S

Problem 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 ss and tt. Each string has length at most 10510^5 and consists only of lowercase letters from 'a' to 'r'. To try to understand this coded message, you are given QQ queries (1Q1051 \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 ss and tt are equal when keeping only the letters given in the query.

Input Format

The first line contains ss.

The second line contains tt.

The third line contains QQ.

The next QQ 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 ss and tt are equal when keeping only the letters given in the query; otherwise output 'N'.

aabcd
caabd
4
a
ac
abd
abcd
YNYN

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,Q1000|s|,|t|,Q\le 1000.
  • Test points 3-11 have no additional constraints.

Translated by ChatGPT 5