Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).

This priority factor will be affected by three types of actions: 

  * 1. "X posted on Y's wall" (15 points), 
  * 2. "X commented on Y's post" (10 points), 
  * 3. "X likes Y's post" (5 points). 



X and Y will be two distinct names. And each action will increase the priority factor between X and Y (and vice versa) by the above value of points (the priority factor between X and Y is the same as the priority factor between Y and X).

You will be given n actions with the above format (without the action number and the number of points), and you have to print all the distinct names in these actions sorted according to the priority factor with you.

Input

The first line contains your name. The second line contains an integer n, which is the number of actions (1 ≤ n ≤ 100). Then n lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All the letters are lowercase. All names in the input will consist of at least 1 letter and at most 10 small Latin letters.

Output

Print m lines, where m is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor, print them in the alphabetical (lexicographical) order.

Note, that you should output all the names that are present in the input data (excluding yourself), even if that person has a zero priority factor.

The lexicographical comparison is performed by the standard "<" operator in modern programming languages. The line a is lexicographically smaller than the line b, if either a is the prefix of b, or if exists such an i (1 ≤ i ≤ min(|a|, |b|)), that ai < bi, and for any j (1 ≤ j < i) aj = bj, where |a| and |b| stand for the lengths of strings a and b correspondently.

Examples

Input

ahmed
3
ahmed posted on fatma's wall
fatma commented on ahmed's post
mona likes ahmed's post


Output

fatma
mona


Input

aba
1
likes likes posted's post


Output

likes
posted

Difficulty: MEDIUM
Tags: String algorithms

Implementation

Starter code:

Solutions:
from collections import defaultdict
(u, p) = (input(), defaultdict(int))
for i in range(int(input())):
	t = input().split()
	(a, k) = (t[0], t[1][0])
	if k == 'p':
		(b, d) = (t[3][:-2], 15)
	elif k == 'c':
		(b, d) = (t[3][:-2], 10)
	else:
		(b, d) = (t[2][:-2], 5)
	if a == u:
		p[b] += d
	elif b == u:
		p[a] += d
	else:
		(p[a], p[b])
r = defaultdict(list)
for (i, j) in p.items():
	r[j].append(i)
for j in r:
	r[j] = '\n'.join(sorted(r[j]))
q = sorted(r.items(), reverse=True)
print('\n'.join((i[1] for i in q)))


from collections import defaultdict
from operator import itemgetter, attrgetter
s = str(input())
n = int(input())
d = defaultdict(int)
for i in range(n):
	string = str(input())
	l = string.split(' ')
	name1 = l[0]
	if len(l) == 5:
		name2 = l[3][0:-2]
	else:
		name2 = l[2][0:-2]
	factor = l[1]
	if factor == 'posted':
		priority = 15
	if factor == 'commented':
		priority = 10
	if factor == 'likes':
		priority = 5
	if name1 == s:
		d[name2] += priority
	elif name2 == s:
		d[name1] += priority
	else:
		if d[name1] == 0:
			d[name1] = 0
		if d[name2] == 0:
			d[name2] = 0
sor = sorted(d.items(), key=lambda item: item[1], reverse=True)
a = []
comp = sor[0][1]
n = len(sor)
i = 0
ans = []
while i < n:
	if sor[i][1] == comp:
		a.append(sor[i][0])
		i += 1
		if i == n:
			a.sort()
			for j in a:
				ans.append(j)
	else:
		a.sort()
		for j in a:
			ans.append(j)
		a = []
		comp = sor[i][1]
for i in ans:
	print(i)


you = input()
n = int(input())
m = dict()
for i in range(n):
	l = list(input().split())
	p = int()
	(x, y) = (str(), str())
	if l[1][0] == 'p':
		p = 15
		x = l[0]
		y = l[3][:len(l[3]) - 2]
	elif l[1][0] == 'c':
		p = 10
		x = l[0]
		y = l[3][:len(l[3]) - 2]
	else:
		p = 5
		x = l[0]
		y = l[2][:len(l[2]) - 2]
	if x not in m:
		m[x] = 0
	if y not in m:
		m[y] = 0
	if x == you:
		m[y] += p
	if y == you:
		m[x] += p
v = list()
for i in m.items():
	if i[0] != you:
		v.append([-i[1], i[0]])
v.sort()
for i in v:
	print(i[1])


myName = input()
actions = int(input())
factors = {'commented': 10, 'posted': 15, 'likes': 5}
dict = {}
for i in range(actions):
	action = input().split()
	if action[0] == myName:
		dict[action[-2].replace("'s", '')] = dict.get(action[-2].replace("'s", ''), 0) + factors[action[1]]
	elif action[-2].replace("'s", '') == myName:
		dict[action[0]] = dict.get(action[0], 0) + factors[action[1]]
	else:
		dict[action[0]] = dict.get(action[0], 0)
		dict[action[-2].replace("'s", '')] = dict.get(action[-2].replace("'s", ''), 0)
sortedDict = sorted(dict, key=lambda k: (-dict[k], k))
for i in sortedDict:
	print(i)


me = input()
n = int(input())
names = {}
point = {'posted': 15, 'commented': 10, 'likes': 5}
for _ in range(n):
	data = input().split()
	if data[1] == 'likes':
		b = data[2][:-2]
	else:
		b = data[3][:-2]
	if data[0] == me and b != me:
		if b in names:
			names[b] += point[data[1]]
		else:
			names[b] = point[data[1]]
	elif data[0] != me and b == me:
		if data[0] in names:
			names[data[0]] += point[data[1]]
		else:
			names[data[0]] = point[data[1]]
	elif data[0] != me and b != me:
		if data[0] not in names:
			names[data[0]] = 0
		if b not in names:
			names[b] = 0
prior = []
for i in names:
	prior.append((i, names[i]))
prior = sorted(prior, key=lambda x: (-x[1], x[0]))
for i in prior:
	print(i[0])


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
key = input()
n = Int()
score = defaultdict(int)
for _ in range(n):
	action = input().split()
	if action[1] == 'posted':
		(p1, p2) = (action[0], action[3][:-2])
		if p1 == key:
			score[p2] += 15
		elif p2 == key:
			score[p1] += 15
		else:
			score[p1] += 0
			score[p2] += 0
	if action[1] == 'commented':
		(p1, p2) = (action[0], action[3][:-2])
		if p1 == key:
			score[p2] += 10
		elif p2 == key:
			score[p1] += 10
		else:
			score[p1] += 0
			score[p2] += 0
	if action[1] == 'likes':
		(p1, p2) = (action[0], action[2][:-2])
		if p1 == key:
			score[p2] += 5
		elif p2 == key:
			score[p1] += 5
		else:
			score[p1] += 0
			score[p2] += 0
score_based = defaultdict(list)
for i in score:
	score_based[score[i]].append(i)
for i in sorted(score_based, reverse=True):
	for ele in sorted(score_based[i]):
		print(ele)


me = input()
d = {}
for _ in range(int(input())):
	s = input().split("'")[0].split()
	(x, y) = (s[0], s[-1])
	if x not in d:
		d[x] = 0
	if y not in d:
		d[y] = 0
	other = None
	if x == me:
		other = y
	elif y == me:
		other = x
	if other:
		if len(s) == 3:
			d[other] -= 1
		elif s[1] == 'posted':
			d[other] -= 3
		else:
			d[other] -= 2
end = [(d[k], k) for k in d if k != me]
end.sort()
for e in end:
	print(e[1])


import re
patts = ["(.*) posted on (.*)'s wall", "(.*) commented on (.*)'s post", "(.*) likes (.*)'s post"]
points = [15, 10, 5]
d = {}
self = input()
n = int(input())
for _ in range(n):
	s = input()
	for i in range(3):
		mtch = re.match(patts[i], s)
		if mtch:
			(a, b) = (mtch.group(1), mtch.group(2))
			if a == self:
				if b not in d:
					d[b] = points[i]
				else:
					d[b] += points[i]
			elif b == self:
				if a not in d:
					d[a] = points[i]
				else:
					d[a] += points[i]
			else:
				if b not in d:
					d[b] = 0
				if a not in d:
					d[a] = 0
			break
d = list(d.items())
d.sort(key=lambda x: (-x[1], x[0]))
print(*map(lambda x: x[0], filter(lambda x: x[0] != self, d)), sep='\n')


data = {'posted': 15, 'commented': 10, 'likes': 5}
name = input()
lst = []
s = []
appear = []
for i in range(int(input())):
	x = input().split()
	if name in x or name + "'s" in x:
		if x[0] == name:
			y = x[-2][:len(x[-2]) - 2]
		else:
			y = x[0]
		if y not in appear:
			appear.append(y)
			s.append(data[x[1]])
		else:
			s[appear.index(y)] += data[x[1]]
	else:
		lst.append(x[0])
		lst.append(x[-2][:len(x[-2]) - 2])
l = len(appear)
while l > 0:
	m = max(s)
	c = s.count(m)
	temp = []
	if c > 1:
		for i in range(c):
			f = s.index(m)
			temp.append(appear[f])
			s[f] = 0
		temp.sort()
		l -= c
		for i in temp:
			print(i)
	else:
		f = s.index(m)
		print(appear[f])
		s[f] = 0
		l -= 1
lst = list(set(lst))
lst.sort()
for i in lst:
	if i not in appear:
		print(i)


name = input()
n = int(input())
priority = {}
nomes = []
for i in range(n):
	txt = input().split()
	a = txt[0]
	b = txt[3][:-2]
	action = txt[1]
	if action == 'likes':
		b = txt[2][:-2]
	if b not in priority and b != name:
		priority[b] = 0
	if a not in priority and a != name:
		priority[a] = 0
	if a == name:
		if action == 'posted':
			priority[b] += 15
		elif action == 'commented':
			priority[b] += 10
		elif action == 'likes':
			priority[b] += 5
	elif b == name:
		if action == 'posted':
			priority[a] += 15
		elif action == 'commented':
			priority[a] += 10
		elif action == 'likes':
			priority[a] += 5
for ele in priority:
	nomes.append((ele, priority[ele]))
nomes = sorted(nomes, key=lambda element: (-element[1], element[0]))
for i in nomes:
	print(i[0])


name = input()
lines = int(input())
points = {'posted': 15, 'commented': 10, 'likes': 5}
people = {}
for _ in range(lines):
	line = input().strip().split()
	name1 = line[0]
	name2 = ''
	command = line[1]
	if command == 'likes':
		name2 = line[2][:-2]
	else:
		name2 = line[3][:-2]
	if name2 == name:
		(name1, name2) = (name2, name1)
	if name1 != name and (not name1 in people):
		people[name1] = 0
	if name2 != name and (not name2 in people):
		people[name2] = 0
	if name1 == name:
		people[name2] += points[command]
people_list = [(-people[x], x) for x in people]
people_list.sort()
for (x, y) in people_list:
	print(y)


me = input()
n = int(input())
cnt = {}
for i in range(n):
	inp = input().split()
	(a, b, act) = (inp[0], inp[-2][:-2], inp[1])
	if a not in cnt.keys():
		cnt[a] = 0
	if b not in cnt.keys():
		cnt[b] = 0
	sc = 0
	if a != me and b != me:
		continue
	if act == 'posted':
		sc = 15
	elif act == 'commented':
		sc = 10
	elif act == 'likes':
		sc = 5
	cnt[a] += sc
	cnt[b] += sc
lst = list(cnt.keys())
lst = sorted(lst, key=lambda x: (-cnt[x], x))
for name in lst:
	if name == me:
		continue
	print(name)


name = input()
n = int(input())
d = dict()
action = [' likes ', ' commented on ', ' posted on ']
for _ in range(n):
	s = input()
	for i in range(3):
		if action[i] in s:
			s = s.split(action[i])
			break
	(a, b) = s
	b = b.split("'")[0]
	s = [a, b]
	if name in s:
		a = s[1 - s.index(name)]
		d[a] = d.get(a, 0) - (i + 1) * 5
	else:
		d[a] = d.get(a, 0)
		d[b] = d.get(b, 0)
ans = [[d[i], i] for i in d]
ans.sort(key=lambda x: (x[0], x[1]))
for i in ans:
	print(i[1])


import re
d = dict()
special = input()
n = int(input())
for i in range(n):
	line = list(input().split())
	first = line[0]
	order = line[1]
	second = line[-2]
	second = re.search("(.+)[']", second)[1]
	if first == special or second == special:
		if order == 'posted':
			d[first] = d.get(first, 0) + 15
			d[second] = d.get(second, 0) + 15
		elif order == 'commented':
			d[first] = d.get(first, 0) + 10
			d[second] = d.get(second, 0) + 10
		else:
			d[first] = d.get(first, 0) + 5
			d[second] = d.get(second, 0) + 5
	else:
		d[first] = d.get(first, 0)
		d[second] = d.get(second, 0)
d = sorted(d.items(), key=lambda x: (-x[1], x[0]))
zero = []
for i in d:
	if i[0] != special and i[1] != 0:
		print(i[0])
	elif i[1] == 0:
		zero.append(i[0])
zero.sort()
for i in zero:
	print(i)


def getPriority(action, name):
	if action[1] == 'likes':
		p1 = action[0]
		p2 = action[2][:-2]
		return (p1, p2, 5 if name == p1 or name == p2 else 0)
	else:
		p1 = action[0]
		p2 = action[3][:-2]
		if action[1] == 'commented':
			return (p1, p2, 10 if name == p1 or name == p2 else 0)
		else:
			return (p1, p2, 15 if name == p1 or name == p2 else 0)

def containsName(name, action):
	return action[0] == name or action[2][:-2] == name or action[3][:-2] == name
name = input()
n = int(input())
actions = []
factor = {}
for i in range(n):
	actions.append(input().split())
for action in actions:
	prio = getPriority(action, name)
	if prio[0] != name:
		factor[prio[0]] = factor.get(prio[0], 0) + prio[2]
	if prio[1] != name:
		factor[prio[1]] = factor.get(prio[1], 0) + prio[2]
print('\n'.join([friend[0] for friend in sorted(factor.items(), key=lambda kv: (-kv[1], kv[0]))]))


def face(name, arr):
	points = {'posted': 15, 'commented': 10, 'likes': 5}
	dct = dict()
	for i in arr:
		c = 3
		if i[1] == 'likes':
			c = 2
		x = i[c][:len(i[c]) - 2]
		if i[0] == name or x == name:
			if i[0] == name:
				dct[x] = dct.get(x, 0) + points[i[1]]
			else:
				dct[i[0]] = dct.get(i[0], 0) + points[i[1]]
		else:
			dct[i[0]] = dct.get(i[0], 0)
			dct[x] = dct.get(x, 0)
	if name in dct.keys():
		dct.pop(name)
	lst = [[x, y] for (x, y) in dct.items()]
	lst = sorted(lst, key=lambda s: s[0])
	lst = sorted(lst, key=lambda s: s[1], reverse=True)
	for (x, y) in lst:
		print(x)
	return ''
a = input()
blanck = []
for i in range(int(input())):
	lst = list(map(str, input().strip().split()))
	blanck.append(lst)
print(face(a, blanck))


import sys
input = sys.stdin.readline
name = input().strip()
n = int(input())
points = {'posted': 15, 'commented': 10, 'likes': 5}
priority = {}
for i in range(n):
	line = input().split()
	X = line[0]
	Y = line[-2][:-2]
	plus = points[line[1]]
	if X == name:
		Y_priority = priority.get(Y, 0)
		priority[Y] = Y_priority + plus
	elif Y == name:
		X_priority = priority.get(X, 0)
		priority[X] = X_priority + plus
	else:
		X_priority = priority.get(X, 0)
		Y_priority = priority.get(Y, 0)
		priority[X] = X_priority
		priority[Y] = Y_priority
L = []
for x in priority:
	L.append((-priority[x], x))
L = sorted(L)
for (x, name) in L:
	print(name)


myname = input()
n = int(input())
priority = {}

def func(action):
	if action[1] == 'posted':
		k = 15
	else:
		k = 10
	if action[1] == 'posted' or action[1] == 'commented':
		(name2, s) = [x for x in action[3].split("'")]
		if action[0] == myname or name2 == myname:
			if action[0] in priority:
				priority[action[0]] += k
			else:
				priority[action[0]] = k
			if name2 in priority:
				priority[name2] += k
			else:
				priority[name2] = k
		else:
			if action[0] not in priority:
				priority[action[0]] = 0
			if name2 not in priority:
				priority[name2] = 0
	else:
		(name2, s) = [x for x in action[2].split("'")]
		if action[0] == myname or name2 == myname:
			if action[0] in priority:
				priority[action[0]] += 5
			else:
				priority[action[0]] = 5
			if name2 in priority:
				priority[name2] += 5
			else:
				priority[name2] = 5
		else:
			if action[0] not in priority:
				priority[action[0]] = 0
			if name2 not in priority:
				priority[name2] = 0
while n > 0:
	n -= 1
	action = [x for x in input().split(' ')]
	func(action)
try:
	priority.pop(myname)
except KeyError as e:
	pass
k = []
v = []
for (key, val) in priority.items():
	k.append(key)
	v.append(val)
n = len(v)
for i in range(n - 1):
	swapped = False
	for j in range(n - 1 - i):
		if v[j] < v[j + 1]:
			(v[j], v[j + 1]) = (v[j + 1], v[j])
			(k[j], k[j + 1]) = (k[j + 1], k[j])
			swapped = True
		elif v[j] == v[j + 1]:
			if k[j] > k[j + 1]:
				(v[j], v[j + 1]) = (v[j + 1], v[j])
				(k[j], k[j + 1]) = (k[j + 1], k[j])
				swapped = True
	if not swapped:
		break
for item in k:
	print(item)


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

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

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

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def solve():
	my_name = input()
	names = {}
	for _ in range(int(input())):
		s = input().split("'s")
		s = ''.join(s)
		s = s.split(' ')
		points = 0
		if 'posted' == s[1]:
			(n1, n2) = (s[0], s[3])
			points = 15
		elif 'commented' == s[1]:
			(n1, n2) = (s[0], s[3])
			points = 10
		else:
			(n1, n2) = (s[0], s[2])
			points = 5
		if n1 == my_name or n2 == my_name:
			if n1 != my_name:
				try:
					names[n1] += points
				except KeyError:
					names[n1] = points
			if n2 != my_name:
				try:
					names[n2] += points
				except KeyError:
					names[n2] = points
		else:
			try:
				names[n1] += 0
			except KeyError:
				names[n1] = 0
			try:
				names[n2] += 0
			except KeyError:
				names[n2] = 0
	names = sort_dict(names)
	ans = []
	i = 0
	while i < len(names):
		(u, v) = names[i]
		j = i + 1
		temp = [u]
		while j < len(names) and v == names[j][1]:
			temp.append(names[j][0])
			j += 1
		i = j
		temp.sort()
		for t in temp:
			ans.append(t)
	for i in ans:
		print(i)
t = 1
for _ in range(t):
	solve()


from collections import defaultdict
import functools

def customsort(a, b):
	if a[0] == b[0]:
		return a[1] > b[1]
	else:
		return a[0] > b[0]
a = input()
n = int(input())
names = defaultdict(lambda : 0)
for i in range(n):
	(*l,) = map(str, input().split())
	pt = 0
	if l[1] == 'posted':
		pt = 15
	elif l[1] == 'commented':
		pt = 10
	else:
		pt = 5
	if not (l[0] == a or l[-2][:-2] == a):
		pt = 0
	names[l[0]] += pt
	names[l[-2][:-2]] += pt
lst = [[100000 - names[k], k] for k in names.keys() if k != a]
lst.sort()
for (i, j) in lst:
	print(j)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
nam = is1()
d = {}
for _ in range(ii1()):
	s = is1()
	if ' commented ' in s:
		s = s.split()
		if nam in [s[0], s[3][:-2]]:
			d.setdefault(s[0], [0])[0] += 10
			d.setdefault(s[3][:-2], [0])[0] += 10
		else:
			d.setdefault(s[0], [0])
			d.setdefault(s[3][:-2], [0])
	elif ' likes ' in s:
		s = s.split()
		if nam in [s[0], s[2][:-2]]:
			d.setdefault(s[0], [0])[0] += 5
			d.setdefault(s[2][:-2], [0])[0] += 5
		else:
			d.setdefault(s[0], [0])
			d.setdefault(s[2][:-2], [0])
	else:
		s = s.split()
		if nam in [s[0], s[3][:-2]]:
			d.setdefault(s[0], [0])[0] += 15
			d.setdefault(s[3][:-2], [0])[0] += 15
		else:
			d.setdefault(s[0], [0])
			d.setdefault(s[3][:-2], [0])
res = []
for i in d:
	if i != nam:
		res.append([d[i][0], i])
res.sort(key=lambda x: (-x[0], x[1]))
for i in res:
	print(i[1])


a = input()
n = int(input())
d = []
for i in range(n):
	s = list(map(str, input().split()))
	if s[1] == 'likes':
		s[2] = s[2][:len(s[2]) - 2]
	else:
		s[3] = s[3][:len(s[3]) - 2]
	d.append(s)
dic = {}
for i in d:
	dic[i[0]] = 0
	if i[1] == 'likes':
		dic[i[2]] = 0
	else:
		dic[i[3]] = 0
if a in dic:
	dic.pop(a)
for i in d:
	if a in i:
		if i[1] == 'likes':
			if i[0] == a:
				dic[i[2]] += 5
			else:
				dic[i[0]] += 5
		elif i[1] == 'commented':
			if i[0] == a:
				dic[i[3]] += 10
			else:
				dic[i[0]] += 10
		elif i[0] == a:
			dic[i[3]] += 15
		else:
			dic[i[0]] += 15
res = []
for i in dic:
	res.append([dic[i], i])
res = sorted(res, reverse=True)
c = []
for i in range(len(res) - 1):
	if res[i][0] > res[i + 1][0]:
		print(res[i][1])
		c.sort()
		for i in c:
			print(i)
		c = []
	else:
		c.append(res[i][1])
c.append(res[len(res) - 1][1])
c.sort()
for i in c:
	print(i)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

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

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 998244353

def comp(a, b):
	if a[0] == b[0]:
		if a[1] > b[1]:
			return -1
		else:
			return 1
	else:
		return -b[0] + a[0]
from functools import cmp_to_key

def solve(case):
	s = inp()
	n = int(inp())
	score = {}
	for i in range(n):
		temp = stringlis()
		a = temp[0]
		b = temp[-2]
		b = b[:len(b) - 2]
		curr = 0
		if 'likes' in temp and len(temp) == 4:
			curr += 5
		elif 'post' in temp:
			curr += 10
		else:
			curr += 15
		if a not in score:
			score[a] = 0
		if b not in score:
			score[b] = 0
		if a == s:
			score[b] += curr
		if b == s:
			score[a] += curr
	a = []
	for i in score:
		a.append((score[i], i))
	a = sorted(a, key=cmp_to_key(comp), reverse=True)
	for i in range(len(a)):
		if a[i][1] == s:
			continue
		print(a[i][1])
testcase(1)


from sys import *
from math import *
from functools import cmp_to_key

def main():
	d = {}
	n = input()
	k = int(input())
	for i in range(k):
		data = list(map(str, input().split()))
		x = data[0]
		y = data[-2][:-2]
		com = data[1]
		p = 0
		if com == 'posted':
			p = 15
		elif com == 'commented':
			p = 10
		elif com == 'likes':
			p = 5
		if d.get(x) == None:
			d[x] = 0
		if d.get(y) == None:
			d[y] = 0
		if x == n or y == n:
			d[x] += p
			d[y] += p
		else:
			d[x] += 0
			d[y] += 0
	r = sorted(d.items(), key=lambda d: (-d[1], d[0]))
	for i in r:
		if i[0] != n:
			print(i[0])
main()


def update(X, Y, dic, points):
	flag = you in (X, Y)
	if X in dic:
		if flag:
			dic[X] += points
	else:
		dic[X] = points * flag
	if Y in dic:
		if flag:
			dic[Y] += points
	else:
		dic[Y] = points * flag
you = input()
n = int(input())
priority = {}
for i in range(n):
	action = input()
	X = action.split()[0]
	if 'posted' == action.split()[1]:
		Y = action.split()[3][:-2]
		update(X, Y, priority, 15)
	if 'commented' == action.split()[1]:
		Y = action.split()[3][:-2]
		update(X, Y, priority, 10)
	if 'likes' == action.split()[1]:
		Y = action.split()[2][:-2]
		update(X, Y, priority, 5)
if you in priority:
	del priority[you]
names = list(priority.keys())
for i in range(len(names) - 1):
	for j in range(len(names) - 1, i, -1):
		if priority[names[j - 1]] < priority[names[j]] or (priority[names[j - 1]] == priority[names[j]] and names[j - 1] > names[j]):
			temp = names[j]
			names[j] = names[j - 1]
			names[j - 1] = temp
for name in names:
	print(name)


x = input()
n = int(input())
m = set()
al = []
for i in range(n):
	s = list(map(str, input().split()))
	m.add(s[0])
	m.add(s[len(s) - 2][:len(s[len(s) - 2]) - 2])
	al.append(s)
l = {}
for i in m:
	l[i] = 0
for i in al:
	if len(i) == 5 and i[4] == 'wall' and (i[0] == x or i[3][:len(i[3]) - 2] == x):
		l[i[0]] += 15
		l[i[3][:len(i[3]) - 2]] += 15
	elif len(i) == 5 and i[4] == 'post' and (i[0] == x or i[3][:len(i[3]) - 2] == x):
		l[i[0]] += 10
		l[i[3][:len(i[3]) - 2]] += 10
	elif len(i) == 4 and (i[0] == x or i[2][:len(i[2]) - 2] == x):
		l[i[0]] += 5
		l[i[2][:len(i[2]) - 2]] += 5
X = [[] for i in range(1505)]
for i in l.keys():
	X[l[i]].append(i)
for i in range(1504, -1, -1):
	for j in sorted(X[i]):
		if j != x:
			print(j)


(my_name, friendship_rate) = (input(), {})
for _ in range(int(input())):
	event = input().split()
	(name1, action) = (event[0], event[1])
	if action == 'likes':
		name2 = event[2][:-2]
		points = 5
	else:
		name2 = event[3][:-2]
		points = 15 if action == 'posted' else 10
	if name1 != my_name:
		(name1, name2) = (name2, name1)
	if name1 == my_name:
		if name2 in friendship_rate:
			friendship_rate[name2] += points
		else:
			friendship_rate[name2] = points
	else:
		for name in (name1, name2):
			if name not in friendship_rate:
				friendship_rate[name] = 0
for (name, rate) in sorted(friendship_rate.items(), key=lambda x: (-x[1], x[0])):
	print(name)


def solve():
	d = {}
	myname = input()
	n = int(input())
	ad = {'posted': 15, 'commented': 10, 'likes': 5}
	for _ in range(n):
		lst = input().split()
		x = lst[0]
		action = lst[1]
		if action == 'likes':
			y = lst[2][:-2]
		else:
			y = lst[3][:-2]
		if y == myname:
			if x in d:
				d[x] += ad[action]
			else:
				d[x] = ad[action]
		elif x == myname:
			if y in d:
				d[y] += ad[action]
			else:
				d[y] = ad[action]
		else:
			if x not in d:
				d[x] = 0
			if y not in d:
				d[y] = 0
	d2 = {}
	for (k, v) in d.items():
		if v in d2:
			d2[v].append(k)
		else:
			d2[v] = [k]
	d3 = sorted(d2, reverse=True)
	for k in d3:
		for name in sorted(d2[k]):
			print(name)
solve()


from collections import defaultdict
s = str(input())
n = int(input())
dictt = {'posted': 15, 'commented': 10, 'likes': 5}
friends = defaultdict(int)
for _ in range(n):
	st = list(str(input()).split(' '))
	if st[1] == 'likes':
		st.insert(2, 'ww')
	if st[0] == s:
		friends[st[3][0:-2]] += dictt[st[1]]
	elif st[3][0:-2] == s:
		friends[st[0]] += dictt[st[1]]
	else:
		friends[st[0]] += 0
		friends[st[3][0:-2]] += 0
friends = {k: v for (k, v) in sorted(friends.items(), key=lambda item: (-item[1], item[0]))}
for i in friends:
	print(i)


def main():
	nm = input()
	bd = set()
	d = dict()
	n = int(input())
	f = {'posted': 15, 'commented': 10, 'likes': 5}
	for i in range(n):
		p = input().split()
		if len(p) == 5:
			(n1, do, _, n2, _) = p
		else:
			(n1, do, n2, _) = p
		n2 = n2[:-2]
		if n1 not in bd:
			bd.add(n1)
			d[n1] = 0
		if n2 not in bd:
			bd.add(n2)
			d[n2] = 0
		if n1 == nm:
			d[n2] += f[do]
		if n2 == nm:
			d[n1] += f[do]
	bd -= {nm}
	a = []
	for i in bd:
		a.append([d[i], i])
	a = sorted(a, key=lambda x: (-x[0], x[1]))
	for i in a:
		print(i[1])
main()


from collections import *
from operator import *
(myname, n, mem) = (input(), int(input()), defaultdict(int))
for i in range(n):
	(s, val) = (input().split(), 0)
	(x, y) = (s[0], s[3][:-2])
	if s[1] == 'posted':
		val = 15
	elif s[1] == 'commented':
		val = 10
	else:
		val = 5
		y = s[2][:-2]
	if x == myname:
		mem[y] += val
	elif y == myname:
		mem[x] += val
	else:
		if not mem[x]:
			mem[x] = 0
		if not mem[y]:
			mem[y] = 0
ans = sorted(list(mem.items()), reverse=True, key=itemgetter(1, 0))
mem = defaultdict(list)
for (i, j) in ans:
	mem[j].append(i)
for (i, j) in mem.items():
	for k in j[::-1]:
		print(k)


name = input()
n = int(input())
d = dict()
for _ in range(n):
	s = input()
	t = s.split()
	(a, b) = (t[0], t[-2][:-2])
	typ = 15 if s.count('posted on') else 10 if s.count('commented on') else 5
	if b not in d.keys():
		d[b] = 0
	if a not in d.keys():
		d[a] = 0
	if a == name:
		d[b] += typ
	elif b == name:
		d[a] += typ
vl = []
for e in d.keys():
	vl.append([-d[e], e])
vl.sort()
for e in vl:
	if e[1] == name:
		continue
	print(e[1])


import sys

def read(func=int):
	return func(sys.stdin.readline().strip())

def readList(func=int):
	return list(map(func, sys.stdin.readline().split()))
name = read(str)
n = read()
priority = {}
actions_value = {'posted': 15, 'commented': 10, 'likes': 5}
for _ in range(n):
	action = readList(str)
	name1 = action[0]
	name2 = action[-2][:-2]
	if name1 == name:
		priority[name2] = priority.get(name2, 0) + actions_value[action[1]]
	elif name2 == name:
		priority[name1] = priority.get(name1, 0) + actions_value[action[1]]
	else:
		priority[name1] = priority.get(name1, 0) + 0
		priority[name2] = priority.get(name2, 0) + 0
names = list(priority)
names.sort()
names.sort(key=lambda x: priority.get(x, 0), reverse=True)
for name in names:
	print(name)


from collections import defaultdict
name = input()
temp = name + "'s"
n = int(input())
dic = defaultdict(int)
for i in range(n):
	s = list(input().split())
	if s[1] == 'posted':
		if s[0] == name:
			dic[s[3][:len(s[3]) - 2]] += 15
		elif s[3] == temp:
			dic[s[0]] += 15
		else:
			dic[s[0]] += 0
			dic[s[3][:len(s[3]) - 2]] += 0
	elif s[1] == 'commented':
		if s[0] == name:
			dic[s[3][:len(s[3]) - 2]] += 10
		elif s[3] == temp:
			dic[s[0]] += 10
		else:
			dic[s[0]] += 0
			dic[s[3][:len(s[3]) - 2]] += 0
	elif s[1] == 'likes':
		if s[0] == name:
			dic[s[2][:len(s[2]) - 2]] += 5
		elif s[2] == temp:
			dic[s[0]] += 5
		else:
			dic[s[0]] += 0
			dic[s[2][:len(s[2]) - 2]] += 0
ans = []
for i in dic:
	ans.append([i, dic[i]])
ans = sorted(ans, reverse=True, key=lambda x: x[1])
j = 0
for i in range(len(ans)):
	if i + 1 < len(ans) and ans[j][1] != ans[i + 1][1]:
		ans[j:i + 1] = sorted(ans[j:i + 1], key=lambda x: x[0])
		j = i + 1
	if i + 1 == len(ans):
		ans[j:i + 1] = sorted(ans[j:i + 1], key=lambda x: x[0])
for i in range(len(ans)):
	print(ans[i][0])


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
from collections import defaultdict
name = input()
n = iinput()
dict = defaultdict(int)

def changes(dict, name1, name2, val):
	if name1 == name:
		dict[name2] += val
	elif name2 == name:
		dict[name1] += val
	else:
		dict[name1] += 0
		dict[name2] += 0

def get_names(A):
	return (A[0], A[-2][:-2])
for _ in range(n):
	A = list(input().split())
	(name1, name2) = get_names(A)
	if A[1] == 'posted':
		changes(dict, name1, name2, 15)
	if A[1] == 'commented':
		changes(dict, name1, name2, 10)
	if A[1] == 'likes':
		changes(dict, name1, name2, 5)
lists = list(dict.items())
lists.sort(key=lambda x: (-x[1], x[0]))
for l in lists:
	print(l[0])


u = input
a = str(u())
n = int(u())
d1 = dict()
while n:
	f = 1
	n -= 1
	l = u().split()
	(x, y) = (l[0], '')
	if l[1] == 'likes':
		y = l[2][:-2]
	else:
		y = l[3][:-2]
	q = ''
	if a in {x, y}:
		p = a
		q = ({x, y} - {a}).pop()
		if q not in d1:
			d1[q] = 0
	else:
		f = 0
		if x not in d1:
			d1[x] = 0
		if y not in d1:
			d1[y] = 0
	if f:
		if l[1] == 'likes':
			d1[q] += 5
		if l[1] == 'commented':
			d1[q] += 10
		if l[1] == 'posted':
			d1[q] += 15
w = [e[1] for e in sorted(((-v, k) for (k, v) in d1.items()))]
for k in w:
	print(k)


acttopoint = {'posted': 15, 'commented': 10, 'likes': 5}

def addrait(rait, item, point):
	if item in rait:
		rait[item] += point
	else:
		rait[item] = point

def getnames(s):
	end = s.find(' ')
	fname = s[:end]
	beg = s.find(' ', end + 1)
	point = acttopoint[s[end + 1:beg]]
	if point > 5:
		beg = s.find(' ', beg + 1)
	end = s.find("'")
	sname = s[beg + 1:end]
	return (fname, sname, int(point))
myname = input()
n = int(input())
v = []
for c in range(n):
	v.append(getnames(input()))
rait = dict()
for c in v:
	tar = -1
	if c[0] == myname:
		tar = 1
	elif c[1] == myname:
		tar = 0
	if tar == -1:
		addrait(rait, c[0], 0)
		addrait(rait, c[1], 0)
		continue
	addrait(rait, c[tar], c[2])
v = list(rait.items())
v.sort(key=lambda x: (-x[1], x[0]))
for c in v:
	print(c[0])


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def cmp(a, b):
	if a[1] > b[1]:
		return -1
	if a[1] < b[1]:
		return 1
	if a[0][0] < b[0][0]:
		return -1
	return 1
name = data()
n = int(data())
score = dd(int)
for i in range(n):
	arr = sl()
	if arr[1] == 'posted':
		temp = arr[3][:len(arr[3]) - 2]
		if temp == name:
			score[arr[0], temp] += 15
		elif arr[0] == name:
			score[temp, arr[0]] += 15
		else:
			score[temp, name] += 0
			score[arr[0], name] += 0
	if arr[1] == 'commented':
		temp = arr[3][:len(arr[3]) - 2]
		if temp == name:
			score[arr[0], temp] += 10
		elif arr[0] == name:
			score[temp, arr[0]] += 10
		else:
			score[temp, name] += 0
			score[arr[0], name] += 0
	if arr[1] == 'likes':
		temp = arr[2][:len(arr[2]) - 2]
		if temp == name:
			score[arr[0], temp] += 5
		elif arr[0] == name:
			score[temp, arr[0]] += 5
		else:
			score[temp, name] += 0
			score[arr[0], name] += 0
score = sorted(score.items(), key=cmp_to_key(cmp))
for i in score:
	if i[0][1] == name:
		out(i[0][0])


from collections import defaultdict
(myname, p) = (input(), defaultdict(int))
for i in range(int(input())):
	action = input().split()
	(name1, operation) = (action[0], action[1][0])
	if operation == 'p':
		(name2, priority) = (action[3][:-2], 15)
	elif operation == 'c':
		(name2, priority) = (action[3][:-2], 10)
	else:
		(name2, priority) = (action[2][:-2], 5)
	if name1 == myname:
		p[name2] += priority
	elif name2 == myname:
		p[name1] += priority
	else:
		(p[name1], p[name2])
r = defaultdict(list)
for (i, j) in p.items():
	r[j].append(i)
for j in r:
	r[j] = '\n'.join(sorted(r[j]))
q = sorted(r.items(), reverse=True)
print('\n'.join((i[1] for i in q)))


n = input()
t = int(input())
l = []
for i in range(t):
	l.append(input())
result = {n: 0}
for j in l:
	act = j.split()
	if act[0] not in result:
		result[act[0]] = 0
	if act[-2][:-2] not in result:
		result[act[-2][:-2]] = 0
	if act[0] == n or act[-2][:-2] == n:
		score = 0
		if act[1] == 'posted':
			score += 15
		elif act[1] == 'commented':
			score += 10
		else:
			score += 5
		result[act[0]] += score
		result[act[-2][:-2]] += score
		score = 0
result.pop(n)
for i in sorted(result.items(), key=lambda x: (-x[1], x[0])):
	print(i[0])


from collections import defaultdict

def getList(dict):
	return dict.keys()
name = input()
n = int(input())
mp = dict()
for k in range(n):
	x = input()
	y = x.split()
	if y[1] == 'posted':
		frnd = y[-2]
		if y[0] != name and frnd[:-2] == name:
			if y[0] in mp.keys():
				mp[y[0]] = mp[y[0]] + 15
			else:
				mp[y[0]] = 15
		elif frnd[:-2] != name and y[0] == name:
			if frnd[:-2] in mp.keys():
				mp[frnd[:-2]] = mp[frnd[:-2]] + 15
			else:
				mp[frnd[:-2]] = 15
		else:
			if y[0] not in mp.keys():
				mp[y[0]] = 0
			if frnd[:-2] not in mp.keys():
				mp[frnd[:-2]] = 0
	if y[1] == 'commented':
		frnd = y[-2]
		if y[0] != name and frnd[:-2] == name:
			if y[0] in mp.keys():
				mp[y[0]] = mp[y[0]] + 10
			else:
				mp[y[0]] = 10
		elif frnd[:-2] != name and y[0] == name:
			if frnd[:-2] in mp.keys():
				mp[frnd[:-2]] = mp[frnd[:-2]] + 10
			else:
				mp[frnd[:-2]] = 10
		else:
			if y[0] not in mp.keys():
				mp[y[0]] = 0
			if frnd[:-2] not in mp.keys():
				mp[frnd[:-2]] = 0
	if y[1] == 'likes':
		frnd = y[-2]
		if y[0] != name and frnd[:-2] == name:
			if y[0] in mp.keys():
				mp[y[0]] = mp[y[0]] + 5
			else:
				mp[y[0]] = 5
		elif frnd[:-2] != name and y[0] == name:
			if frnd[:-2] in mp.keys():
				mp[frnd[:-2]] = mp[frnd[:-2]] + 5
			else:
				mp[frnd[:-2]] = 5
		else:
			if y[0] not in mp.keys():
				mp[y[0]] = 0
			if frnd[:-2] not in mp.keys():
				mp[frnd[:-2]] = 0
st = set()
names = []
for (key, value) in sorted(mp.items()):
	names.append(key)
	st.add(value)
st2 = sorted(st, reverse=True)
for i in st2:
	for nm in names:
		if mp[nm] == i:
			print(nm)


def Sort(sub_li):
	return sorted(sub_li, key=lambda x: x[1])
s = input().rstrip()
n = int(input())
L = []
Q = []
for i in range(0, n):
	p = input().rstrip().split(' ')
	if len(p) == 4:
		A = p[0]
		B = p[2]
		P = []
		D = B
		F = D.split("'")
		C = F[0]
		if A != s and C != s:
			if A not in L:
				L.append(A)
				Q.append(0)
			if C not in L:
				L.append(C)
				Q.append(0)
			continue
		if A != s:
			if A not in L:
				L.append(A)
				Q.append(5)
			else:
				T = L.index(A)
				Q[T] += 5
		if C != s:
			A = C
			if A not in L:
				L.append(A)
				Q.append(5)
			else:
				T = L.index(A)
				Q[T] += 5
	else:
		A = p[0]
		B = p[3]
		P = []
		D = B
		F = D.split("'")
		C = F[0]
		if A != s and C != s:
			if A not in L:
				L.append(A)
				Q.append(0)
			if C not in L:
				L.append(C)
				Q.append(0)
			continue
		if p[len(p) - 1] == 'post':
			if A != s:
				if A not in L:
					L.append(A)
					Q.append(10)
				else:
					T = L.index(A)
					Q[T] += 10
			if C != s:
				A = C
				if A not in L:
					L.append(A)
					Q.append(10)
				else:
					T = L.index(A)
					Q[T] += 10
		else:
			if A != s:
				if A not in L:
					L.append(A)
					Q.append(15)
				else:
					T = L.index(A)
					Q[T] += 15
			if C != s:
				A = C
				if A not in L:
					L.append(A)
					Q.append(15)
				else:
					T = L.index(A)
					Q[T] += 15
D = []
for i in range(0, len(L)):
	E = []
	E.append(L[i])
	E.append(Q[i])
	D.append(E)
E = Sort(D)
E.reverse()
Q = []
for i in range(0, len(E) - 1):
	if E[i][1] != E[i + 1][1]:
		if len(Q) > 0:
			Q.append(E[i][0])
			Q.sort()
			for j in range(0, len(Q)):
				print(Q[j])
			Q = []
		else:
			print(E[i][0])
	else:
		Q.append(E[i][0])
if len(Q) > 0:
	Q.append(E[len(E) - 1][0])
	Q.sort()
	for j in range(0, len(Q)):
		print(Q[j])
	Q = []
else:
	print(E[len(E) - 1][0])


from collections import Counter
name = input()
n = int(input())
cnt = Counter()
points = {'posted': 15, 'commented': 10, 'likes': 5}
for _ in range(n):
	action = input().split()
	subj = action[0]
	dest = action[3] if len(action) == 5 else action[2]
	dest = dest[:-2]
	p = points[action[1]]
	if subj == name:
		cnt[dest] += p
	elif dest == name:
		cnt[subj] += p
	else:
		cnt[subj] += 0
		cnt[dest] += 0
ans = sorted(((v, k) for (k, v) in cnt.items()), key=lambda x: (-x[0], x[1]))
print('\n'.join((x[1] for x in ans)))


name = input()
n = int(input())
actions = []
for i in range(n):
	actions.append(input())
results = {name: 0}
for action in actions:
	comps = action.split()
	if comps[0] not in results:
		results[comps[0]] = 0
	if comps[-2][:-2] not in results:
		results[comps[-2][:-2]] = 0
	if comps[0] == name or comps[-2][:-2] == name:
		score = 0
		if comps[1] == 'posted':
			score += 15
		elif comps[1] == 'commented':
			score += 10
		else:
			score += 5
		results[comps[0]] += score
		results[comps[-2][:-2]] += score
		score = 0
results.pop(name)
for e in sorted(results.items(), key=lambda x: (-x[1], x[0])):
	print(e[0])


from sys import stdin
name = stdin.readline().strip()
n = int(stdin.readline().strip())
actions = []
for i in range(n):
	actions.append(stdin.readline().strip().split())
scores = {}
for i in range(n):
	if len(actions[i]) == 5:
		first = actions[i][0]
		second = actions[i][3][:-2]
		if first not in scores.keys():
			scores[first] = 0
		if second not in scores.keys():
			scores[second] = 0
		if actions[i][1] == 'posted' and (first == name or second == name):
			scores[first] += 15
			scores[second] += 15
		elif actions[i][1] == 'commented' and (first == name or second == name):
			scores[first] += 10
			scores[second] += 10
	else:
		first = actions[i][0]
		second = actions[i][2][:-2]
		if first not in scores.keys():
			scores[first] = 0
		if second not in scores.keys():
			scores[second] = 0
		if first == name or second == name:
			scores[first] += 5
			scores[second] += 5
results = {}
for (nam, score) in scores.items():
	if score not in results.keys():
		results[score] = []
	results[score].append(nam)
results_items = results.items()
sorted_items = sorted(results_items, reverse=True)
for s in sorted_items:
	names_sorted = sorted(s[1])
	for na in names_sorted:
		if na != name:
			print(na)


import sys
import math
import string
import operator
import functools
import fractions
import collections
sys.setrecursionlimit(10 ** 7)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
RI = lambda : list(map(int, input().split()))
RS = lambda : input().rstrip().split()
name = RS()[0]
n = RI()[0]
di = {'posted': 15, 'commented': 10, 'likes': 5}
priority = {}
for i in range(n):
	S = RS()
	X = S[0]
	action = S[1]
	Y = S[-2][:-2]
	if X == name:
		(X, Y) = (Y, X)
	if X not in priority:
		priority[X] = 0
	if Y != name and Y not in priority:
		priority[Y] = 0
	elif Y == name:
		priority[X] += di[action]
ans = [[priority[i], i] for i in priority]
ans.sort(key=lambda x: (-x[0], x[1]))
for i in ans:
	print(i[1])


s = input()
n = int(input())
dict1 = {}
for i in range(n):
	ss = input()
	ll = ss.split()
	if len(ll) == 4:
		a1 = ll[0]
		a2 = ll[2][0:len(ll[2]) - 2]
		if a1 == s:
			if a2 in dict1:
				dict1[a2] += 5
			else:
				dict1[a2] = 5
		elif a2 == s:
			if a1 in dict1:
				dict1[a1] += 5
			else:
				dict1[a1] = 5
		else:
			if a1 in dict1:
				dict1[a1] += 0
			else:
				dict1[a1] = 0
			if a2 in dict1:
				dict1[a2] += 0
			else:
				dict1[a2] = 0
	else:
		a1 = ll[0]
		a2 = ll[3][0:len(ll[3]) - 2]
		if ll[-1] == 'wall':
			c = 15
		else:
			c = 10
		if a1 == s:
			if a2 in dict1:
				dict1[a2] += c
			else:
				dict1[a2] = c
		elif a2 == s:
			if a1 in dict1:
				dict1[a1] += c
			else:
				dict1[a1] = c
		else:
			if a1 in dict1:
				dict1[a1] += 0
			else:
				dict1[a1] = 0
			if a2 in dict1:
				dict1[a2] += 0
			else:
				dict1[a2] = 0
flist = []
for i in dict1:
	flist.append((dict1[i], i))
for i in range(len(flist) - 1):
	for j in range(i + 1, len(flist)):
		if flist[i][0] < flist[j][0]:
			(flist[i], flist[j]) = (flist[j], flist[i])
		elif flist[i][0] == flist[j][0]:
			if flist[i][1] > flist[j][1]:
				(flist[i], flist[j]) = (flist[j], flist[i])
for i in range(len(flist)):
	print(flist[i][1])


def main():
	my_name = input()
	actions = (input().split() for _ in range(int(input())))
	priority_factor = {}
	rewards = {'posted': 15, 'commented': 10, 'likes': 5}
	all_names = {my_name}
	for act in actions:
		X = act[0]
		Y = act[2 if act[1] == 'likes' else 3]
		Y = Y[:-2]
		all_names.add(X)
		all_names.add(Y)
		if Y == my_name:
			(X, Y) = (Y, X)
		if X == my_name:
			priority_factor.setdefault(Y, 0)
			priority_factor[Y] += rewards[act[1]]
	all_names.remove(my_name)

	def key(y):
		return (-priority_factor[y] if y in priority_factor else 0, y)
	print(*sorted(all_names, key=key), sep='\n')
main()


s = input()
n = int(input())
l = []
for i in range(n):
	k = input().split()
	if len(k) == 5:
		a = k[0]
		b = k[3][:-2]
		f = True
		f2 = True
		for q in range(len(l)):
			if a == l[q][0]:
				f = False
			if b == l[q][0]:
				f2 = False
		if f and a != s:
			l.append([a, 0])
		if f2 and b != s:
			l.append([b, 0])
		score = 10
		if k[1] == 'posted':
			score = 15
		for u in range(len(l)):
			if l[u][0] == a and b == s:
				l[u][1] += score
			if l[u][0] == b and a == s:
				l[u][1] += score
	if len(k) == 4:
		a = k[0]
		b = k[2][:-2]
		f = True
		f2 = True
		for q in range(len(l)):
			if a == l[q][0]:
				f = False
			if b == l[q][0]:
				f2 = False
		if f and a != s:
			l.append([a, 0])
		if f2 and b != s:
			l.append([b, 0])
		score = 5
		for u in range(len(l)):
			if l[u][0] == a and b == s:
				l[u][1] += score
			if l[u][0] == b and a == s:
				l[u][1] += score
i = 0
while i < len(l):
	j = 0
	while j < len(l) - 1:
		if l[j][1] < l[j + 1][1]:
			k = l[j]
			l[j] = l[j + 1]
			l[j + 1] = k
		if l[j][1] == l[j + 1][1]:
			if l[j][0] > l[j + 1][0]:
				k = l[j]
				l[j] = l[j + 1]
				l[j + 1] = k
		j += 1
	i += 1
for i in l:
	print(i[0])


k = input()
temp = k
m = int(input())
hash = {}
for i in range(m):
	c = input()
	l = list(map(str, c.split()))
	for h in l:
		if "'" in h:
			ans = h
			u = ans.index("'")
			ans = ans[:u]
			break
	m = c.index(' ')
	if c[:m] not in hash.keys():
		hash[c[:m]] = 0
	if ans not in hash.keys():
		hash[ans] = 0
	if c[:m] == temp or ans == temp:
		if 'posted' == c[m + 1:m + 7]:
			hash[c[:m]] += 15
			hash[ans] += 15
		elif 'commented' == c[m + 1:m + 10]:
			hash[c[:m]] += 10
			hash[ans] += 10
		else:
			hash[c[:m]] += 5
			hash[ans] += 5
ha = []
for i in hash.keys():
	ha.append([hash[i], i])
ha.sort()
ba = set()
sa = []
for i in range(len(ha)):
	ba.add(ha[i][0])
ba = sorted(list(ba))
ba.reverse()
for i in ba:
	ta = []
	for j in range(len(ha)):
		if i == ha[j][0]:
			ta.append(ha[j][1])
	ta.sort()
	for b in ta:
		if b != temp:
			sa.append(b)
for j in sa:
	print(j)


I = input
r = {'posted': 15, 'commented': 10, 'likes': 5}
n = I()
a = {}
m = set()
for _ in '0' * int(I()):
	t = I().split()
	s = t[0]
	p = t[3 - (t[1] == 'likes')][:-2]
	m.add(s)
	m.add(p)
	if s == n:
		a[p] = a.get(p, 0) + r[t[1]]
	if p == n:
		a[s] = a.get(s, 0) + r[t[1]]
if n in m:
	m.remove(n)
for v in sorted(set(a.values()) | set([0]))[::-1]:
	print('\n'.join(sorted((s for s in m if a.get(s, 0) == v))))


my_name = input()
n_actions = int(input())
priority = {'posted': 15, 'commented': 10, 'likes': 5}
names = {}
for i in range(n_actions):
	action = input().split()
	(n1, n2) = (action[0], action[-2][:-2])
	if n1 == my_name:
		names.setdefault(n2, 0)
		names[n2] -= priority[action[1]]
	elif n2 == my_name:
		names.setdefault(n1, 0)
		names[n1] -= priority[action[1]]
	else:
		names.setdefault(n1, 0)
		names.setdefault(n2, 0)
names = sorted(((v, k) for (k, v) in names.items()))
for name in names:
	print(name[1])


class pair:

	def __init__(self, f, s):
		self.f = f
		self.s = s
me = input()
n = int(input())
mp = {}
for i in range(n):
	a = list(map(str, input().split()))
	if a[1] == 'likes':
		ot = a[2]
	else:
		ot = a[3]
	her = ''
	for j in range(len(ot) - 2):
		her += ot[j]
	if me != a[0] and me != her:
		try:
			x = mp.get(a[0])
			mp[a[0]] += 0
		except:
			mp[a[0]] = 0
		try:
			x = mp.get(her)
			mp[her] += 0
		except:
			mp[her] = 0
		continue
	if a[1] == 'posted':
		try:
			x = mp.get(a[0])
			mp[a[0]] += 15
		except:
			mp[a[0]] = 15
		try:
			x = mp.get(a[0])
			mp[her] += 15
		except:
			mp[her] = 15
	elif a[1] == 'commented':
		try:
			x = mp.get(a[0])
			mp[a[0]] += 10
		except:
			mp[a[0]] = 10
		try:
			x = mp.get(a[0])
			mp[her] += 10
		except:
			mp[her] = 10
	else:
		try:
			x = mp.get(a[0])
			mp[a[0]] += 5
		except:
			mp[a[0]] = 5
		try:
			x = mp.get(a[0])
			mp[her] += 5
		except:
			mp[her] = 5
names = []
for i in mp:
	if i != me:
		names.append(pair(mp[i], i))
l = sorted(names, key=lambda x: (-x.f, x.s))
for i in range(len(names)):
	print(l[i].s)


import re
my_name = input()
num_of_interactions = int(input())
post = re.compile("(\\w+) posted on (\\w+)'s wall")
comment = re.compile("(\\w+) commented on (\\w+)'s post")
like = re.compile("(\\w+) likes (\\w+)'s post")
friends = dict()

def get_other_name(my_name, groups):
	global firends
	other_name = str()
	if groups[0] == my_name:
		other_name = groups[1]
	elif groups[1] == my_name:
		other_name = groups[0]
	else:
		friends[groups[0]] = friends.get(groups[0], 0)
		friends[groups[1]] = friends.get(groups[1], 0)
	return other_name
for _ in range(num_of_interactions):
	line = input()
	post_result = post.match(line)
	comment_result = comment.match(line)
	like_result = like.match(line)
	if post_result:
		other_name = get_other_name(my_name, post_result.groups())
		if other_name:
			friends[other_name] = friends.get(other_name, 0) + 15
	elif comment_result:
		other_name = get_other_name(my_name, comment_result.groups())
		if other_name:
			friends[other_name] = friends.get(other_name, 0) + 10
	elif like_result:
		other_name = get_other_name(my_name, like_result.groups())
		if other_name:
			friends[other_name] = friends.get(other_name, 0) + 5
print(*[name for (name, priority) in sorted(friends.items(), key=lambda item: (-item[1], item))], sep='\n')


import sys
import math
from collections import defaultdict
import itertools
MAXNUM = math.inf
MINNUM = -1 * math.inf

def getInts():
	return map(int, sys.stdin.readline().rstrip().split(' '))

def getInt():
	return int(sys.stdin.readline().rstrip())

def getString():
	return sys.stdin.readline().rstrip()

def printOutput(ans):
	for (a, b) in ans:
		sys.stdout.write(a + '\n')

def solve(scores, name):
	lst = []
	for (key, val) in scores.items():
		if key != name:
			lst.append((key, val))
	lst.sort(key=lambda x: x[0])
	lst.sort(key=lambda x: x[1], reverse=True)
	return lst

def readinput():
	scores = defaultdict(int)
	valueDict = {'posted': 15, 'commented': 10, 'likes': 5}
	name = getString()
	actions = getInt()
	for _ in range(actions):
		a = getString().split(' ')
		p1 = a[0]
		op = a[1]
		if a[1][0] == 'p' or a[1][0] == 'c':
			p2 = a[3].split("'")[0]
		else:
			p2 = a[2].split("'")[0]
		if p1 == name or p2 == name:
			scores[p1] += valueDict[op]
			scores[p2] += valueDict[op]
		else:
			if p1 not in scores:
				scores[p1] = 0
			if p2 not in scores:
				scores[p2] = 0
	printOutput(solve(scores, name))
readinput()


import sys
from array import array
from collections import Counter

def input():
	return sys.stdin.buffer.readline().decode('utf-8')
name = input().rstrip()
n = int(input())
cnt = Counter()

def solve(s):
	if s[1] == 'posted':
		return (s[0], s[3][:-2], 15)
	elif s[1] == 'commented':
		return (s[0], s[3][:-2], 10)
	else:
		return (s[0], s[2][:-2], 5)
for _ in range(n):
	s = input().split()
	(name1, name2, pts) = solve(s)
	if name1 == name:
		cnt[name2] += pts
	elif name2 == name:
		cnt[name1] += pts
	else:
		cnt[name1] += 0
		cnt[name2] += 0
res = sorted(((-val, key) for (key, val) in cnt.items()))
for (_, key) in res:
	print(key)


ans = []
me = input()
pri = {}
d = {'p': 15, 'c': 10, 'l': 5}
n = int(input())
for i in range(n):
	s = input().split()
	a = s[0]
	b = s[1]
	c = s[-2][:-2]
	if a == me or c == me:
		if a == me:
			if c in pri:
				pri[c] -= d[b[0]]
			else:
				pri[c] = -d[b[0]]
		elif a in pri:
			pri[a] -= d[b[0]]
		else:
			pri[a] = -d[b[0]]
	else:
		if a not in pri:
			pri[a] = 0
		if c not in pri:
			pri[c] = 0
for (v, k) in sorted(((v, k) for (k, v) in pri.items())):
	print(k)


r = input
c = r()
x = int
A = dict
y = range
I = print
n = x(r())
d = A()
p = [' likes ', ' commented on ', ' posted on ']
for _ in y(n):
	s = r()
	for i in y(3):
		if p[i] in s:
			s = s.split(p[i])
			break
	(a, b) = s
	b = b.split("'")[0]
	s = [a, b]
	if c in s:
		a = s[1 - s.index(c)]
		d[a] = d.get(a, 0) - (i + 1) * 5
	else:
		d[a] = d.get(a, 0)
		d[b] = d.get(b, 0)
j = [[d[i], i] for i in d]
j.sort(key=lambda x: (x[0], x[1]))
for i in j:
	I(i[1])


my = input()
a = {}
for _ in range(int(input())):
	s = input().split()
	(x, y) = (s[0], s[-2][:-2])
	if s[1] == 'posted':
		z = 15
	elif s[1] == 'commented':
		z = 10
	else:
		z = 5
	if x != my and (not x in a):
		a[x] = 0
	if y != my and (not y in a):
		a[y] = 0
	if x == my:
		a[y] += z
	if y == my:
		a[x] += z
b = []
for x in a:
	b.append((100000000 - a[x], x))
b.sort()
for x in b:
	print(x[1])


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
me = input()
n = iinput()
cnt = {}
for i in range(n):
	inp = input().split()
	(a, b, act) = (inp[0], inp[-2][:-2], inp[1])
	if a not in cnt.keys():
		cnt[a] = 0
	if b not in cnt.keys():
		cnt[b] = 0
	if a != me and b != me:
		continue
	if act == 'posted':
		sc = 15
	elif act == 'commented':
		sc = 10
	elif act == 'likes':
		sc = 5
	cnt[a] += sc
	cnt[b] += sc
lst = sorted(list(cnt.keys()), key=lambda x: (-cnt[x], x))
for name in lst:
	if name == me:
		continue
	print(name)


from functools import cmp_to_key
me = input()
q = int(input())
mapita = {}
score = {}
score['posted'] = 15
score['commented'] = 10
score['likes'] = 5

def addValue(name, x):
	if not mapita.get(name):
		mapita[name] = x
	else:
		mapita[name] += x

def comparator(x, y):
	if mapita[x] != mapita[y]:
		return mapita[y] - mapita[x]
	elif x < y:
		return -1
	elif y < x:
		return 1
	else:
		return 0
while q:
	q -= 1
	line = input().split()
	a = line[0]
	action = line[1]
	b = line[2 if action == 'likes' else 3][0:-2]
	if a == me:
		addValue(b, score[action])
	elif b == me:
		addValue(a, score[action])
	else:
		addValue(a, 0)
		addValue(b, 0)
results = sorted(mapita.keys(), key=cmp_to_key(comparator))
for x in results:
	print(x)


NAME = str(input())
n = int(input())
lname = list()
lpoints = list()
tmplist = list()
lstr = str()
for i in range(n):
	lstr = str(input())
	lstr = lstr.replace("'s wall", '')
	lstr = lstr.replace("'s post", '')
	lstr = lstr.replace('ted on ', ' ')
	tmplist = lstr.split(' ')
	if tmplist[0] == NAME or tmplist[2] == NAME:
		if tmplist[0] == NAME:
			lstr = tmplist[2]
		else:
			lstr = tmplist[0]
		action = tmplist[1]
		if action == 'pos':
			lname.append([lstr, 15])
		elif action == 'commen':
			lname.append([lstr, 10])
		elif action == 'likes':
			lname.append([lstr, 5])
	else:
		lname.append([tmplist[0], 0])
		lname.append([tmplist[2], 0])
spnames = dict()
spnames = {lname[i][0]: 0 for i in range(len(lname))}
for i in range(len(lname)):
	spnames[lname[i][0]] = spnames[lname[i][0]] + lname[i][1]
invspnames = dict()
for key in spnames:
	val = spnames[key]
	if val not in invspnames:
		invspnames[val] = [key]
	else:
		invspnames[val].append(key)
lpoints = list(map(int, invspnames.keys()))
lpoints.sort()
lpoints.reverse()
for i in lpoints:
	tmplist = list(map(str, invspnames.get(i)))
	tmplist.sort()
	for s in tmplist:
		print(s)


from collections import defaultdict
from functools import cmp_to_key

def fun(a, b):
	if a[1] == b[1]:
		if a[0] < b[0]:
			return -1
		elif a[0] == b[0]:
			return 0
		else:
			return 1
	elif a[1] < b[1]:
		return 1
	else:
		return -1
points = defaultdict(int)
my_name = input()
for _ in range(int(input())):
	st = input().split()
	if len(st) == 5:
		name1 = st[0]
		name2 = st[3][:-2]
		if st[-1] == 'wall':
			if name1 == my_name or name2 == my_name:
				points[name2] += 15
				points[name1] += 15
			else:
				points[name2] += 0
				points[name1] += 0
		elif name1 == my_name or name2 == my_name:
			points[name2] += 10
			points[name1] += 10
		else:
			points[name2] += 0
			points[name1] += 0
	else:
		name1 = st[0]
		name2 = st[2][:-2]
		if name1 == my_name or name2 == my_name:
			points[name2] += 5
			points[name1] += 5
		else:
			points[name2] += 0
			points[name1] += 0
myList = [(key, value) for (key, value) in dict(points).items() if key != my_name]
myList.sort(key=cmp_to_key(fun))
for i in myList:
	print(i[0])


def cf31B():
	from sys import stdin, stdout
	inp = list(stdin.readline().strip().split('@'))
	flag = True
	if len(inp) >= 2:
		if len(inp[0]) == 0 or len(inp[-1]) == 0:
			flag = False
		if flag:
			for i in range(1, len(inp) - 1):
				if len(inp[i]) < 2:
					flag = False
					break
	else:
		flag = False
	answer = ''
	if flag:
		for (i, j) in enumerate(inp):
			if i == 0:
				answer += j
			elif i == len(inp) - 1:
				answer += '@' + j
			else:
				answer += '@' + j[:-1] + ',' + j[-1]
	else:
		answer = 'No solution'
	stdout.write(answer + '\n')

def cf75B():
	from sys import stdin, stdout
	myname = stdin.readline().strip()
	points = {}
	for _ in range(int(stdin.readline())):
		inp = stdin.readline().strip().split()
		a = inp[0]
		b = inp[-2][:-2]
		p = 0
		if inp[1][0] == 'p':
			p = 15
		elif inp[1][0] == 'c':
			p = 10
		else:
			p = 5
		if a == myname:
			if b in points:
				points[b] += p
			else:
				points[b] = p
		elif b == myname:
			if a in points:
				points[a] += p
			else:
				points[a] = p
		else:
			if a not in points:
				points[a] = 0
			if b not in points:
				points[b] = 0
	revpoints = {}
	mylist = []
	for key in points:
		if points[key] in revpoints:
			revpoints[points[key]].append(key)
		else:
			revpoints[points[key]] = [key]
	for key in revpoints:
		revpoints[key].sort()
	for key in revpoints:
		mylist.append((key, revpoints[key]))
	mylist.sort(reverse=True)
	for (i, j) in enumerate(mylist):
		for name in j[1]:
			stdout.write(name + '\n')
cf75B()