import sys

fIn = 'queries' + sys.argv[1] + '.txt'
fOut = 'popularity' + sys.argv[1] + '.txt'

fdIn = open(fIn, 'r')
fdOut = open(fOut, 'w')

keys = {}
for line in fdIn:
    if line in keys: keys[line] = keys[line] + 1
    else : keys[line] = 1

for i in keys: fdOut.write(str(keys[i]) + '\n')

fdIn.close()
fdOut.close()
