Let's consider the famous game called Boom (aka Hat) with simplified rules.

There are *n* teams playing the game. Each team has two players. The purpose of the game is to explain the words to the teammate without using any words that contain the same root or that sound similarly. 

Player *j* from team *i* (1 ≤ *i* ≤ *n*, 1 ≤ *j* ≤ 2) is characterized by two numbers: *a*<sub class="lower-index">*ij*</sub> and *b*<sub class="lower-index">*ij*</sub>. The numbers correspondingly represent the skill of explaining and the skill of understanding this particular player has. 

Besides, *m* cards are used for the game. Each card has a word written on it. The card number *k* (1 ≤ *k* ≤ *m*) is characterized by number *c*<sub class="lower-index">*k*</sub> — the complexity of the word it contains.

Before the game starts the cards are put in a deck and shuffled. Then the teams play in turns like that: the 1-st player of the 1-st team, the 1-st player of the 2-nd team, ... , the 1-st player of the *n*-th team, the 2-nd player of the 1-st team, ... , the 2-nd player of the *n*-th team, the 1-st player of the 1-st team and so on.

Each turn continues for *t* seconds. It goes like that: Initially the time for each turn is *t*. While the time left to a player is more than 0, a player takes a card from the top of the deck and starts explaining the word it has to his teammate. The time needed for the *j*-th player of the *i*-th team to explain the word from the card *k* to his teammate (the *q*-th player of the *i*-th team) equals *max*(1, *c*<sub class="lower-index">*k*</sub> - (*a*<sub class="lower-index">*ij*</sub> + *b*<sub class="lower-index">*iq*</sub>) - *d*<sub class="lower-index">*ik*</sub>) (if *j* = 1,  then *q* = 2,  else *q* = 1). The value *d*<sub class="lower-index">*ik*</sub> is the number of seconds the *i*-th team has already spent explaining the word *k* during the previous turns. Initially, all *d*<sub class="lower-index">*ik*</sub> equal 0. If a team manages to guess the word before the end of the turn, then the time given above is substracted from the duration of the turn, the card containing the guessed word leaves the game, the team wins one point and the game continues. If the team doesn't manage to guess the word, then the card is put at the bottom of the deck, *d*<sub class="lower-index">*ik*</sub> increases on the amount of time of the turn, spent on explaining the word. Thus, when this team gets the very same word, they start explaining it not from the beginning, but from the point where they stopped. The game ends when words from all *m* cards are guessed correctly.

You are given *n* teams and a deck of *m* cards. You should determine for each team, how many points it will have by the end of the game and which words the team will have guessed.
The first line contains two integers *n*, *t* (1 ≤ *n*, *t* ≤ 100), which correspondingly denote the number of teams and a turn's duration.

Next *n* lines of the input file contain four integers each: *a*<sub class="lower-index">*i*1</sub>, *b*<sub class="lower-index">*i*1</sub>, *a*<sub class="lower-index">*i*2</sub>, *b*<sub class="lower-index">*i*2</sub> (1 ≤ *a*<sub class="lower-index">*ij*</sub>, *b*<sub class="lower-index">*ij*</sub> ≤ 100) — the skills of the first and the second player of the *i*-th team. The teams are given in the order in which they play.

The next line of the input file contains integer *m* (1 ≤ *m* ≤ 100) the number of cards.

Next 2*m* lines contain the cards' descriptions. Two lines describe each card. The first line of the description contains the word that consists of no more than 20 characters. The words only contain small Latin letters. The second line of the description contains an integer *c*<sub class="lower-index">*k*</sub> (1 ≤ *c*<sub class="lower-index">*k*</sub> ≤ 100) — the complexity of the word written on the *k*-th card. The cards are listed in the order in which the lie in the deck from top to bottom. The words on all cards are different.
2 2
1 1 1 1
1 1 1 1
3
home
1
car
1
brother
1
2 home car 
1 brother 
2 4
1 2 2 1
2 3 2 2
4
armchair
3
quetzalcoatl
10
pilotage
5
defibrillator
7
2 armchair quetzalcoatl 
2 pilotage defibrillator 
5 10
7 4 2 1
3 8 4 3
10 1 8 2
1 10 8 1
7 2 8 5
20
awhiwqom
97
bupsrkw
67
cdcle
46
dbw
20
hypayjdabm
96
igclyxfkshgbhrf
78
ldcyjtkldc
73
mgrdcybqbvor
49
njzddrjxafjrrw
63
ozucivhhggjtfkbojuqw
11
qgzsrwl
95
rz
28
tperpgd
66
vilawpd
16
vnujx
8
wadgiywkj
23
ydisqmwtprbiexkxy
16
yejvg
29
yusivpcoucy
43
zdnpcaybyupwnrqjln
69
2 ydisqmwtprbiexkxy ldcyjtkldc 
4 dbw tperpgd qgzsrwl awhiwqom 
7 vilawpd vnujx rz mgrdcybqbvor bupsrkw zdnpcaybyupwnrqjln hypayjdabm 
2 cdcle njzddrjxafjrrw 
5 ozucivhhggjtfkbojuqw yejvg wadgiywkj yusivpcoucy igclyxfkshgbhrf 
5 10
10 10 5 1
7 2 1 3
1 9 6 10
9 9 8 2
9 7 3 3
20
au
9
azyqnadfkgan
40
bljzegoaovxjpmgu
42
coetohydzgsgcobutdis
60
d
29
dbly
72
ejfg
65
g
61
gegfsmb
77
gfchnfbrmgzhka
92
higitegymghcm
59
ipnaqundvzjnth
32
lxwjjupqyeovetkxp
5
mdzdmjffnijjaxumayvf
44
otxrsihubv
4
p
38
ubelpi
80
vrvsyanbzf
56
wultlskyakufgynixzu
98
yyionxuvc
10
6 au azyqnadfkgan mdzdmjffnijjaxumayvf ejfg vrvsyanbzf ubelpi 
4 lxwjjupqyeovetkxp yyionxuvc p wultlskyakufgynixzu 
4 otxrsihubv ipnaqundvzjnth gegfsmb gfchnfbrmgzhka 
3 d coetohydzgsgcobutdis g 
3 bljzegoaovxjpmgu higitegymghcm dbly 
5 10
6 8 9 1
1 7 6 4
10 8 3 7
6 9 8 10
1 9 9 9
20
abbugflflinrioxgvl
14
afpwenhqgfwser
75
akpiohdcrquscdxil
82
cpppzkllbjjwqaao
40
eah
36
em
5
eotdkpityyxejgxuqk
6
evowzppqdmiyjds
40
fifdbjdtoespushpex
54
jibx
54
mhcldvkm
51
myozdrlz
87
sfxdpyunksqixgvrgpye
49
tymtutmayttwhbdt
65
u
37
ujncufz
46
uohkmteallop
12
wug
29
ykgzkwsrfls
54
zm
58
4 abbugflflinrioxgvl u ujncufz jibx 
1 akpiohdcrquscdxil 
3 cpppzkllbjjwqaao mhcldvkm myozdrlz 
7 uohkmteallop eah wug sfxdpyunksqixgvrgpye fifdbjdtoespushpex zm afpwenhqgfwser 
5 em eotdkpityyxejgxuqk evowzppqdmiyjds tymtutmayttwhbdt ykgzkwsrfls 
5 10
20 6 16 6
2 10 13 19
15 11 1 4
15 3 12 6
6 7 19 5
20
andzzevyyejsla
20
bkaljsdgrbqbpoqapknb
74
bkuvgjx
79
ce
34
easgyfwgxfegtqx
73
ecjhpqjvuqtltcyd
59
ganmza
85
gh
100
gmoimkqhbaprgvksati
95
imgugcpeqgtnjbw
55
inrehyoipugj
90
jbhvbvgcmfyv
96
lrzxlgznwhrtkjlg
75
pgxbtjjstynucdxwodwx
36
pyvjrrc
35
qhrjljx
32
thdzwf
59
vacd
6
wgzmzmmyo
25
ydayfmhgesnwmysmslnm
34
6 andzzevyyejsla thdzwf ecjhpqjvuqtltcyd ganmza bkaljsdgrbqbpoqapknb jbhvbvgcmfyv 
5 vacd wgzmzmmyo ydayfmhgesnwmysmslnm lrzxlgznwhrtkjlg gh 
3 pgxbtjjstynucdxwodwx bkuvgjx gmoimkqhbaprgvksati 
2 imgugcpeqgtnjbw easgyfwgxfegtqx 
4 ce pyvjrrc qhrjljx inrehyoipugj 
5 10
8 1 5 14
17 5 16 14
9 4 2 8
1 12 10 10
7 20 8 12
20
arkeegnvzxwkmhttig
95
bxvjixvhrwtddesip
60
ddoyeyftpsfdburf
64
e
62
i
11
kcmkkzacal
100
lwzeutqojfoakzr
7
mgylauhh
60
otsee
54
oymxmaqf
2
pw
84
qbrguhfgswdiqdd
84
rlujthwavumoio
57
sejtaiujdmpykwmsblhw
29
tgiwytlml
75
tkcqescgluggpn
47
uchk
79
uvmwnjpj
78
xugnf
1
yvuyle
55
4 lwzeutqojfoakzr sejtaiujdmpykwmsblhw tkcqescgluggpn mgylauhh 
4 bxvjixvhrwtddesip otsee uchk qbrguhfgswdiqdd 
3 oymxmaqf ddoyeyftpsfdburf tgiwytlml 
2 e arkeegnvzxwkmhttig 
7 i xugnf rlujthwavumoio yvuyle kcmkkzacal pw uvmwnjpj 
5 10
15 4 15 14
13 8 6 17
11 17 2 1
7 13 8 15
7 6 17 20
20
aaqiqonqh
38
akonztimlx
99
dplqs
20
eadliyjzqrmpusux
49
fferd
44
gpvogqvfg
31
h
69
iagxaacjqrdfyqhalqip
25
iuylompdxxro
82
jaoesfe
72
kqqgigyuncqoxh
27
krcmediuiholmtefnhjj
32
lrwjbttlzdxvvzcmhjg
98
pijippred
45
pyvamvpwllojbnqowxi
2
qahpgw
63
rbyvangmxes
17
sezugolsnnuxibunzt
13
vbcvglvndzdskks
63
ym
7
4 aaqiqonqh pyvamvpwllojbnqowxi pijippred akonztimlx 
6 dplqs rbyvangmxes sezugolsnnuxibunzt eadliyjzqrmpusux h iuylompdxxro 
2 ym jaoesfe 
3 gpvogqvfg kqqgigyuncqoxh lrwjbttlzdxvvzcmhjg 
5 iagxaacjqrdfyqhalqip krcmediuiholmtefnhjj fferd vbcvglvndzdskks qahpgw 
5 10
2 8 13 14
9 3 9 11
14 3 11 6
13 2 7 8
19 12 6 7
20
bociyuihqsycazxbui
4
cpmele
66
engvnnjisqaavzfxfd
27
exh
29
fdfsvmiit
53
ikzcj
8
khsiqelk
78
kztgoyoyvhsmvgel
35
mebxvlhzjcszgsjpibw
56
ovxakwrtpyybp
49
ozsoefwgaztswtwb
3
paojwscogjvogeyzwe
15
phdbcnfuqeskauygu
55
rds
51
shastxtximm
62
ssenuaqqxvhdqgeayrir
57
vcelxizohyfjrzxalhcv
59
yisnkcedfkk
45
zcknnzdruemywcbndzp
64
zpw
90
7 bociyuihqsycazxbui exh ovxakwrtpyybp yisnkcedfkk mebxvlhzjcszgsjpibw cpmele zpw 
5 engvnnjisqaavzfxfd ozsoefwgaztswtwb paojwscogjvogeyzwe rds phdbcnfuqeskauygu 
2 ssenuaqqxvhdqgeayrir shastxtximm 
2 ikzcj khsiqelk 
4 kztgoyoyvhsmvgel fdfsvmiit vcelxizohyfjrzxalhcv zcknnzdruemywcbndzp 
5 10
8 19 18 11
2 16 9 12
9 1 20 5
1 7 15 9
8 3 13 10
20
a
89
adzyvfy
87
aoybveo
3
bgydqvpv
64
bsfap
35
ezdrupaqno
32
ip
39
ipcgzrz
21
jvejeogiwk
12
las
19
lsasbtvbmw
20
ltnqvtsrsxplcrvbou
4
mcokeatvdjvv
26
mcycqkq
83
pdesmpuapplpxbpjoo
49
slokvekutpxfvadwfl
61
wwocjxemijrdmbje
97
ymbijnafcxp
97
zjffmxjuolyoqnob
18
zuylsraoahtcncl
43
15 ip ipcgzrz jvejeogiwk las lsasbtvbmw ltnqvtsrsxplcrvbou mcokeatvdjvv zjffmxjuolyoqnob ezdrupaqno zuylsraoahtcncl pdesmpuapplpxbpjoo slokvekutpxfvadwfl bgydqvpv mcycqkq a 
1 wwocjxemijrdmbje 
2 aoybveo ymbijnafcxp 
0 
2 bsfap adzyvfy 
5 10
94 46 74 76
98 78 62 64
7 94 44 18
95 18 40 52
76 94 74 83
20
ai
61
akwvpfyuovffgzmiwij
34
dkqpsirmrlrwlgmez
78
dtmpwtuiumzvgt
18
eryegapeqgtsxrbg
98
goaoldmikasvae
6
jvmbaidtwcubkxbj
100
nupdjdwii
89
ougt
59
pqqwvnmexqiahhmhxzv
65
pzogwycbtnns
100
qglmnq
100
rikefhitquizqzcisw
21
rpivyqjbycahluq
18
t
3
tpzvlmu
66
vcjlejgt
48
wkish
56
yjeistoxf
28
zwiyyokxcfnsaeqb
30
10 ai akwvpfyuovffgzmiwij dkqpsirmrlrwlgmez dtmpwtuiumzvgt eryegapeqgtsxrbg goaoldmikasvae jvmbaidtwcubkxbj nupdjdwii ougt pqqwvnmexqiahhmhxzv 
10 pzogwycbtnns qglmnq rikefhitquizqzcisw rpivyqjbycahluq t tpzvlmu vcjlejgt wkish yjeistoxf zwiyyokxcfnsaeqb 
0 
0 
0 
5 10
49 18 18 52
26 77 12 43
21 82 70 77
49 1 50 90
73 31 68 46
20
agwxdzcn
56
amhreihencdrvgp
93
bdfofyqlgi
59
cpbaknolumygqniuwbe
7
dzdtqmtdnipwdamwln
61
etmigbmyujysw
6
grxhwyd
67
jfsfuuppzomdsfmnyzll
65
ldgvplfitficghxluyl
53
owgatyzyqndkdetwz
87
qbbrtprovvitokrpitfr
76
qdeknxkanbwrbqcixolg
86
rqbrba
86
sdwyovjg
97
skncaygbfwsolymu
89
ukufa
42
uydvdsyaqevwwg
25
wjkhjtevg
32
yyfnmzhqi
69
zek
20
10 agwxdzcn amhreihencdrvgp bdfofyqlgi cpbaknolumygqniuwbe dzdtqmtdnipwdamwln etmigbmyujysw grxhwyd jfsfuuppzomdsfmnyzll ldgvplfitficghxluyl owgatyzyqndkdetwz 
1 qbbrtprovvitokrpitfr 
9 rqbrba sdwyovjg skncaygbfwsolymu ukufa uydvdsyaqevwwg wjkhjtevg yyfnmzhqi zek qdeknxkanbwrbqcixolg 
0 
0 
5 10
57 90 62 27
5 75 62 69
87 23 48 36
2 32 60 80
69 16 13 56
20
bhmbverlrtgvx
52
dnhosobck
99
hlznhilcvdnr
92
izbjynytcgrbpqnqhp
75
jaifakkvnlr
37
jrbtxkbobtosuaud
15
kv
98
li
75
milllkprtl
94
nhdrfrl
90
nlphcovhnfnfumapkbm
49
nuhnsdlhumwvs
21
nuwhuubonagwpmmm
28
pirifeguyqen
25
sspdbzm
68
stzuhm
71
tdfltomloxwlphacktyg
47
tixhw
15
vhuerqvvrjhnc
50
vjrrozumn
31
1 bhmbverlrtgvx 
0 
10 izbjynytcgrbpqnqhp jaifakkvnlr jrbtxkbobtosuaud kv li milllkprtl nhdrfrl nlphcovhnfnfumapkbm nuhnsdlhumwvs nuwhuubonagwpmmm 
7 pirifeguyqen sspdbzm stzuhm tdfltomloxwlphacktyg tixhw vhuerqvvrjhnc vjrrozumn 
2 hlznhilcvdnr dnhosobck 
5 10
12 9 6 3
33 73 12 95
1 11 74 96
55 15 71 18
66 1 6 67
20
ajswnebgqqqbjxmkdheo
58
arc
99
artszhohkioftbczj
100
czrmrqxj
45
duheezasxssdlf
99
eayvzrnfzxsdvbkhak
20
ebegtvr
66
gwklmtrccwkll
73
irt
81
jodtdtvupsqg
93
n
53
ouptrwdjlh
79
pckhvvk
48
rkosjzej
94
tbqaulkrgudsmnwuohsy
53
vlhygzjqiosd
47
vsizzuritvag
80
xyigmazkcb
45
yg
6
z
43
0 
10 arc artszhohkioftbczj czrmrqxj duheezasxssdlf eayvzrnfzxsdvbkhak ebegtvr gwklmtrccwkll irt jodtdtvupsqg n 
10 ouptrwdjlh pckhvvk rkosjzej tbqaulkrgudsmnwuohsy vlhygzjqiosd vsizzuritvag xyigmazkcb yg z ajswnebgqqqbjxmkdheo 
0 
0 
5 10
20 81 50 31
13 72 62 21
16 100 52 55
61 98 81 57
63 86 99 30
20
acujkdmfpuaplztwjvf
52
aukaptogrrs
89
bvigwerojcsnwkyc
50
bwkcfuxdvlbqoi
90
bxajnylvt
28
dgzcyqcydlusjuxggz
79
dwoknsorfijnwvqfurx
45
dxczy
45
ezydesaaojxxgpx
98
juyl
61
k
35
mwzvcim
9
qutttclwzcpyooq
65
qvntkgapdfms
58
qxcsubefyvn
55
sjycfizpxtzpfzo
44
tjzaazdgmtveqsh
77
ucywuorbapn
78
uyibtcpkmscfyxoidx
43
wfc
2
1 acujkdmfpuaplztwjvf 
0 
0 
10 bxajnylvt dgzcyqcydlusjuxggz dwoknsorfijnwvqfurx dxczy ezydesaaojxxgpx juyl k mwzvcim qutttclwzcpyooq qvntkgapdfms 
9 qxcsubefyvn sjycfizpxtzpfzo tjzaazdgmtveqsh ucywuorbapn uyibtcpkmscfyxoidx wfc aukaptogrrs bvigwerojcsnwkyc bwkcfuxdvlbqoi 
5 50
10 8 3 3
2 4 6 2
2 8 7 5
3 10 9 10
10 8 9 6
20
amfenzyhouqyb
28
au
83
f
20
k
31
kcqpzf
70
lpnwt
60
mciyhhqhzcux
6
nkxlqseszxqsecitby
17
nvgdtvgptbdkae
65
pzhsbcfvtzsb
63
rauqfn
93
sdhbzvpprmkngh
95
soz
41
swn
20
tjjtrbhvctmcuwipc
97
tmntkzwqguzpurixss
24
urgi
71
vyzu
45
xwxvnbkgovrvdaz
34
yqsuqsw
95
4 amfenzyhouqyb lpnwt urgi yqsuqsw 
4 f k soz swn 
1 tmntkzwqguzpurixss 
9 mciyhhqhzcux nkxlqseszxqsecitby vyzu xwxvnbkgovrvdaz nvgdtvgptbdkae rauqfn au kcqpzf tjjtrbhvctmcuwipc 
2 pzhsbcfvtzsb sdhbzvpprmkngh 
5 50
2 5 1 10
8 1 2 9
6 1 10 7
5 5 5 6
8 7 6 3
20
a
61
anwfhdzbroapky
43
aqs
6
asyrerlvmedr
27
bydnewaighdz
35
dfcolvmynxggqotjebus
40
eoihqup
82
epjb
55
hndfoylj
10
lcd
39
lthdbhinxmjodeycotbw
36
pktluolmnfpxtha
65
qubalanyjrs
9
rkybaxglies
49
sqhwsohkckgwlvzose
48
txzt
64
xqxebvboqef
96
xtgrawwn
91
ykjadz
74
zo
61
5 a qubalanyjrs rkybaxglies zo xtgrawwn 
5 aqs asyrerlvmedr bydnewaighdz dfcolvmynxggqotjebus eoihqup 
4 lcd anwfhdzbroapky ykjadz xqxebvboqef 
3 epjb hndfoylj sqhwsohkckgwlvzose 
3 lthdbhinxmjodeycotbw pktluolmnfpxtha txzt 
5 50
5 4 8 5
3 8 5 6
9 5 2 10
9 9 9 1
3 4 1 10
20
ancdcwlv
31
bcwvki
51
bmwmpfdzdbvltxqda
39
ccwojdhjqzw
23
dpkeuxvzne
37
drtehqk
47
fili
80
girpbsdjwftwlylnaw
84
gnjs
69
j
77
juawwnr
42
msorjozptebsnc
14
plmociostnusoyjcb
68
rvajwvzggnyqeptnpru
90
tmakmmcatbortnzohgz
18
wiyvtgmrjb
84
xchosuozgyolons
46
yigrbslff
49
ysm
77
zzuzjydmlkjhjggk
30
3 ancdcwlv gnjs j 
6 bmwmpfdzdbvltxqda ccwojdhjqzw juawwnr msorjozptebsnc zzuzjydmlkjhjggk rvajwvzggnyqeptnpru 
4 drtehqk dpkeuxvzne plmociostnusoyjcb fili 
5 tmakmmcatbortnzohgz girpbsdjwftwlylnaw yigrbslff wiyvtgmrjb ysm 
2 xchosuozgyolons bcwvki 
5 50
8 3 7 10
1 5 1 3
3 8 3 2
3 6 3 5
1 1 6 7
20
apppvvfctrygtlak
89
awrdgntimvwgrsogwyh
84
bagkyaojjvyrozaitziq
44
balolgsdsiqh
77
euhcsj
25
gioscscimj
32
jnzbl
77
lmlomhusnkxaqgng
81
ofusonyqpwlpcfbaha
57
p
20
qgvhqdhrnzgfkmaisr
98
rkljm
86
tljevehfr
91
tlynkqdk
95
tznddgxugv
26
vtsiqbjowume
62
wd
81
wobwxcqjgmsjp
80
ytxmdaoztkgtci
4
zv
98
5 ofusonyqpwlpcfbaha tznddgxugv apppvvfctrygtlak awrdgntimvwgrsogwyh zv 
3 balolgsdsiqh jnzbl wobwxcqjgmsjp 
3 bagkyaojjvyrozaitziq qgvhqdhrnzgfkmaisr tlynkqdk 
6 euhcsj gioscscimj ytxmdaoztkgtci tljevehfr lmlomhusnkxaqgng rkljm 
3 p vtsiqbjowume wd 
5 50
6 10 1 10
8 1 2 5
3 7 5 4
9 6 7 2
8 2 5 5
20
bdxhtiyvnidncbxm
62
cew
9
dkuzi
58
dyklulpdxpyk
27
g
62
h
31
hw
1
izhcoyxnau
42
jpmnpruqwrntnimlatc
17
jrdirm
41
kfyfybhrjjvbhqy
3
mlrfzcmjtmumtsrtr
75
nonzf
7
pekcqqqueqvdcgdkfvq
10
q
99
ujfyhulrvbwpmtjfdix
77
umfyhgfhbqsbhi
59
vyztrqkbjxksx
93
whiecyszn
15
xlryjtewrmadscw
34
4 bdxhtiyvnidncbxm cew izhcoyxnau mlrfzcmjtmumtsrtr 
3 dyklulpdxpyk ujfyhulrvbwpmtjfdix q 
3 h hw vyztrqkbjxksx 
6 jpmnpruqwrntnimlatc jrdirm kfyfybhrjjvbhqy whiecyszn xlryjtewrmadscw umfyhgfhbqsbhi 
4 nonzf pekcqqqueqvdcgdkfvq dkuzi g 
5 50
20 9 4 15
11 7 20 19
10 12 16 20
12 16 8 8
8 8 17 20
20
aiddcowxna
3
alxnogcbowinrdkjwzce
83
aytwtj
21
ekfan
49
eleyngyfyegsndt
64
fv
38
g
14
hmpezcyerp
10
ilfwwnksg
88
kvheokhedoxehezog
83
mirkhoxpdfjbmadom
71
mng
23
njwxhcilaipojnjxgop
48
spieiz
2
szu
34
vicqplxewimms
33
wfxaniwrzfgcqoynp
10
x
38
ysbxs
77
yxajhu
60
10 aiddcowxna alxnogcbowinrdkjwzce aytwtj spieiz szu vicqplxewimms wfxaniwrzfgcqoynp njwxhcilaipojnjxgop x eleyngyfyegsndt 
2 ekfan ysbxs 
5 fv g hmpezcyerp yxajhu ilfwwnksg 
1 kvheokhedoxehezog 
2 mirkhoxpdfjbmadom mng 
5 50
5 3 16 3
11 20 16 13
17 11 20 8
15 15 5 13
12 12 17 3
20
bavp
62
ca
23
ezfsjtk
83
hwhjlqkttxphrwcgeigl
40
jmoubzudsvgjaspum
8
jpdlz
18
kgkcfspxyktf
13
kgpasabhelruzxv
12
kvoxay
60
kwijsxgrvgg
56
mrtxzpwcamqotjdk
18
oiehvcwvrvrjuxogml
51
srqdbqvcaditbahljz
27
tjxqhmsynadmy
60
uhrvobtjdlmrqrsb
90
vf
19
vlnysf
81
wtnhlty
61
xbgunpa
76
zichtmwnxnlgo
61
2 zichtmwnxnlgo tjxqhmsynadmy 
4 ca vf vlnysf uhrvobtjdlmrqrsb 
7 hwhjlqkttxphrwcgeigl jmoubzudsvgjaspum jpdlz kgkcfspxyktf kgpasabhelruzxv xbgunpa wtnhlty 
5 kwijsxgrvgg mrtxzpwcamqotjdk bavp ezfsjtk oiehvcwvrvrjuxogml 
2 srqdbqvcaditbahljz kvoxay 
5 50
19 8 7 10
12 13 19 15
12 17 11 5
19 1 10 18
16 16 5 5
20
bztasxrdqjohdni
64
dwovblrsrpwchcouuckh
30
fadnywcwok
26
ghaebyrzwaevmvzhnb
17
gvfuraokmbpbnpfldleh
71
hozprpseuoikckbim
72
ihkgm
64
jnfppsvdrdzfrjdzzgl
58
knqiqkmwp
21
mdvirneqphzt
36
npirgxvvfqfomkzv
93
qqgxywhwlhswcf
80
tzpiiekollt
3
udlesioaorijvvkrwo
29
ugccemcppztewzfzdo
90
utfqciwvumhjebkceigu
15
v
64
wdjmzytgzcfi
96
wnilntitqcedelw
20
z
71
6 bztasxrdqjohdni dwovblrsrpwchcouuckh fadnywcwok ghaebyrzwaevmvzhnb tzpiiekollt udlesioaorijvvkrwo 
4 hozprpseuoikckbim utfqciwvumhjebkceigu v qqgxywhwlhswcf 
5 jnfppsvdrdzfrjdzzgl knqiqkmwp wnilntitqcedelw z wdjmzytgzcfi 
3 gvfuraokmbpbnpfldleh ihkgm npirgxvvfqfomkzv 
2 mdvirneqphzt ugccemcppztewzfzdo 
5 50
4 1 19 18
13 6 3 8
20 16 15 13
2 20 7 3
1 19 6 7
20
ai
61
bvqwbmqdaubogayvw
51
cauhidgjapnqg
69
csjtakwufxljc
79
ghxfrjjtcatau
13
hhtwyffedlxugfa
9
hyhuiaytkywdwbvaegca
84
isbaua
54
mbzixjlhinlaqmicsc
12
mekhaolgybapknwaqvlb
71
mzyhickr
61
omhezs
12
pkbizfxxoyflsnnz
14
rldwhrl
64
ryfuclrvcxmunzsof
73
sycuncfzjgxedqisikbs
36
v
20
xbdqi
45
xpwcg
8
zdbztlgroj
40
6 ai mzyhickr omhezs pkbizfxxoyflsnnz mbzixjlhinlaqmicsc mekhaolgybapknwaqvlb 
3 cauhidgjapnqg rldwhrl ryfuclrvcxmunzsof 
10 ghxfrjjtcatau hhtwyffedlxugfa sycuncfzjgxedqisikbs v xbdqi xpwcg zdbztlgroj bvqwbmqdaubogayvw hyhuiaytkywdwbvaegca csjtakwufxljc 
1 isbaua 
0 
5 50
10 7 19 5
14 19 6 2
15 14 7 1
18 19 4 7
5 3 6 17
20
anjanquhtpmvxjlls
15
apbqgw
89
bbdb
56
egwbywecktqi
15
fmdt
18
hoeaqpuhnpdoay
72
jfotd
70
lfnjpaml
77
mbnrhgptxwrzuc
6
pdxylbogsx
50
rvnucqxntanzthxftf
1
shzurowgelywkvgo
86
sja
53
slxiuocwj
35
toeumedszamrwgi
77
tyqulaygk
15
wjrzov
10
wpgouiakamdet
76
zhn
63
zipa
40
6 anjanquhtpmvxjlls sja slxiuocwj zipa apbqgw toeumedszamrwgi 
7 bbdb egwbywecktqi fmdt tyqulaygk wjrzov jfotd lfnjpaml 
1 zhn 
0 
6 mbnrhgptxwrzuc pdxylbogsx rvnucqxntanzthxftf hoeaqpuhnpdoay wpgouiakamdet shzurowgelywkvgo 
5 50
59 19 4 25
43 84 20 78
100 34 83 95
70 68 54 69
79 3 64 13
20
ageyekyeotphxor
66
ahivvgoxeinupvjjmna
25
cdhrvlw
93
epihzzwa
37
gqv
48
gwqdctxjqqaa
51
ktelqfyr
35
nicuhosl
7
pggqv
49
qssfunopqcpapwtlszo
4
rndbqbrbbvjsxyn
51
slbmbuaj
62
t
58
tkozezypszfeha
68
uodsxhlpilvxjb
52
wmlpngngl
50
xduistxka
35
yjhcjqm
84
ypefmbnrzdkhwi
90
ztuyqfldahhb
12
20 ageyekyeotphxor ahivvgoxeinupvjjmna cdhrvlw epihzzwa gqv gwqdctxjqqaa ktelqfyr nicuhosl pggqv qssfunopqcpapwtlszo rndbqbrbbvjsxyn slbmbuaj t tkozezypszfeha uodsxhlpilvxjb wmlpngngl xduistxka yjhcjqm ypefmbnrzdkhwi ztuyqfldahhb 
0 
0 
0 
0 
5 50
46 66 37 1
21 48 55 59
54 91 44 25
70 30 62 58
38 72 71 78
20
aewcafbvegypxtohswql
49
bpgmyiv
78
chbfvhlvwjvgtaxp
3
eozeghdjcvhofzmefe
20
gv
66
iaixcggahrxeu
29
iruluvirbwthphzhvit
40
iuyjteocfyqgoxds
64
kimnqo
72
lsclcjc
56
lxqjghfdakxekxub
93
m
78
obg
4
oeizzjxfxz
90
plamvbets
33
rfdrljdolmytuc
11
tsetdq
35
wqcpsi
60
z
83
znxinpggugojxmsxqcwz
25
4 aewcafbvegypxtohswql bpgmyiv chbfvhlvwjvgtaxp eozeghdjcvhofzmefe 
16 iaixcggahrxeu iruluvirbwthphzhvit iuyjteocfyqgoxds kimnqo lsclcjc lxqjghfdakxekxub m obg oeizzjxfxz plamvbets rfdrljdolmytuc tsetdq wqcpsi z znxinpggugojxmsxqcwz gv 
0 
0 
0 
5 50
82 62 70 78
98 13 90 40
59 97 6 54
71 92 17 95
97 41 78 90
20
cgautxwtmlabznreq
70
cvkauepojwpjefa
12
diprexliwld
65
ficct
98
grdtqyribdzbdiff
25
gsdsiibnae
24
hjgfnglgipzhqga
8
jqvgsd
97
kyhisgyaemjfmrfsgrgv
4
lfh
35
mmsudyzdczaq
90
n
4
odlomhgwzsscl
27
ojuvlqpnvuorcm
65
pldvzhx
46
qukyrrnohsovufck
33
swcchorziuixlppbvv
84
tyxjoljgg
10
ylngxglaknqsmkmjibms
88
zujjnypzonnznuaqr
37
20 cgautxwtmlabznreq cvkauepojwpjefa diprexliwld ficct grdtqyribdzbdiff gsdsiibnae hjgfnglgipzhqga jqvgsd kyhisgyaemjfmrfsgrgv lfh mmsudyzdczaq n odlomhgwzsscl ojuvlqpnvuorcm pldvzhx qukyrrnohsovufck swcchorziuixlppbvv tyxjoljgg ylngxglaknqsmkmjibms zujjnypzonnznuaqr 
0 
0 
0 
0 
5 50
69 9 2 54
76 77 26 21
12 54 16 83
23 53 73 84
4 10 33 3
20
bmnxihdetiqy
75
dhmdlcbnkpokanszze
26
emc
87
fdctpnpzcf
3
fqngmlfbk
53
gdm
87
hbvgtopviqequtuzewm
17
hlvtavljzxsgxjyt
57
jkpdwxthqedkyog
79
jpoytysgjmwp
27
lcgekveeecbeeybsh
72
nuokijkionqdm
33
qezequdandvc
38
qykpwytljsspdjy
40
rkvykuxpyeagjshj
75
slysoumltgtrcqgy
30
thfdjdps
37
urkekqnwdg
38
vgmecwqzarqdnfr
8
wxbhydmyb
54
20 bmnxihdetiqy dhmdlcbnkpokanszze emc fdctpnpzcf fqngmlfbk gdm hbvgtopviqequtuzewm hlvtavljzxsgxjyt jkpdwxthqedkyog jpoytysgjmwp lcgekveeecbeeybsh nuokijkionqdm qezequdandvc qykpwytljsspdjy rkvykuxpyeagjshj slysoumltgtrcqgy thfdjdps urkekqnwdg vgmecwqzarqdnfr wxbhydmyb 
0 
0 
0 
0 
5 50
59 9 99 28
98 25 1 73
100 26 15 42
94 6 74 70
80 16 98 34
20
ayhoayordvvtkc
40
ch
74
eryetue
59
gahetf
21
hjvhzybokveeaxflj
78
jtldpiukiqdfmnwm
76
k
64
kpxfebgk
40
om
51
otmqusdzhuoyeavdsvk
59
ovbphkivfjvpgxhj
77
pgiyswfmsu
27
piaqhupfusebwv
4
qfcbmlksbfcpynnvzxne
92
qldrufcidocofac
24
rinavovgihwtb
55
sghpkh
74
sjdsknqytq
65
wpubtyezskqswm
33
zwmgzpdmgzktgdmgqj
37
20 ayhoayordvvtkc ch eryetue gahetf hjvhzybokveeaxflj jtldpiukiqdfmnwm k kpxfebgk om otmqusdzhuoyeavdsvk ovbphkivfjvpgxhj pgiyswfmsu piaqhupfusebwv qfcbmlksbfcpynnvzxne qldrufcidocofac rinavovgihwtb sghpkh sjdsknqytq wpubtyezskqswm zwmgzpdmgzktgdmgqj 
0 
0 
0 
0 
fin = open('input.txt', 'r')
fout = open('output.txt', 'w')

n, t = list(map(int, fin.readline().split()))
teams = [list(map(int, fin.readline().split())) for _ in range(0, n)]
m = int(fin.readline())
words = [(fin.readline(), int(fin.readline())) for _ in range(0, m)]
d = [{i[0]: 0 for i in words} for _ in range(0, n)]
pts = [0 for _ in range(0, n)]
solved_words = [[] for _ in range(0, n)]
removed = []
player = 0
team = 0
while sum(pts) < m:
    if player == 0:
        a = teams[team][2]
        b = teams[team][1]
    else:
        a = teams[team][0]
        b = teams[team][3]

    time_remaining = t
    for i in range(0, len(words)):
        if i in removed:
            continue

        word, complexity = words[i]
        time_before = d[team][word]
        time_needed = max(1, complexity - (a + b) - time_before)
        if time_needed <= time_remaining:
            pts[team] += 1
            solved_words[team].append(word.strip())
            removed.append(i)
            time_remaining -= time_needed
        else:
            d[team][word] += time_needed
            words.append(words.pop(i))
            break

    if player == 0:
        player = 1
    else:
        player = 0

    team = (team + 1) % n

for i in range(0, n):
    fout.write(str(pts[i])+' '+' '.join(list(map(str, solved_words[i])))+'\n')
