TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

There are different kinds of pizza, and listing all of them down on a paper is not an easy job. Fortunately, we can describe them with features. For example, a pizza with

#{Hawaiian}

tag can be read as
pineapple,ham

and a pizza with
#{BBQBeef}

can be expected as
beef,BBQsauce


Sometimes, we can describe a feature with other features. For example,

#{SixFamilies}
tag is described by
pork,sausage,#{BBQBeaf},greenPepper,#{Mushroom}

and this can also be expanded by
pork,sausage,beef,BBQsauce,greenPepper,mushroom,onion

Now, given these features, we want to know the L-th to R-th character of the expanded version.


The description of a feature will not start with another feature.

Input Format

The first line of the input file contains an integer T (1<= T<= 100) indicating the number of test cases.


For each test case, first line contains three integers n, L, R (1<= n<= 100; 1<= L<= R<= 100000; 0<= R-L<= 100). Then n lines follow. Each line contains two strings Name, Expr separated by exactly one space. Both Name and Expr will not contain any whitespaces. The last line contains a $Name$ that you are going to expand. All expressions are valid. That is, you can always find a description of a feature in the list. A Name consists of lower-case and upper-case letters. An Expr is a comma-separated list of ingredients, where each ingredient is either a word of lower/upper case letters or #{Name}. The length of Name and Expr will not exceed 100.

Output Format

For each test case, please output the desired substring in a line. You may assume that the length of expanded version contains at least R characters (may be infinite!)

Sample Input 1

2
3 1 10
Seafood shrimp,octopus
SeafoodEX seashell,#{Seafood},fish
FishFood seaweed,#{SeafoodEX}
FishFood
1 2 7
XD XD,#{XD},XD,#{XD},XD
XD

Sample Output 1

seaweed,se
D,XD,X

Hints

Problem Source

Migrated from old NTUJ.

Tmt, Ferng

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 5000 65536 16384