Associated Course(s):
Sudo Placement 2019

Geek recently read about strings, and he got interested in them.Geek has a list containing N words (not necessarily distinct)-denoted by Li.Now, he will ask Q queries.Each query will consist of a string x.You need to tell How many strings in the List has the string x as its prefix.

**Input:**

The First line contains an integer T, the number oftestcases.The first line of eachtestcase contains an integer N , the total number of Words.Each of the next N lines contains a string consisting of only lowercase alphabets -denoting Li.

The next Line contains Q- denoting the number of queries.Each of the next Q linescontain a string -denoting the string x.

**Output:**

For each query Output an integer denoting the total number of strings in the list that have string x as their prefix.

**Constraints:
1<=T<=10
1<= N<=30000
1<=Q<=10000
1<=Li,x<=100**

**Example:
Input:**

1

5

abracadabra

geeksforgeeks

abracadabra

geeks

geeksthrill

5

abr

geeks

geeksforgeeks

ge

gar

**Output:**

2

3

1

3

0

Explanation:

There are 2 strings that have prefix "abr" - **"****abracadabra****" and "abracadabra"**

There are 3 strings that have prefix "geeks" -** "****geeksforgeeks****" and "geeks" and "****geeksthrill****"**

There is 1 string thathave prefix "geeksforgeeks" - "**geeksforgeeks****"**.

There are 3 strings that have prefix "ge" - **"****geeksforgeeks****" and "geeks" and "****geeksthrill****"**

There is No string thathave prefix as "gar".

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

ShubhamJain18 | 205 |

makeitdonesolo | 140 |

lost_found | 124 |

maggiiiii | 118 |

SahatPrasad1 | 108 |

Bishnu Dev Panda | 777 |

okayboss | 551 |

ShubhamJain18 | 516 |

yk12 | 514 |

makeitdonesolo | 480 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.