#include <iostream>
#include <map>

using namespace std;

int main()
{
    uint32_t n;
    cin >> n;

    map<uint32_t, uint32_t> m;
    for (uint32_t i = 0; i < n; ++i) {
        uint32_t key, value;
        cin >> key >> value;
        m[key] += value;
    }
    for (auto &i : m) {
        cout << i.first << " " << i.second << endl;
    }
}