Easygoing Single Tune Circulation
题号:NC15334
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Mr.Frog likes to use a music player called “NetEase Cloud Music”. There are N songs in the music library of “NetEase Cloud Music”. We use the string Si to indicate the melody of the ith song. The duration of the ith song is |Si| seconds. The phoneme of the ith song at jth second(j ∈ [1,|Si|]) is Si,j. There are 26 types of phoneme, and we use lowercase ‘a’-‘z’ to represent them. Each phoneme appears at most once in the same song.                    

Every day, Mr.Frog can choose exactly one song from the music library, then he will start playing this song in the single tune circulation mode.

One day, he wants to listen a special melody “fabc”. If he chooses a song “abcdef”, he will listen the melody “abcdefabcdefab... ...”. So, he can listen the special melody from 6th second to 9th second.

In the next Q days, Mr.Frog hopes to listen a special melody Mi at the ith day. Please tell him whether he can listen this melody.

输入描述:

The first line contains an integer T, where T is the number of test cases. T test cases follow.
For each test case, the first line contains one integer N, where N is the number of songs in the music library of “NetEase Cloud Music”.

The next N lines, the ith line contains one string Si, where Si is the melody of the ith song.

In the (N + 2)th line contains one integer Q.

The next Q lines, the ith line contains one string Mi, where Mi is the special melody that he wants tolisten at the ith day.
       

• 1≤T,N,Q≤105.

• |Si| ≥ 1 and each phoneme appears at most once in the same song. 
• 1≤|Mi|≤105.
• 1 ≤ ∑|Si|,∑|Mi| ≤ 105.
• Si, Mi contains only lowercase letters.
• the sum of N in all test cases doesn’t exceed 106.
• the sum of Q in all test cases doesn’t exceed 106.
• the sum of |Si| in all test cases doesn’t exceed 106.
• the sum of |Mi| in all test cases doesn’t exceed 106.


输出描述:

For each test case, output one line containing “Case #x:”, where x is the test case number (startingfrom 1). The following Q lines, each line output “YES” if he can listen the special melody at the ith day.Otherwise, output “NO”.

示例1

输入

复制
1
4
abcd
acd
ad
d
5
cda
ddddddd
dada
cda
acdca

输出

复制
Case #1:
YES
YES
YES
YES
NO

备注:

For the 1st day, he chooses the 1st song from the music library, and plays this song in the single tunecirculation mode, he will listen the melody “abcdabcdabcdab... ...”. He can listen the special melody “cda”from 3rd second to 5th second.