#include<iostream>
#include<map>
using namespace std;

int main()
{
	int n = 0;
	map<int, int> hash;
	cin >> n;
	int index, value;
	while (n)
	{
		cin >> index >> value;
		if (hash.count(index) == 0)
		{
			hash[index] = value;
		}
		else
		{
			hash[index] = hash[index] + value;
		}
		--n;
	}
	for (auto i : hash)
	{
		cout << i.first << " " << i.second << endl;
	}
	return 0;
}