def main():
	sim, friends, train, test = get_usersim(), get_friends(), get_train(), get_test()
	score = 0
	for line in test:
		user, artist = line.split()[:2]
		# get 10 recommended artists for every user
		recommended = recommend(sim, train, friends, user, n=34)
		hit = int(artist in recommended) # determine whether the artist was recommended/predicted or not
		score += hit
	print("Score: {} from {}\nAccuracy: {:.2f}%".format(score, len(test), 100*score/len(test)))
def main():
	train, test = get_train(), get_test()
	all_artists = list(train)
	score = 0
	for line in test:
		user, artist = line.split()[:2]
		# get 10 random artists for every user
		shuffle(all_artists)
		recommended = all_artists[:10]
		hit = int(artist in recommended) # determine whether the artist was recommended/predicted or not
		score += hit
	print("Score: {} from {}\nAccuracy: {:.2f}%".format(score, len(test), 100*score/len(test)))
from collections import defaultdict
from get import get_artist_ID, get_itemsim, get_usersim, get_friends, get_train, get_test
from sys import stdin

sim = get_itemsim()
artist_ID = get_artist_ID()
train = get_train()

for line in stdin:
	artist = line.strip()
	scores = []
	for sim_artist in sim[artist]:
		similarity_score = sim[artist][sim_artist]
		scores.append((similarity_score,sim_artist))
	topNsimilar = sorted(scores,reverse=1)[:10]
	for tup in topNsimilar:
		print(artist_ID[tup[1]], tup[0])