while(line = readline()) {
    var rowCount = parseInt(line)
    var map = {}
    var row
    while(row = readline()) {
        var rowArr = row.split(' ')
        if (map[rowArr[0]] === undefined) {
            map[rowArr[0]] = 0
        }
        map[rowArr[0]] += parseInt(rowArr[1])
    }
    Object.keys(map).sort(
        function(a, b) {
            return a - b
        }
    ).forEach(key => {
        console.log(key + ' ' + map[key])
    })
}