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: interview

Starter code:

Solutions:
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


"""
Codeforces Contest 281 Div 2 Problem A

Author  : chaotic_iak
Language: Python 3.3.4
"""

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)

################################### NON-SOLUTION STUFF BELOW

def read(mode=2):
    # 0: String
    # 1: List of strings
    # 2: List of integers
    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())

__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
    else:
        if 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

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)


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)


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)

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


    
        

        



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

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)



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

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)


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

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

    
        
        



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)
    
    


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)


from collections import defaultdict
n1, n2 = input(), input()
n = int(input())
#mp = defaultdict(list)
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


homename= input()
awayname= input()
fouls= int(input())

a= []
b=[]
for foul in range(fouls):
    #print(foul)
    #print("hello")
    data= input().split() 
    #print(data)  
    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:
        #print("Hell")
        
        for i in range(len(a)):
            #print(a[i][1:], data[1:])
            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)
            
    #print(a)


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
        else:
            if 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
        else:
            if 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 = list(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]))


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

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

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