Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.

Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya.


-----Input-----

The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.

Next follows number n (1 ≤ n ≤ 90) — the number of fouls. 

Each of the following n lines contains information about a foul in the following form:   first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs;  then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player;  then goes the player's number m (1 ≤ m ≤ 99);  then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. 

The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute.


-----Output-----

For each event when a player received his first red card in a chronological order print a string containing the following information:  The name of the team to which the player belongs;  the player's number in his team;  the minute when he received the card. 

If no player received a card, then you do not need to print anything.

It is possible case that the program will not print anything to the output (if there were no red cards).


-----Examples-----
Input
MC
CSKA
9
28 a 3 y
62 h 25 y
66 h 42 y
70 h 25 y
77 a 4 y
79 a 25 y
82 h 42 r
89 h 16 y
90 a 13 r

Output
MC 25 70
MC 42 82
CSKA 13 90

Difficulty: EASY

Solutions:
from collections import defaultdict

def main(t1, t2, n, t, ha, m, yr):
	reds = {}
	yellows = {}
	teams = [t1, t2]
	for i in range(n):
		player = (ha[i], m[i])
		if player not in reds:
			if player not in yellows:
				yellows[player] = 0
			if yr[i] == 'y':
				yellows[player] += 1
			if yellows[player] >= 2 or yr[i] == 'r':
				reds[player] = 1
				print(teams[ha[i] == 'a'], m[i], t[i])

def main_input():
	t1 = input()
	t2 = input()
	n = int(input())
	t = list(range(n))
	ha = list(range(n))
	m = list(range(n))
	yr = list(range(n))
	for i in range(n):
		(t[i], ha[i], m[i], yr[i]) = input().split()
	t = [int(x) for x in t]
	m = [int(x) for x in m]
	main(t1, t2, n, t, ha, m, yr)
main_input()


home = input()
away = input()
n = int(input())
homey = set()
homer = set()
awayy = set()
awayr = set()
ans = []
for i in range(n):
	tmp = input().split()
	if tmp[1] == 'h':
		if tmp[2] in homer:
			continue
		if tmp[3] == 'r':
			ans.append(' '.join([home, tmp[2], tmp[0]]))
			homer.add(tmp[2])
		elif tmp[2] in homey:
			ans.append(' '.join([home, tmp[2], tmp[0]]))
			homer.add(tmp[2])
		else:
			homey.add(tmp[2])
	else:
		if tmp[2] in awayr:
			continue
		if tmp[3] == 'r':
			ans.append(' '.join([away, tmp[2], tmp[0]]))
			awayr.add(tmp[2])
		elif tmp[2] in awayy:
			ans.append(' '.join([away, tmp[2], tmp[0]]))
			awayr.add(tmp[2])
		else:
			awayy.add(tmp[2])
for ln in ans:
	print(ln)


def main():
	s1 = read(0)
	s2 = read(0)
	(n,) = read()
	arr = dict()
	res = []
	for i in range(n):
		(w, x, y, z) = read(1)
		w = int(w)
		if x + y in arr.keys():
			if arr[x + y][1] != 'r':
				res.append((x, y, w))
			arr[x + y] = (w, 'r')
		else:
			arr[x + y] = (w, z)
			if arr[x + y][1] == 'r':
				res.append((x, y, w))
	for (x, y, w) in res:
		print(s1 if x == 'h' else s2, y, w)

def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return list(map(int, inputs.split()))

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')
write(main())


homename = input()
awayname = input()
fouls = int(input())
a = []
b = []
for foul in range(fouls):
	data = input().split()
	if data[3] == 'r':
		for j in range(len(b)):
			if b[j][1:3] == data[1:3]:
				break
		else:
			if data[1] == 'h':
				print(' '.join([homename, data[2], data[0]]))
			else:
				print(' '.join([awayname, data[2], data[0]]))
		b.append(data)
	else:
		for i in range(len(a)):
			if a[i][1:] == data[1:]:
				if data[1] == 'h':
					print(' '.join([homename, data[2], data[0]]))
				else:
					print(' '.join([awayname, data[2], data[0]]))
				b.append(a[i])
				a.remove(a[i])
				break
		else:
			for j in range(len(b)):
				if b[j][1:3] == data[1:3]:
					break
			else:
				a.append(data)


teams = [input(), input()]
n = int(input())
cnt = [0] * 10000
used = [False] * 10000
for i in range(n):
	(time, t, m, c) = input().split()
	m = int(m)
	if t != 'h':
		m += 1000
	if c == 'y':
		cnt[m] += 1
	else:
		cnt[m] += 2
	if cnt[m] >= 2 and (not used[m]):
		used[m] = True
		m %= 1000
		ans = ''
		if t == 'h':
			ans += teams[0]
		else:
			ans += teams[1]
		ans += ' '
		ans = ans + str(m)
		ans += ' '
		ans += time
		print(ans)


h = input()
aw = input()
n = int(input())
team = [[0, 0] for i in range(200)]
ans = []
for i in range(n):
	(a, b, c, d) = map(str, input().split())
	a = int(a)
	c = int(c)
	if b == 'h':
		if d == 'y':
			team[c][0] += 1
		elif team[c][0] < 2:
			team[c][0] = 2
		if team[c][0] == 2:
			ans.append([h, c, a])
			team[c][0] = 100
	else:
		if d == 'y':
			team[c][1] += 1
		elif team[c][1] < 2:
			team[c][1] = 2
		if team[c][1] == 2:
			ans.append([aw, c, a])
			team[c][1] = 100
for i in ans:
	print(*i)


(h, a) = (input(), input())
s = lambda x, n, m: '%s %s %s' % (x, n, m)
t = int(input())
(b, c) = (dict(), dict())

def is_red(d, key, name, m, func):
	if d[key] in (2, 3):
		print(func(name, key, m))
while t > 0:
	d = input().split()
	cnt = 1 if d[3] == 'y' else 2
	if d[1] == 'h':
		if b.get(d[2], 0) < 2 and 1 < b.get(d[2], 0) + cnt < 4:
			print(s(h, d[2], d[0]))
		b[d[2]] = b.get(d[2], 0) + cnt
	else:
		if c.get(d[2], 0) < 2 and 1 < c.get(d[2], 0) + cnt < 4:
			print(s(a, d[2], d[0]))
		c[d[2]] = c.get(d[2], 0) + cnt
	t -= 1


def main():
	home = input()
	away = input()
	n = int(input())
	cards = {}
	teams = {}
	teams['h'] = home
	teams['a'] = away
	for i in range(n):
		(t, team, m, card) = map(str, input().split())
		t = int(t)
		m = int(m)
		curr = (team, m)
		if curr not in cards.keys():
			cards[team, m] = [[card, 1]]
			if card == 'r':
				print(teams[team], m, t)
		elif len(cards[team, m]) == 1:
			if cards[team, m][0][0] == 'y' and cards[team, m][0][1] == 1:
				print(teams[team], m, t)
				cards[team, m][0][1] += 1
main()


(h, a) = (input(), input())
(H, A) = ([0] * 100, [0] * 100)
s = []
for i in range(int(input())):
	(m, x, n, c) = input().split()
	k = int(n)
	if c == 'y':
		if x == 'h':
			H[k] += 1
			if H[k] == 2:
				s.append(h + ' ' + n + ' ' + m)
		else:
			A[k] += 1
			if A[k] == 2:
				s.append(a + ' ' + n + ' ' + m)
	elif x == 'h':
		if H[k] < 2:
			H[k] = 2
			s.append(h + ' ' + n + ' ' + m)
	elif A[k] < 2:
		A[k] = 2
		s.append(a + ' ' + n + ' ' + m)
print('\n'.join(s))


(a, b, n) = (input(), input(), int(input()))
ans = []
(p1, p2, f1, f2) = ([0] * 100, [0] * 100, [0] * 100, [0] * 100)
for i in range(n):
	(t, com, m, c) = input().split()
	(t, m) = map(int, (t, m))
	if com == 'h':
		p1[m] += 1 if c == 'y' else 2
		if p1[m] >= 2 and (not f1[m]):
			ans.append((a, m, t))
			f1[m] = 1
	else:
		p2[m] += 1 if c == 'y' else 2
		if p2[m] >= 2 and (not f2[m]):
			ans.append((b, m, t))
			f2[m] = 1
[print(*i) for i in ans]


import collections
a_name = input()
b_name = input()
n = int(input())
players = [collections.Counter() for i in range(2)]
for i in range(n):
	(t, team, player, color) = input().split()
	team = 0 if team == 'h' else 1
	player = int(player)
	if color == 'y' and players[team][player] == 0:
		players[team][player] = 1
	elif color == 'r' and 0 <= players[team][player] <= 1 or players[team][player] == 1:
		players[team][player] = 2
		print(a_name if team == 0 else b_name, player, t)


ht = input()
at = input()
N = int(input())
hc = [0] * 100
ac = [0] * 100
for n in range(N):
	ar = input().split()
	t = int(ar[0])
	m = int(ar[2])
	if ar[1] == 'h':
		if ar[3] == 'r':
			if hc[m] < 2:
				print(ht, m, t)
				hc[m] = 2
		else:
			hc[m] += 1
			if hc[m] == 2:
				print(ht, m, t)
	if ar[1] == 'a':
		if ar[3] == 'r':
			if ac[m] < 2:
				print(at, m, t)
				ac[m] = 2
		else:
			ac[m] += 1
			if ac[m] == 2:
				print(at, m, t)


hom_tm = input()
awy_tm = input()
fouls = int(input())
home = {}
away = {}
for i in range(fouls):
	(time, land, player, card) = input().split()
	if land == 'h':
		if card == 'y':
			if player not in home:
				home[player] = 1
			elif home[player] != 'done':
				home[player] += 1
			if home[player] != 'done' and home[player] == 2:
				home[player] = 'done'
				print(hom_tm, player, time)
		elif player in home and home[player] != 'done' or player not in home:
			home[player] = 'done'
			print(hom_tm, player, time)
	elif card == 'y':
		if player not in away:
			away[player] = 1
		elif away[player] != 'done':
			away[player] += 1
		if away[player] != 'done' and away[player] == 2:
			away[player] = 'done'
			print(awy_tm, player, time)
	elif player in away and away[player] != 'done' or player not in away:
		away[player] = 'done'
		print(awy_tm, player, time)


s1 = input()
s2 = input()
n = int(input())
h = []
a = []
for i in range(n):
	k = input().split()
	if k[1] == 'h':
		if h.count(k[2]) == 0 and k[3] == 'y':
			h.append(k[2])
		elif h.count(k[2]) == 1:
			h.append(k[2])
			print(s1, k[2], k[0])
		if h.count(k[2]) == 0 and k[3] == 'r':
			h.append(k[2])
			h.append(k[2])
			print(s1, k[2], k[0])
	else:
		if a.count(k[2]) == 0 and k[3] == 'y':
			a.append(k[2])
		elif a.count(k[2]) == 1:
			a.append(k[2])
			print(s2, k[2], k[0])
		if a.count(k[2]) == 0 and k[3] == 'r':
			a.append(k[2])
			a.append(k[2])
			print(s2, k[2], k[0])


team_one = input()
team_two = input()
n = int(input())
pts_one = [0 for i in range(100)]
pts_two = [0 for i in range(100)]
for i in range(n):
	line = input()
	(t, team, m, card) = line.split()
	t = int(t)
	m = int(m)
	fault = 0
	if card == 'y':
		fault = 1
	else:
		fault = 2
	if team == 'h':
		pts_one[m] += fault
		if pts_one[m] == 2 or (pts_one[m] == 3 and fault == 2):
			print(team_one, m, t)
	elif team == 'a':
		pts_two[m] += fault
		if pts_two[m] == 2 or (pts_two[m] == 3 and fault == 2):
			print(team_two, m, t)


s = input()
t = input()
s.rstrip()
t.rstrip()
n = int(input())
a = [0] * 100
b = [0] * 100
for i in range(n):
	e = list(map(str, input().split()))
	if e[1] == 'h':
		if a[int(e[2])] != -1:
			if e[3] == 'y':
				a[int(e[2])] = a[int(e[2])] + 1
			elif e[3] == 'r':
				a[int(e[2])] = a[int(e[2])] + 2
			if a[int(e[2])] >= 2:
				print(s, int(e[2]), e[0])
				a[int(e[2])] = -1
	elif b[int(e[2])] != -1:
		if e[3] == 'y':
			b[int(e[2])] = b[int(e[2])] + 1
		elif e[3] == 'r':
			b[int(e[2])] = b[int(e[2])] + 2
		if b[int(e[2])] >= 2:
			print(t, int(e[2]), e[0])
			b[int(e[2])] = -1


name = {}
name['h'] = input()
name['a'] = input()
n = int(input())
info = {}
for i in range(n):
	(m, t, p, c) = input().split()
	m = int(m)
	p = int(p)
	if c == 'r' and (not ((t, p) in info and info[t, p] == 'r')):
		print(name[t], p, m)
		info[t, p] = 'r'
	elif c == 'y':
		if (t, p) in info and info[t, p] != 'r':
			print(name[t], p, m)
			info[t, p] = 'r'
		elif not (t, p) in info:
			info[t, p] = c


G = {}
G['h'] = input()
G['a'] = input()
n = int(input())
M = {}
for i in range(n):
	[t, zn, gra, kartka] = input().split(' ')
	t = int(t)
	gra = int(gra)
	if (zn, gra) not in M:
		M[zn, gra] = 0
	if M[zn, gra] >= 2:
		continue
	if kartka == 'y':
		M[zn, gra] += 1
	else:
		M[zn, gra] += 2
	if M[zn, gra] >= 2:
		print(G[zn], gra, t)


homeTeam = input()
cmngTeam = input()
n = int(input())
stck = []
hmTeam = [0] * 100
cmTeam = [0] * 100
i = 0
while i < n:
	stck.append(input())
	i += 1
i = 0
while i < len(stck):
	cur = stck[i].split()
	if cur[1] == 'h':
		if cur[3] == 'y':
			hmTeam[int(cur[2])] += 1
			if hmTeam[int(cur[2])] >= 2:
				if hmTeam[int(cur[2])] >= 0:
					print(homeTeam, end=' ')
					print(cur[2], end=' ')
					print(cur[0], end='\n')
					hmTeam[int(cur[2])] = -100000
		elif hmTeam[int(cur[2])] >= 0:
			print(homeTeam, end=' ')
			print(cur[2], end=' ')
			print(cur[0], end='\n')
			hmTeam[int(cur[2])] = -100000
	elif cur[3] == 'y':
		cmTeam[int(cur[2])] += 1
		if cmTeam[int(cur[2])] >= 2:
			if cmTeam[int(cur[2])] >= 0:
				print(cmngTeam, end=' ')
				print(cur[2], end=' ')
				print(cur[0], end='\n')
				cmTeam[int(cur[2])] = -10000
	elif cmTeam[int(cur[2])] >= 0:
		print(cmngTeam, end=' ')
		print(cur[2], end=' ')
		print(cur[0], end='\n')
		cmTeam[int(cur[2])] = -100000
	i += 1


from collections import *
home = input()
away = input()
n = int(input())
hd = defaultdict(int)
ad = defaultdict(int)
for i in range(n):
	a = list(map(str, input().split()))
	if a[1] == 'h':
		if hd[a[2]] != -1:
			if a[-1] == 'r':
				hd[a[2]] = -1
				print(home, a[2], a[0])
			else:
				hd[a[2]] += 1
				if hd[a[2]] == 2:
					hd[a[2]] = -1
					print(home, a[2], a[0])
	elif ad[a[2]] != -1:
		if a[-1] == 'r':
			ad[a[2]] = -1
			print(away, a[2], a[0])
		else:
			ad[a[2]] += 1
			if ad[a[2]] == 2:
				ad[a[2]] = -1
				print(away, a[2], a[0])


s = input()
t = input()
n = int(input())
(homecards, awaycards, homefouls, awayfouls) = ({}, {}, [], [])
fouls = []

def newfoul(x, y):
	if y == 'h':
		if not x[1] in homefouls:
			homefouls.append(x[1])
			fouls.append(x)
	elif not x[1] in awayfouls:
		awayfouls.append(x[1])
		fouls.append(x)
for x in range(n):
	string = input()
	foul = string.split()
	(a, b, c, d) = (int(foul[0]), foul[1], int(foul[2]), foul[3])
	if d == 'r':
		if b == 'h':
			newfoul([s, c, a], 'h')
		else:
			newfoul([t, c, a], 'a')
	elif b == 'h':
		if not c in homecards:
			homecards[c] = 0
		homecards[c] += 1
		if homecards[c] == 2:
			newfoul([s, c, a], 'h')
	else:
		if not c in awaycards:
			awaycards[c] = 0
		awaycards[c] += 1
		if awaycards[c] == 2:
			newfoul([t, c, a], 'a')
for x in fouls:
	print(' '.join(map(str, x)))


I = lambda : input()
IMI = lambda : map(int, input().split())
P = lambda *l: print(*l)
team1 = I()
team2 = I()
n = int(I())
EVENTS = [list(I().split()) for i in range(n)]
res_team1 = [0] * 100
res_team2 = [0] * 100
res = []
for e in EVENTS:
	if e[1] == 'h':
		if e[3] == 'y':
			if res_team1 != 1:
				res_team1[int(e[2])] += 1
		elif res_team1 != 1:
			res_team1[int(e[2])] += 2
		if res_team1[int(e[2])] >= 2:
			res_team1[int(e[2])] = -100000
			print(team1, e[2], e[0])
	else:
		if e[3] == 'y':
			if res_team2 != 1:
				res_team2[int(e[2])] += 1
		elif res_team2 != 1:
			res_team2[int(e[2])] += 2
		if res_team2[int(e[2])] >= 2:
			res_team2[int(e[2])] = -100000
			print(team2, e[2], e[0])


(ho, a) = (input(), input())
r = []
(_h, _a) = ([0] * 100, [0] * 100)
for _ in ' ' * int(input()):
	(t, h, m, y) = input().split()
	m = int(m)
	if h == 'h':
		if y == 'r':
			if _h[m] < 2:
				r.append([ho, m, t])
				_h[m] = 3
		else:
			_h[m] += 1
			if _h[m] == 2:
				r.append([ho, m, t])
				_h[m] = 3
	elif y == 'r':
		if _a[m] < 2:
			r.append([a, m, t])
			_a[m] = 3
	else:
		_a[m] += 1
		if _a[m] == 2:
			r.append([a, m, t])
			_a[m] = 3
for i in r:
	print(*i)


home = input()
away = input()
n = int(input())
yellows = set()
reds = set()
s = {'h': home, 'a': away}
while n:
	x = input().split()
	time = int(x[0])
	team = x[1]
	shirt = int(x[2])
	card = x[3]
	if card == 'y':
		if (shirt, team) in yellows and (shirt, team) not in reds:
			print(s[team], shirt, time)
			yellows.remove((shirt, team))
			reds.add((shirt, team))
		else:
			yellows.add((shirt, team))
	elif (shirt, team) not in reds:
		reds.add((shirt, team))
		print(s[team], shirt, time)
	n -= 1


I = input
s = [I(), I()]
d = {}
for _ in '0' * int(I()):
	(m, h, t, k) = I().split()
	t = int(t) * (2 * (h == 'h') - 1)
	a = d.get(t, 0)
	d[t] = [a + 1, max(a, 2)][k == 'r']
	if d[t] == 2:
		print(s[t < 0], abs(t), m)
		d[t] = 3


s1 = input()
s2 = input()
n = int(input())
from collections import *
al = defaultdict(int)
for i in range(n):
	(time, ty, num, col) = map(str, input().split())
	al[ty + num + col] += 1
	if col == 'y' and al[ty + num + col] == 2 and (al[ty + num + 'r'] == 0):
		if ty == 'a':
			print(s2, end=' ')
			print(num, end=' ')
			print(time)
		else:
			print(s1, end=' ')
			print(num, end=' ')
			print(time)
	elif col == 'r' and al[ty + num + col] == 1 and (al[ty + num + 'y'] == 0 or al[ty + num + 'y'] == 1):
		if ty == 'a':
			print(s2, end=' ')
			print(num, end=' ')
			print(time)
		else:
			print(s1, end=' ')
			print(num, end=' ')
			print(time)


__author__ = 'Rakshak.R.Hegde'
teams = dict(h=input(), a=input())
n = int(input())
fouls = {}
while n:
	n -= 1
	details = input().split()
	player = details[1] + details[2]
	foulsByM = fouls.get(player, 0) + 1
	fouls[player] = foulsByM
	if details[3] == 'r' and foulsByM <= 2:
		fouls[player] = 3
		print(teams[details[1]], details[2], details[0])
	elif foulsByM == 2:
		print(teams[details[1]], details[2], details[0])


from collections import defaultdict
(n1, n2) = (input(), input())
n = int(input())
mp = [[0 for i in range(100)], [0 for i in range(100)]]
for i in range(n):
	line = input().split()
	t = int(line[0])
	m = int(line[2])
	if line[1] == 'h':
		mp[0][m] += 1
		if line[3] == 'r':
			if mp[0][m] < 3:
				print(n1, m, t)
			mp[0][m] = 3
			continue
		if mp[0][m] == 2:
			print(n1, m, t)
			mp[0][m] = 3
	else:
		mp[1][m] += 1
		if line[3] == 'r':
			if mp[1][m] < 3:
				print(n2, m, t)
			mp[1][m] = 3
			continue
		if mp[1][m] == 2:
			print(n2, m, t)
			mp[1][m] = 3


import collections
a = input()
b = input()
stats = collections.defaultdict(int)
removed = set()
for _ in range(int(input())):
	(minute, team, number, card) = str.split(input())
	player = team + number
	stats[player] += int(1 if card == 'y' else 2)
	if stats[player] > 1 and player not in removed:
		removed.add(player)
		print(a if team == 'h' else b, number, minute)


home = input()
away = input()
n = int(input())
ytrial = []
rtrial = []
for s in range(n):
	(m, t, p, c) = map(str, input().split())
	pair = []
	pair.append(p)
	pair.append(t)
	if (c == 'r' or pair in ytrial) and pair not in rtrial:
		rtrial.append(pair)
		if t == 'a':
			print(away, end=' ')
		else:
			print(home, end=' ')
		print(p, end=' ')
		print(m)
	else:
		pair = []
		pair.append(p)
		pair.append(t)
		ytrial.append(pair)


teams = ['', '']
cards = [[0] * 100, [0] * 100]
for i in range(0, 2):
	teams[i] = input()
n = int(input())
for i in range(0, n):
	args = input().split()
	time = args[0]
	home = args[1]
	index = 0 if home == 'h' else 1
	num = int(args[2])
	card = args[3]
	if cards[index][num] < 0:
		continue
	if card == 'y':
		cards[index][num] += 1
	else:
		cards[index][num] += 2
	if cards[index][num] > 1:
		print(teams[index], num, time)
		cards[index][num] = -1


hometeam = input()
awayteam = input()
n = int(input())
homeDict = {}
awayDict = {}
for i in range(n):
	str = input().split(' ')
	t = int(str[0])
	team = str[1]
	dict = homeDict if team == 'h' else awayDict
	m = int(str[2])
	color = 1 if str[3] == 'y' else 2
	card = dict.get(m) if m in dict else 0
	if card == 1 or card + color == 2:
		dict.update({m: 3})
		print('%s %d %d' % (hometeam if str[1] == 'h' else awayteam, m, t))
	elif card == 0:
		dict.update({m: 1})


teams = dict()
teams['h'] = input()
teams['a'] = input()
n = int(input())
data = {}
report = []
for _ in range(n):
	(time, team, num, card) = input().split()
	name = team + num
	if name not in data:
		data[name] = card
		if card == 'r':
			report.append('{} {} {}'.format(teams[team], num, time))
	elif data[name] == 'y':
		report.append('{} {} {}'.format(teams[team], num, time))
		data[name] = 'r'
print('\n'.join(report))


__author__ = 'PrimuS'
s1 = input().strip('\n')
s2 = input().strip('\n')
n = int(input())
d1 = {}
d2 = {}
for i in range(n):
	ss = input().split()
	t = int(ss[0])
	x = int(ss[2])
	ss[3].strip('\n')
	if ss[1] == 'h':
		if x in d1 and d1[x] == 1:
			print(s1, x, t)
			d1[x] = 2
		elif x not in d1:
			if ss[3] == 'r':
				print(s1, x, t)
				d1[x] = 2
			else:
				d1[x] = 1
	elif x in d2 and d2[x] == 1:
		print(s2, x, t)
		d2[x] = 2
	elif x not in d2:
		if ss[3] == 'r':
			print(s2, x, t)
			d2[x] = 2
		else:
			d2[x] = 1


team_name = dict()
team_name['h'] = input()
team_name['a'] = input()
N = int(input())
info = dict()
for _ in range(N):
	(m, team, player, card) = input().split()
	m = int(m)
	player = int(player)
	if card == 'r' and (not ((team, player) in info and info[team, player] == 'r')):
		print(team_name[team], player, m)
		info[team, player] = 'r'
	elif card == 'y':
		if (team, player) in info and info[team, player] != 'r':
			print(team_name[team], player, m)
			info[team, player] = 'r'
		elif not (team, player) in info:
			info[team, player] = card


home = input()
away = input()
n = int(input())
vec = []
arr = []
for i in range(n):
	arr.append(list(input().split(' ')))
mp1 = {}
mp2 = {}
res1 = {}
res2 = {}
for i in range(n):
	(min, team_name, player, card_color) = (arr[i][0], arr[i][1], arr[i][2], arr[i][3])
	if card_color == 'y' and team_name == 'h' and (player not in mp1):
		mp1[player] = True
	elif card_color == 'y' and team_name == 'a' and (player not in mp2):
		mp2[player] = True
	elif card_color == 'y' and team_name == 'h' and (player in mp1):
		ans = ''
		if player not in res1:
			res1[player] = True
			ans += home
			ans += ' '
			ans += player
			ans += ' '
			ans += min
			vec.append(ans)
	elif card_color == 'y' and team_name == 'a' and (player in mp2):
		ans = ''
		if player not in res2:
			res2[player] = True
			ans += away
			ans += ' '
			ans += player
			ans += ' '
			ans += min
			vec.append(ans)
	elif card_color == 'r':
		ans = ''
		if team_name == 'a':
			if player not in res2:
				res2[player] = True
				ans += away
				ans += ' '
				ans += player
				ans += ' '
				ans += min
				vec.append(ans)
		else:
			ans = ''
			if player not in res1:
				res1[player] = True
				ans += home
				ans += ' '
				ans += player
				ans += ' '
				ans += min
				vec.append(ans)
for i in vec:
	print(i)


home = input()
away = input()
n = int(input())
hT = {}
hSet = {}
aT = {}
aSet = {}
reds = []
for i in range(n):
	List = input().split()
	t = List[0]
	if List[1] == 'h':
		if List[2] in hT:
			hT[List[2]] = 'r'
		else:
			hT[List[2]] = List[3]
		if hT[List[2]] == 'r':
			reds.append([home, List[2], t])
	else:
		if List[2] in aT:
			aT[List[2]] = 'r'
		else:
			aT[List[2]] = List[3]
		if aT[List[2]] == 'r':
			reds.append([away, List[2], t])
Set = set()
for red in reds:
	if not (red[0], red[1]) in Set:
		print(red[0], red[1], red[2])
		Set.add((red[0], red[1]))


teamname = []
teamname.append(input().strip())
teamname.append(input().strip())
n = int(input())
foul = [[0 for m in range(100)] for i in range(2)]
for i in range(n):
	info = input().split()
	t = int(info[0])
	team = info[1]
	m = int(info[2])
	card = info[3]
	if team == 'h':
		td = 0
	else:
		td = 1
	if foul[td][m] >= 2:
		continue
	if card == 'y':
		foul[td][m] += 1
	else:
		foul[td][m] += 2
	if foul[td][m] >= 2:
		print('{0} {1} {2}'.format(teamname[td], m, t))


s = [input(), input()]
n = int(input())
ans = [[0] * 101 for i in range(2)]
for i in range(n):
	a = input().split()
	q = 0
	p = 0
	if a[3] == 'y':
		q = 1
	else:
		q = 2
	if a[1] == 'h':
		p = 0
	else:
		p = 1
	if ans[p][int(a[2])] >= 2:
		continue
	ans[p][int(a[2])] += q
	if ans[p][int(a[2])] >= 2:
		print(s[p] + ' ' + a[2] + ' ' + a[0])


def input_split(f):
	return map(f, input().split())

def main():
	home = input()
	away = input()
	n = int(input())
	p = lambda team, m, time: print('{} {} {}'.format(home if team == 'h' else away, m, time))
	r = set([])
	y = set([])
	for i in range(n):
		(t, team, m, c) = input_split(str)
		a = (team, m)
		if c == 'r':
			if a not in r:
				r.add(a)
				y.add(a)
				p(team, m, t)
		else:
			if a in r:
				pass
			elif a in y:
				r.add(a)
				p(team, m, t)
			y.add(a)
main()


(team1, team2) = (input(), input())
n = int(input())
yellow = set()
red = set()
for i in range(n):
	(a, b, c, d) = input().split()
	a = int(a)
	c = int(c)
	c2 = c
	if b != 'h':
		c += 111000
	if d == 'y':
		if c in red:
			continue
		if c in yellow:
			print(team1 if b == 'h' else team2, c2, a)
			red.add(c)
		else:
			yellow.add(c)
	if d == 'r':
		if c in red:
			continue
		print(team1 if b == 'h' else team2, c2, a)
		red.add(c)


f = input()
s = input()
n = int(input())
ans = []
printed = []
for i in range(n):
	(t, ty, m, ca) = input().split()
	li = []
	if ca == 'r':
		li.append(ty)
		li.append(m)
		if li not in printed:
			if ty == 'h':
				print(f, m, t)
			else:
				print(s, m, t)
			printed.append(li)
	else:
		li.append(ty)
		li.append(m)
		if li not in ans:
			ans.append(li)
		elif li not in printed:
			if ty == 'h':
				print(f, m, t)
			else:
				print(s, m, t)
			printed.append(li)


s = input()
tr = input()
h = set()
g = set()
udalh = set()
udalg = set()
n = int(input())
for i in range(n):
	(t, hq, m, y) = input().split()
	if hq == 'h':
		if m not in udalh:
			if m in h or y == 'r':
				print(s, m, t)
				udalh.add(m)
			else:
				h.add(m)
	elif m not in udalg:
		if m in g or y == 'r':
			print(tr, m, t)
			udalg.add(m)
		else:
			g.add(m)


sh = input()
sa = input()
lh = {}
la = {}
n = int(input())
sc = 0
(mi, s, num, f) = (0, '', 0, '')
while n > 0:
	(mi, s, num, f) = input().split()
	mi = int(mi)
	num = int(num)
	if f == 'y':
		sc = 1
	else:
		sc = 2
	if s == 'h':
		if num not in lh.keys():
			lh.update({num: sc})
		else:
			lh.update({num: lh[num] + sc})
		if lh[num] >= 2 and lh[num] < 4:
			lh.update({num: 4})
			print(sh, num, mi)
	else:
		if num not in la.keys():
			la.update({num: sc})
		else:
			la.update({num: la[num] + sc})
		if la[num] >= 2 and la[num] < 4:
			la.update({num: 4})
			print(sa, num, mi)
	n -= 1


name1 = input()
name2 = input()
faults = int(input())
s1 = [0] * 100
s2 = [0] * 100
for i in range(faults):
	(time, t, m, card) = input().split()
	time = int(time)
	m = int(m)
	s = s1 if t == 'h' else s2
	if card == 'y':
		if s[m] == 1:
			print(name1 if t == 'h' else name2, m, time)
		s[m] += 1
	elif s[m] < 2:
		print(name1 if t == 'h' else name2, m, time)
		s[m] += 2


from math import *
t1 = input()
t2 = input()
(m1, m2) = ({}, {})
for i in range(int(input())):
	(t, time, n, cor) = input().split()
	n = int(n)
	if time == 'h' and (n not in m1 or m1[n] != 'r') or (time == 'a' and (n not in m2 or m2[n] != 'r')):
		if time == 'h' and (n in m1 and m1[n] == 'y' or cor == 'r') or (time == 'a' and (n in m2 and m2[n] == 'y' or cor == 'r')):
			if time == 'h':
				m1[n] = 'r'
			else:
				m2[n] = 'r'
			print(t1 if time == 'h' else t2, n, t)
		elif time == 'h':
			m1[n] = 'y'
		else:
			m2[n] = 'y'


h_team_name = input()
a_team_name = input()
h = dict()
a1 = dict()
ans = []
for _ in range(int(input())):
	(a, b, c, d) = input().split()
	if d == 'r':
		if b == 'h':
			h.setdefault(c, 0)
			h[c] += 2
			if h[c] == 2 or h[c] == 3:
				ans.append([h_team_name, c, a])
		else:
			a1.setdefault(c, 0)
			a1[c] += 2
			if a1[c] == 2 or a1[c] == 3:
				ans.append([a_team_name, c, a])
	elif b == 'h':
		h.setdefault(c, 0)
		h[c] += 1
		if h[c] == 2:
			ans.append([h_team_name, c, a])
	else:
		a1.setdefault(c, 0)
		a1[c] += 1
		if a1[c] == 2:
			ans.append([a_team_name, c, a])
for i in ans:
	print(*i)


s1 = input()
h = {}
s2 = input()
a = {}
n = int(input())
for i in range(n):
	info = input().split()
	t = int(info[0])
	com = info[1]
	m = int(info[2])
	card = info[3]
	if com == 'h':
		if card == 'y':
			if m not in h:
				h[m] = 'yello_card'
			elif h[m] != 'redcard':
				h[m] = 'redcard'
				print(s1, m, t)
		elif m in h and h[m] != 'redcard' or m not in h:
			h[m] = 'redcard'
			print(s1, m, t)
	elif card == 'y':
		if m not in a:
			a[m] = 'yello_card'
		elif a[m] != 'redcard':
			a[m] = 'redcard'
			print(s2, m, t)
	elif m in a and a[m] != 'redcard' or m not in a:
		a[m] = 'redcard'
		print(s2, m, t)