(function (f) local a=f() for i=1,#a do io.write(a[i][1]," ",a[i][2],"\n") if i==10 then break end end end)(function () local a,h,i={},{},1 for _=1,tonumber(io.stdin:read("*l")) do io.stdin:read("*l") local t=tonumber(io.stdin:read("*l"):match("%s(%d+)")) for e in io.stdin:read("*l"):gmatch("[%w%.]+") do if h[e]==nil then a[i],h[e],i={e,0},i,i+1 end a[h[e]][2]=a[h[e]][2]+t end end table.sort(a,function (a,b) return a[2]==b[2] and a[1]b[2] end) return a end)