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

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
team_home = STRING()
team_away = STRING()
n = INT()
st1 = set()
st2 = set()
d = defaultdict(list)
for i in range(1, 100):
	d[i] = [0, team_home]
d2 = defaultdict(list)
for i in range(1, 100):
	d2[i] = [0, team_away]
res = []
for i in range(n):
	l = input().split()
	t = int(l[0])
	s = l[1]
	num = int(l[2])
	c = l[3]
	if s == 'h' and num not in st1 or (s == 'a' and num not in st2):
		if c == 'r':
			if s == 'h':
				res.append([team_home, num, t])
				st1.add(num)
			else:
				res.append([team_away, num, t])
				st2.add(num)
		elif s == 'h':
			if d[num][0] == 0:
				d[num][0] = 1
			else:
				res.append([team_home, num, t])
				st1.add(num)
		elif d2[num][0] == 0:
			d2[num][0] = 1
		else:
			res.append([team_away, num, t])
			st2.add(num)
for i in res:
	print(*i)


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()


card_dict = dict()
res = []
players = set()
home = input()
other = input()
num = int(input())
for i in range(0, num):
	(m, t, n, c) = input().split(' ')
	m = int(m)
	if t == 'h':
		tname = home
	else:
		tname = other
	if (t, n) not in card_dict:
		card_dict[t, n] = 0
	if c == 'y':
		card_dict[t, n] += 1
	else:
		card_dict[t, n] += 2
	if card_dict[t, n] >= 2 and (t, n) not in players:
		res.append((tname, n, m))
		players.add((t, n))
res.sort(key=lambda x: x[2])
for r in res:
	print(r[0] + ' ' + r[1] + ' ' + str(r[2]))


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())


tn = [input(), input()]
t2i = {'h': 0, 'a': 1}
c2s = {'y': 1, 'r': 2}
st = [[0] * 100, [0] * 100]
for i in range(int(input())):
	(m, t, p, c) = input().split()
	m = int(m)
	t = t2i[t]
	p = int(p)
	s = c2s[c]
	if st[t][p] < 2:
		st[t][p] += s
		if st[t][p] >= 2:
			print(tn[t], p, m)


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)


__author__ = 'DK Wang'
from fractions import gcd
home = input()
away = input()
n = int(input())
time = [[0 for x in range(105)] for x in range(2)]
for x in range(n):
	(t, ha, num, type) = [x for x in input().split()]
	hora = 0 if ha == 'h' else 1
	add = 1 if type == 'y' else 2
	num = int(num)
	if time[hora][num] < 2:
		time[hora][num] += add
		if time[hora][num] >= 2:
			print((home if hora == 0 else away) + ' ' + str(num) + ' ' + t)


__author__ = 'zhan'
names = []
n = 0
team = [[0 for i in range(1, 101)], [0 for i in range(1, 101)]]
team_index = {'h': 0, 'a': 1}
card_index = {'y': 1, 'r': 2}
names.append(input())
names.append(input())
n = int(input())
for i in range(n):
	line = input().split()
	t = line[0]
	tm = line[1]
	number = int(line[2])
	card = line[3]
	team[team_index[tm]][number] += card_index[card]
	if team[team_index[tm]][number] >= 2:
		team[team_index[tm]][number] = -200
		print(names[team_index[tm]] + ' ' + str(number) + ' ' + str(t))


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)


teams = {'h': input(), 'a': input()}
n = int(input())
a = {'h': [], 'a': []}
for i in range(101):
	a['h'].append(0)
	a['a'].append(0)
for i in range(n):
	[time, team, num, color] = input().split()
	num = int(num)
	if a[team][num] >= 2:
		continue
	if color == 'r':
		a[team][num] = 2
	else:
		a[team][num] += 1
	if a[team][num] == 2:
		print(teams[team] + ' ' + str(num) + ' ' + time)


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)


s = input()
t = input()
n = int(input())
lis = []
anh = [0] * 101
ana = [0] * 101
an = []
for i in range(n):
	(n, m, a, b) = map(str, input().split())
	if m == 'h':
		lis.append([int(n), s, int(a), b, m])
	else:
		lis.append([int(n), t, int(a), b, m])
lis.sort()
for i in lis:
	(n, m, a, b, c) = i
	if b == 'y':
		if c == 'h':
			if anh[a] != 2:
				anh[a] += 1
				if anh[a] == 2:
					an.append([m, a, n])
		elif ana[a] != 2:
			ana[a] += 1
			if ana[a] == 2:
				an.append([m, a, n])
	elif b == 'r':
		if c == 'h':
			if anh[a] != 2:
				anh[a] = 2
				an.append([m, a, n])
		elif ana[a] != 2:
			ana[a] = 2
			an.append([m, a, n])
for i in an:
	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()


__author__ = 'Administrator'

def inp():
	return input()
home = inp()
away = inp()
n = int(inp())

class Node:
	time = 0
	team = 0
	num = 0
	color = 0

	def __lt__(self, other):
		return self.time < other.time

	def __init__(self, a, b, c, d):
		self.time = a
		self.team = b
		self.num = c
		self.color = d
i = 0
lt = []
while i < n:
	temp = inp().split(' ')
	o = Node(int(temp[0]), temp[1] == 'h', int(temp[2]), temp[3] == 'r')
	lt.append(o)
	i += 1
a = [0 for i in range(100)]
b = [0 for i in range(100)]
lt.sort()
i = 0
while i < n:
	if lt[i].team:
		if a[lt[i].num] < 2:
			if lt[i].color:
				a[lt[i].num] += 2
			else:
				a[lt[i].num] += 1
			if a[lt[i].num] >= 2:
				print(home, ' ', lt[i].num, ' ', lt[i].time)
			else:
				pass
		else:
			pass
	elif b[lt[i].num] < 2:
		if lt[i].color:
			b[lt[i].num] += 2
		else:
			b[lt[i].num] += 1
		if b[lt[i].num] >= 2:
			print(away, ' ', lt[i].num, ' ', lt[i].time)
		else:
			pass
	else:
		pass
	i += 1


(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)


s1 = input()
s2 = input()
L = {}
L['h'] = s1
L['a'] = s2
n = int(input())
D = {}
F = {}
for i in range(n):
	a = input().split()
	m = int(a[0])
	t = L[a[1]]
	num = int(a[2])
	c = a[3]
	if (t, num) in D:
		continue
	if c == 'r' or (c == 'y' and (t, num) in F):
		D[t, num] = 1
		print(t, num, m)
	else:
		F[t, num] = 1


home = input()
away = input()
n = int(input())
t = []
ha = []
m = []
m2 = []
ha2 = []
for i in range(n):
	(t1, ha1, m1, yr) = map(str, input().strip().split(' '))
	t1 = int(t1)
	m1 = int(m1)
	f2 = 0
	for j in range(len(m2)):
		if m2[j] == m1 and ha2[j] == ha1:
			f2 = 1
			break
	if f2 == 0:
		if yr == 'r':
			m2.append(m1)
			ha2.append(ha1)
			if ha1 == 'h':
				print(home, m1, t1, end=' ')
				print()
			else:
				print(away, m1, t1, end=' ')
				print()
		else:
			f = 0
			for j in range(len(t)):
				if ha[j] == ha1 and m[j] == m1:
					m2.append(m1)
					ha2.append(ha1)
					if ha1 == 'h':
						print(home, m1, t1, end=' ')
						print()
					else:
						print(away, m1, t1, end=' ')
						print()
					del ha[j]
					del m[j]
					del t[j]
					f = 1
					break
			if f == 0:
				t.append(t1)
				ha.append(ha1)
				m.append(m1)


team = {'h': input(), 'a': input()}
n = int(input())
d = {}
lis = []
for x in range(n):
	(t, ha, num, card) = input().split()
	t = int(t)
	num = int(num)
	lis.append((t, ha, num, card))
lis.sort(key=lambda x: x[0])
for x in range(n):
	(t, ha, num, card) = lis[x]
	if (ha, num) not in d:
		d[ha, num] = (t, card)
		if card == 'r':
			print(team[ha], num, t)
	elif d[ha, num][1] == 'y':
		d[ha, num] = (t, 'r')
		print(team[ha], num, 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)


h = input()
a = input()
n = int(input())
t = []
team = []
m = []
card = []
visits = []
x = []
y = []
z = []

def alinput(x):
	x = x.split(' ')
	x[0] = int(x[0])
	x[2] = x[2]
	t.append(x[0])
	if x[1] == 'a':
		x[1] = a
	else:
		x[1] = h
	team.append(x[1])
	m.append(x[2])
	card.append(x[3])
	return (t, m, team, card)
for i in range(0, n):
	alinput(x=input())

def check(i):
	for l in range(0, len(visits)):
		if visits[l] == m[i] + team[i]:
			return False
	return True
for i in range(0, n):
	if check(i):
		if card[i] == 'r':
			x.append(team[i])
			y.append(m[i])
			z.append(t[i])
			visits.append(m[i] + team[i])
		elif card[i] == 'y':
			for j in range(i + 1, n):
				if m[i] == m[j] and team[i] == team[j] and (card[j] == 'y'):
					x.append(team[i])
					y.append(m[i])
					z.append(t[j])
					visits.append(m[j] + team[j])
					break
for i in range(0, len(x)):
	for j in range(i, len(x)):
		if z[j] < z[i]:
			(z[j], z[i]) = (z[i], z[j])
			(x[j], x[i]) = (x[i], x[j])
			(y[j], y[i]) = (y[i], y[j])
for i in range(0, len(x)):
	print(x[i] + ' ' + y[i] + ' ' + str(z[i]))


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


(home, away, n) = (input(), input(), int(input()))
cards = {'h': {}, 'a': {}}
ans = [[] for i in range(91)]
for i in range(n):
	inf = input().split()
	if not inf[2] in cards[inf[1]]:
		cards[inf[1]][inf[2]] = inf[3]
		if inf[3] == 'r':
			ans[int(inf[0])] = [inf[1], inf[2]]
	elif cards[inf[1]][inf[2]] == 'y':
		cards[inf[1]][inf[2]] = 'r'
		ans[int(inf[0])] = [inf[1], inf[2]]
for i in range(1, 91):
	if ans[i]:
		print(home if ans[i][0] == 'h' else away, ans[i][1], i)


a = input()
b = input()
n = int(input())
dic = {}
for i in range(n):
	array = input().split()
	mark = (a if array[1] == 'h' else b) + ' ' + array[2]
	if mark not in dic:
		dic[mark] = 0
	if dic[mark] < 2:
		if array[3] == 'y':
			dic[mark] += 1
		if array[3] == 'r':
			dic[mark] += 2
		if dic[mark] >= 2:
			print(mark, array[0])


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])


h = input()
a = input()
n = int(input())
d = dict()
for i in range(n):
	arr = input().split()
	mark = (h if arr[1] == 'h' else a) + ' ' + arr[2]
	if mark not in d:
		d[mark] = 0
	if d[mark] < 2:
		d[mark] += 1 if arr[3] == 'y' else 2
		if d[mark] >= 2:
			print(mark, arr[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])


team1 = input()
team2 = input()
fouls = int(input())
warn1 = [False] * 100
warn2 = [False] * 100
out1 = [False] * 100
out2 = [False] * 100
warns = []
for i in range(fouls):
	(a, b, c, d) = map(str, input().split(' '))
	(a, c) = (int(a), int(c))
	if b == 'a' and d == 'r' and (out2[c] == False):
		warns.append([team2, c, a])
		out2[c] = True
	elif b == 'h' and d == 'r' and (out1[c] == False):
		warns.append([team1, c, a])
		out1[c] = True
	elif b == 'a' and d == 'y' and warn2[c] and (out2[c] == False):
		warns.append([team2, c, a])
		out2[c] = True
	elif b == 'a' and d == 'y' and (not warn2[c]):
		warn2[c] = True
	elif b == 'h' and d == 'y' and warn1[c] and (out1[c] == False):
		warns.append([team1, c, a])
		out1[c] = True
	elif b == 'h' and d == 'y' and (not warn1[c]):
		warn1[c] = True
warns.sort(key=lambda x: x[2])
for a in warns:
	print(' '.join([str(x) for x in a]))


(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)


from collections import defaultdict

def main():
	ha = {'h': input().strip(), 'a': input().strip()}
	n = int(input().strip())
	d = defaultdict(list)
	for _ in range(n):
		(t, a, player, card) = input().strip().split()
		d[' '.join((ha[a], player))].append((int(t), {'y': 1, 'r': 2}[card]))
	res = []
	for (k, l) in d.items():
		l.sort()
		tot = 0
		for (t, x) in l:
			tot += x
			if tot > 1:
				res.append((t, k))
				break
	res.sort()
	for (t, k) in res:
		print(k, t)
main()


import sys
hom = sys.stdin.readline()[:-1]
away = sys.stdin.readline()[:-1]
numcases = int(sys.stdin.readline())
ht = [0] * 100
at = [0] * 100

def solve(a):
	p = int(a.split()[2])
	t = int(a.split()[0])
	ah = a.split()[1]
	if ah == 'h':
		n = hom
		if ht[p] < 2:
			if a.split()[3] == 'y':
				ht[p] += 1
			else:
				ht[p] = 2
			if ht[p] == 2:
				x = [(t, n, p)]
				return x
	elif at[p] < 2:
		n = away
		if a.split()[3] == 'y':
			at[p] += 1
		else:
			at[p] = 2
		if at[p] == 2:
			x = [(t, n, p)]
			return x
r = []
for casenum in range(1, numcases + 1):
	x = solve(sys.stdin.readline())
	if x != None:
		r = r + x
for i in list(sorted(r)):
	print(i[1], i[2], i[0])


a = input()
b = input()
n = int(input())
home_yellow = set()
away_yellow = set()
home_red = set()
away_red = set()
players = []
for i in range(n):
	q = list(input().split())
	time = int(q[0])
	team = q[1]
	player = int(q[2])
	card = q[3]
	if q[1] == 'h' and player not in home_red:
		if card == 'r':
			players.append([a, player, time])
			home_red.add(player)
		elif player in home_yellow:
			players.append([a, player, time])
			home_red.add(player)
		else:
			home_yellow.add(player)
	if q[1] == 'a' and player not in away_red:
		if card == 'r':
			players.append([b, player, time])
			away_red.add(player)
		elif player in away_yellow:
			players.append([b, player, time])
			away_red.add(player)
		else:
			away_yellow.add(player)
players.sort(key=lambda x: x[2])
for [i, j, k] in players:
	print(str(i) + ' ' + str(j) + ' ' + str(k))


import time, math, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def solve():
	(home, away) = (input(), input())
	n = II()
	dr = {}
	dy = {}
	for i in range(n):
		(mn, tm, no, crd) = [x for x in input().split()]
		(mn, no) = (int(mn), int(no))
		if crd == 'y':
			if dy.get((tm, no), 0) == 0:
				dy[tm, no] = [mn, crd]
			elif (tm, no) not in dr:
				dr[tm, no] = mn
		elif (tm, no) not in dr:
			dr[tm, no] = mn
	li = []
	for (ele1, ele2) in dr:
		if ele1 == 'h':
			li.append([home, ele2, dr[ele1, ele2]])
		else:
			li.append([away, ele2, dr[ele1, ele2]])
	li.sort(key=lambda x: x[2])
	for ele in li:
		print(*ele)
solve()


h = input()
a = input()
n = int(input())
dic = {}
while n > 0:
	n -= 1
	line = input().split()
	t = line[0]
	m = 0
	if line[1].startswith('a'):
		m += 100
	m += int(line[2])
	f = 1
	if line[3].startswith('r'):
		f += 1
	give_red = False
	if m in list(dic.keys()):
		if dic[m] < 2:
			give_red = True
		dic[m] += f
	else:
		dic[m] = f
		if f > 1:
			give_red = True
	if give_red:
		line = ' ' + t
		if m > 100:
			line = a + ' ' + str(m - 100) + line
		else:
			line = h + ' ' + str(m) + line
		print(line)


import sys
home = input()
away = input()
n = int(input())
player_home = [[0, 0] for i in range(100)]
player_away = [[0, 0] for i in range(100)]
info = []
for i in range(n):
	(time, team, no, color) = sys.stdin.readline().split()
	info.append((int(time), team, int(no), color))
for i in range(n):
	(time, team, no, color) = (info[i][0], info[i][1], info[i][2], info[i][3])
	if team == 'a':
		if player_away[no][1] != 0:
			continue
		if color == 'r':
			player_away[no][1] = 1
			print(away, no, time)
		else:
			player_away[no][0] += 1
			if player_away[no][0] == 2:
				player_away[no][1] = 1
				print(away, no, time)
	else:
		if player_home[no][1] != 0:
			continue
		if color == 'r':
			player_home[no][1] = 1
			print(home, no, time)
		else:
			player_home[no][0] += 1
			if player_home[no][0] == 2:
				player_home[no][1] = 1
				print(home, no, time)


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


home = input()
alien = input()
n = int(input())
time = [''] * 91
cards = [[0] * 2 for i in range(100)]
ans = []
l = 0
for i in range(n):
	c = input().split()
	t = int(c[0])
	m = int(c[2])
	if c[1] == 'h':
		time[t] += home + ' ' + str(m) + ' '
		id = 0
	else:
		time[t] += alien + ' ' + str(m) + ' '
		id = 1
	if c[3] == 'y':
		cards[m][id] += 1
	elif cards[m][id] < 2:
		cards[m][id] = 2
	else:
		cards[m][id] += 2
	if cards[m][id] == 2:
		time[t] += str(t)
		ans.append(time[t])
		l += 1
for i in range(l):
	print(ans[i])


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})


def check(a, s):
	i = 0
	while i < len(a):
		if a[i][0] == s[0] and a[i][1] == s[1]:
			return True
		i = i + 1
	return False
A = {}
H = {}
team = {'h': input(), 'a': input()}
n = int(input())
i = 0
a = []
while i < n:
	lists = list(map(str, input().split()))
	if lists[3] == 'r':
		if not check(a, [team[lists[1]], lists[2], lists[0]]):
			a.append([team[lists[1]], lists[2], lists[0]])
	elif lists[1] == 'a':
		if lists[2] in A:
			if not check(a, [team[lists[1]], lists[2], lists[0]]):
				a.append([team['a'], lists[2], lists[0]])
		elif not check(a, [team[lists[1]], lists[2], lists[0]]):
			A[lists[2]] = 1
	elif lists[2] in H:
		if not check(a, [team[lists[1]], lists[2], lists[0]]):
			a.append([team['h'], lists[2], lists[0]])
	elif not check(a, [team[lists[1]], lists[2], lists[0]]):
		H[lists[2]] = 1
	i = i + 1
i = 0
while i < len(a):
	print(' '.join(a[i]))
	i = i + 1


host = input()
guest = input()
n = int(input())
d = {host: {}, guest: {}}
for i in range(n):
	(time, w, num, card) = input().split()
	if w == 'a':
		if d[guest].get(num):
			if d[guest][num] == 'y':
				print(guest, num, time)
			d[guest][num] = 'r'
		else:
			d[guest][num] = card
			if card == 'r':
				print(guest, num, time)
	elif d[host].get(num):
		if d[host][num] == 'y':
			print(host, num, time)
		d[host][num] = 'r'
	else:
		d[host][num] = card
		if card == 'r':
			print(host, num, time)


teams = [input(), input()]
n = int(input())
yel = []
red = []

def convert(t, n):
	global teams
	s = ''
	if t == 'a':
		s += teams[1] + ' '
	else:
		s += teams[0] + ' '
	return s + n
for foul in range(n):
	a = input().split()
	temp = convert(a[1], a[2])
	if a[-1] == 'y':
		if temp in yel:
			yel.remove(temp)
			red.append(temp)
			print(temp + ' ' + a[0])
		elif temp in red:
			continue
		else:
			yel.append(temp)
	elif a[-1] == 'r':
		temp = convert(a[1], a[2])
		if temp in red:
			continue
		else:
			print(temp + ' ' + a[0])
			red.append(temp)


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()
fouls = int(input())
d = {}
for _ in range(fouls):
	s = input()
	(m, t, n, c) = s.split(' ')
	if t == 'h':
		player = home + ' ' + n
	else:
		player = away + ' ' + n
	if player not in d:
		d[player] = 0
	if d[player] < 2:
		d[player] += 1 if c == 'y' else 2
		if d[player] >= 2:
			print(player, m)


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]))


import time
home = input()
guest = input()
home_fall = {str(i): 0 for i in range(1, 100)}
guest_fall = {str(i): 0 for i in range(1, 100)}
n = int(input())
start = time.time()
for i in range(n):
	(t, command, n, card) = (i for i in input().split())
	if command == 'h':
		table = home_fall
	else:
		table = guest_fall
	if card == 'y' and table[n] == 0:
		table[n] = -1
	elif card == 'y' and table[n] == -1 or (card == 'r' and table[n] <= 0):
		table[n] = int(t)
falls = []
for i in home_fall.keys():
	if home_fall[i] > 0:
		falls.append([home, i, home_fall[i]])
for i in guest_fall.keys():
	if guest_fall[i] > 0:
		falls.append([guest, i, guest_fall[i]])
falls = sorted(falls, key=lambda x: x[::-1])
for i in falls:
	s = ''
	for j in i:
		s += str(j) + ' '
	print(s)
finish = time.time()


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)


def main():
	home = input()
	away = input()
	n = int(input())
	fouls = {}
	yellowed = set()
	printed = set()
	for i in range(n):
		(t, team, m, color) = input().split(' ')
		fouls[int(t)] = (team, int(m), color)
	for t in range(1, 91):
		if t not in fouls:
			continue
		(team, m, color) = fouls[t]
		if (m, team) in printed:
			continue
		if color == 'r' or (m, team) in yellowed:
			if team == 'a':
				print(away, m, t)
			else:
				print(home, m, t)
			printed.add((m, team))
		yellowed.add((m, team))
main()


class Command:

	def __init__(self, name):
		self.name = name
		self.d = {}
		self.rC = []

	def add(self, i):
		numb = i[2]
		pl = self.d.get(numb)
		if not pl:
			self.d[numb] = [i[0], i[3]]
			if i[3] == 'r':
				self.rC.append([numb, i[0]])
		elif i[3] == 'y' and pl[1] == 'y':
			self.d[numb] = [i[0], 'r']
			self.rC.append([numb, i[0]])
		elif pl[1] == 'r':
			pass
		else:
			self.d[numb] = [i[0], i[3]]
			if i[3] == 'r':
				self.rC.append([numb, i[0]])

	def getMinRes(self):
		if len(self.rC):
			return [self.name] + self.rC[0]

	def delMinRes(self):
		self.rC.pop(0)

class Game:

	def __init__(self, n1, n2):
		self.n1 = Command(n1)
		self.n2 = Command(n2)

	def parse(self, s):
		l = s.split(' ')
		if l[1] == 'h':
			self.n1.add(l)
		else:
			self.n2.add(l)

	def getRes(self):
		while 1:
			n1 = self.n1.getMinRes()
			n2 = self.n2.getMinRes()
			if n1 and n2:
				if int(n1[2]) < int(n2[2]):
					self.printRes(n1)
					self.n1.delMinRes()
				else:
					self.printRes(n2)
					self.n2.delMinRes()
			elif n1:
				self.printRes(n1)
				self.n1.delMinRes()
			elif n2:
				self.printRes(n2)
				self.n2.delMinRes()
			else:
				break

	def printRes(self, a):
		print('{} {} {}'.format(a[0], a[1], a[2]))
first = input()
sec = input()
g = Game(first, sec)
n = int(input())
s = []
for i in range(n):
	l = input()
	s.append(l)
for i in range(len(s)):
	g.parse(s[i])
g.getRes()


s1 = input()
s2 = input()
n = int(input())
a = []
for _ in range(n):
	(t, u, v, w) = input().split()
	a.append((int(t), u, int(v), w))
a.sort()
xs = set()
ys = set()
for (t, u, v, w) in a:
	if (u, v) in ys:
		continue
	if w == 'y':
		if (u, v) in xs:
			ys.add((u, v))
			print(s1 if u == 'h' else s2, v, t)
		else:
			xs.add((u, v))
	else:
		ys.add((u, v))
		print(s1 if u == 'h' else s2, v, t)


team_1 = input()
team_2 = input()
n = int(input())
ll = []
for i in range(n):
	(mi, te, num, card) = map(str, input().split())
	ll.append((int(mi), te, int(num), card))
ll.sort(key=lambda x: x[0])
team_1_p = [0 for x in range(101)]
team_2_p = [0 for x in range(101)]
(d_1, d_2) = ({}, {})
sol = []
for l in ll:
	if l[1] == 'h':
		if l[3] == 'r':
			if l[2] not in d_1:
				sol.append((team_1, l[2], l[0]))
				d_1[l[2]] = True
		elif l[3] == 'y':
			if team_1_p[l[2]] == 0:
				team_1_p[l[2]] += 1
			elif l[2] not in d_1:
				sol.append((team_1, l[2], l[0]))
				d_1[l[2]] = True
	if l[1] == 'a':
		if l[3] == 'r':
			if l[2] not in d_2:
				sol.append((team_2, l[2], l[0]))
				d_2[l[2]] = True
		elif l[3] == 'y':
			if team_2_p[l[2]] == 0:
				team_2_p[l[2]] += 1
			elif l[2] not in d_2:
				sol.append((team_2, l[2], l[0]))
				d_2[l[2]] = True
for x in sol:
	print(*x)


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


from sys import *
inp = lambda : stdin.readline()

def main():
	h = []
	h.append(inp()[:-1])
	h.append(inp()[:-1])
	n = int(inp())
	r = {}
	y = {}
	rc = []
	for i in range(n):
		(a, b, c, d) = inp().split()
		if d == 'r':
			if (c, b) not in r:
				r[c, b] = (h[0] if b == 'h' else h[1], int(c), int(a))
				rc.append(r[c, b])
		elif (c, b) in y:
			if (c, b) not in r:
				r[c, b] = (h[0] if b == 'h' else h[1], int(c), int(a))
				rc.append(r[c, b])
		else:
			y[c, b] = 1
	rc = sorted(rc, key=lambda x: x[2])
	for i in rc:
		print(i[0], i[1], i[2])
main()


import sys
import math
loc = [sys.stdin.readline().split()[0], sys.stdin.readline().split()[0]]
n = int(sys.stdin.readline())
hg = [{}, {}]
for i in range(n):
	st = sys.stdin.readline().split()
	v = 0
	if st[1] == 'a':
		v = 1
	if st[2] in hg[v]:
		if hg[v][st[2]] == 'r':
			continue
		hg[v][st[2]] = 'r'
	else:
		hg[v][st[2]] = st[3]
	if hg[v][st[2]] == 'r':
		print(loc[v], st[2], st[0])


from collections import defaultdict

def main():
	home = input()
	away = input()
	num_fouls = int(input())
	players = defaultdict(int)
	banned = set()
	for _ in range(num_fouls):
		(minute, team, player, card) = input().split()
		team_name = home if team == 'h' else away
		if card == 'y':
			players[team_name, player] += 1
		else:
			players[team_name, player] = 2
		if (team_name, player) not in banned and players[team_name, player] >= 2:
			print(team_name, player, minute)
			banned.add((team_name, player))
main()


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


hName = input()
aName = input()
n = int(input())
bd = []
for i in range(n):
	s = input().split()
	if s[1] == 'h':
		bd.append({'comm': hName, 'minute': s[0], 'num': s[2], 'card': s[3]})
	else:
		bd.append({'comm': aName, 'minute': s[0], 'num': s[2], 'card': s[3]})
res = []
pared = []
for pl in range(n):
	if [bd[pl]['comm'], bd[pl]['num']] not in pared:
		if bd[pl]['card'] == 'r':
			res.append(bd[pl])
			pared.append([bd[pl]['comm'], bd[pl]['num']])
		else:
			double = False
			for i in range(pl):
				if bd[pl]['num'] == bd[i]['num'] and bd[pl]['comm'] == bd[i]['comm']:
					double = True
			if double:
				res.append(bd[pl])
				pared.append([bd[pl]['comm'], bd[pl]['num']])
for i in range(len(res)):
	print(res[i]['comm'] + ' ' + res[i]['num'] + ' ' + res[i]['minute'])


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)


first_team = str(input())
second_team = str(input())
n = int(input())
deleted = []
a_cards = dict()
h_cards = dict()
for x in range(n):
	[t, team, m, card] = input().split(' ')
	t = int(t)
	team = str(team)
	m = int(m)
	card = str(card)
	if team == 'a':
		team = a_cards
		team_name = second_team
	else:
		team = h_cards
		team_name = first_team
	if m not in team:
		if card == 'y':
			team[m] = 1
		else:
			team[m] = 2
			print(team_name, m, t)
	elif team[m] == 1:
		team[m] = 2
		print(team_name, m, t)
	else:
		continue


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)