All Tracks Algorithms String Algorithms Problem

TnP Thanksgiving Party
Tag(s):

Very-Easy

Problem
Editorial
Analytics

It has been a norm for the years that after getting placed everyone should throw a party for the tnp coordinators as a token of thanksgiving.

But Poster Jain and Pandey Ji has decided to change this norm. Instead they will give treats to all the placed ones in Dominos :D (Great na? coz they are the best :D ).

In Dominos each pizza is represented as a string of lowercase alphabets (ex : "mantumania").

N students are already placed. Now it's party time. Each N students has N preferred choices of pizza (not necessarily distinct). Each student will like a pizza only if some prefix of his/her preferred pizza matches with the given pizza. (ex : preferred pizza is : "mantumania" and given pizza is : "mantu" , So it matches and hence they like "mantu" pizza. )

Poster Jain and Pandey Ji can go to Dominos for Q days. And they need to figure out whether on each day their ordered pizzas are satisfactory or not. i.e., if M pizzas are ordered on a particular day then atleast S pizzas among M are liked by the group (Particular pizza is liked by the group if it is liked by any of the N students). See sample test case for more clarification.

For Q days print "Yes" if the order is satisfactory else print "No".

Input

The first line contains an integer N ( 1 <= N <= 10^5 ), number of students.

The second line contains N strings ( 1<= length of each string <= 10 ), preferred pizza of each students.

The third line contains an integer Q ( 1 <= Q <= 100 ), the no of days they can visit Dominos.

Each Day is represented by two lines

First line contains two integers M and S ( 1 <= S <= M <= 10^3 ), no of pizzas ordered on a particular day and the no of pizzas need to be liked by the group respectively.

Second line contains M strings containing only lowercase english alphabets. ( 1 <= length of string <= 10 ) , pizzas ordered on the particular day.

Output

Print Q lines, each containing either "Yes" or "No".

AUTHOR : spaul100

SAMPLE INPUT
5
mantumania pizzamania maniamania pizzapizza macaroni
2
5 4
mantu mania pizza abcd pi 
5 5
abcdefghij aaaaaaaaaa bbcde pizza ab
SAMPLE OUTPUT
Yes
No
Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Scala 2.11.8, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

Notifications
View All Notifications