const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    // Write your code here
    await readline();
    const map = {};
    while ((line = await readline())) {
        const currArr = line.split(" ")
        const idx = currArr[0];
        const num = +currArr[1]
        if (!map[idx]) {
            map[idx] = line;
        }else{
            const arr = map[idx].split(" ")
            const number = +arr[1]
            map[idx] = idx + " " + (num + number)
        }
    }
    Object.values(map).forEach(item=>console.log(item))
})();