N = gets.to_i
input_data = []
tmp = []
while tmp = gets() do
	input_data << tmp.split.to_a
end
input_data.sort_by!{|s, p|s}
tmp_ary = []
ans = []
N.times do |i|
	tmp_ary << input_data[i]
	tmp = input_data[i][0]
	cnt = 0
	while tmp == input_data[i + cnt][0] do
		tmp_ary << input_data[i + cnt]
		tmp_ary.sort_by!{|s, p|p.to_i}
		cnt += 1
	end
	ans << tmp_ary
	tmp_ary.clear
end