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
    while(line = await readline()){
        let length = parseInt(line);

        let obj = {};
        for (let i = 0; i < length; i++) {
            let [k,v] = (await readline()).split(" ");
            if (obj[k]) {
            obj[k] += parseInt(v);
            } else {
            obj[k] = parseInt(v)
            }
        }
        
        for (const key in obj) {
            console.log(key + " " + obj[key]);
        }
    }
}()