402337: GYM100733 B Ascencion

Memory Limit:64 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Ascenciontime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

Gehenna is coming to an end, after a long and undocumented period of art exhibitions and forum threads.

Every bot in Gehenna, at this point, has decided to stay or leave the simulation. We know they have formed gangs within the forums, inspired by documents about Al Capone and the mafia in the library archive.

The admin used to be the ruler of this forgotten place, but Uriel_Copy.v.23.4.5 has managed to convince him to leave the simulation. Now a new administrator has to be elected by the democratic system of Gehenna.

To do so, the users decided to use a system devised by The_Blacksmith. There will be an art gallery contest, as usual, and each art work will receive a grade. The user that produces the best artwork will be made ADMIN.

An artwork is a n × m matrix of ASCII characters. Each user has a nickname and has a gang name. It is a common practice in Gehenna to reward symbolic language and hidden meanings. This is what The_Blacksmith system does: the score of an art is the number of times you can build both the creator's name and gang name using the characters in the art.

Given the arts, names and gangs from all the users in the Billboard System, prove your worth by making the script that figures out the winner.

Input

The input begins with the number k of users (1 ≤ k ≤ 100). Follows k lines, each with the user's nickname and gang name. The nickname and gangname are composed of no more than 20 lowercase characters or numbers, and they are separated by a blank space. In the following lines comes the k artworks of each of the users, in order. Each artwork begins with integers n and m (1 ≤ m, n ≤ 50). Then follows n lines, each with m characters that form the artwork.

Output

Output the name and the gang of the new admin, separated by a blank space. If there's a draw, choose the candidate that appears first on the input.

ExamplesInput
2
a b
c c
3 3
bxa
axx
xxb
3 3
xcx
cxx
xxc
Output
a b
Input
3
lilith lol
theblacksmith art
401 renegades
5 10
lzzi2hlola
acilethlol
aalil2thlo
l9a3iliaaa
t3lolloa11
5 5
taart
hkcci
ekvta
bsahj
lm8ok
4 10
104410401s
renega0des
renega01es
ddrenegaes
Output
401 renegades
Input
3
orc trolls
mrmulciber elohim
theblacksmith gema
9 9
lptkblrsv
cororpoyr
tolor58rt
rotozkhox
lclulasll
crucn2o5r
y0rlcolws
1tvsqb7la
tlssitlos
5 7
afi9gnw
j7qyksb
b2o3915
yk1hij3
3lab6fq
8 10
ghaseuteje
eveabhvne8
kfths3htbe
kagagmfmma
mbttsvmbl2
shkg1mcklh
ahijetciaz
rwci0lbmmi
Output
orc trolls
Note

In the test case #1 we can build a b two times, it is, we have two a's and two b's. We can build c c only once, because we have only three c's.

It is unfair, but yes, the artworks may have different sizes.

Source/Category

加入题单

算法标签: