Alumni

At UPF there is a document with the names of all students that finished
their studies, but an employee opened the wrong document in the UPF
servers and accidentally deployed the Alumni virus.

The virus reads all student names and merges them into a single string
that maintains the order of each name. For instance, Alumni can read
alice and bob and generate a document with a single string alibobce.
Both alice and bob are subsequences of this string, but another name
such as bond is not. Multiple names can share letters in the generated
string, e.g. Alumni can merge boben and bobby as bobebny.

UPF needs your help to write a program that determines whether or not a
student name is part of a string d and reports “YES” or “NO”
accordingly.

Input

The input starts with the number of test cases T ≤ 100. For each test
case, there is an intenger Q ≤ 100 that represents the number of queries
to answer. The following line is the output non-empty string d of Alumni
virus with less than 10⁶ characters. The next Q lines are strings that
correspond to possible non-empty student names, and their length could
be as large as min(|d|,1000). Your program should say if each student
name exists in d. All input strings have lowercase letters.

Output

For each test case, output Q lines corresponding to each query: “YES” if
the queried name exist, “NO” otherwise. Print and end of line character
after each test case.

Problem information

Author: Javier Segovia

Generation: 2026-01-25T21:55:25.156Z

© Jutge.org, 2006–2026.
https://jutge.org
