let num = parseInt(readline())
let obj = {}
for(let i= 0; i<num; i++) {
const [k, v] = readline().split(' ')
if (!obj[k]) {
obj[k] = +v
} else {
obj[k] += +v
}
}
Object.keys(obj).forEach((el) => {
console.log(`${el} ${obj[el]}`)
})