#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool sortowanie(const pair<int,int> &p1,const pair<int,int> &p2)
{
if(p1.first != p2.first)
return p2.first < p1.first;
else
return p2.second > p1.second;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ilosc_towarow;
cin>>ilosc_towarow;
vector<pair<int,int>> towar(ilosc_towarow);
for(int i=0;i<ilosc_towarow;i++)
cin>>towar[i].second>>towar[i].first;
sort(towar.begin(),towar.end(),sortowanie);
for(int i=0;i<ilosc_towarow;i++)
cout<<towar[i].second<<' '<<towar[i].first<<endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpib29sIHNvcnRvd2FuaWUoY29uc3QgcGFpcjxpbnQsaW50PiAmcDEsY29uc3QgcGFpcjxpbnQsaW50PiAmcDIpCgl7CgkJaWYocDEuZmlyc3QgIT0gcDIuZmlyc3QpCgkJcmV0dXJuIHAyLmZpcnN0IDwgcDEuZmlyc3Q7CgkJZWxzZQoJCXJldHVybiBwMi5zZWNvbmQgPiBwMS5zZWNvbmQ7Cgl9CmludCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsgCiAgICBjaW4udGllKDApOwogICAgY291dC50aWUoMCk7CiAgICAKICAgIGludCBpbG9zY190b3dhcm93OwogICAgY2luPj5pbG9zY190b3dhcm93OwogICAgdmVjdG9yPHBhaXI8aW50LGludD4+IHRvd2FyKGlsb3NjX3Rvd2Fyb3cpOwoJCglmb3IoaW50IGk9MDtpPGlsb3NjX3Rvd2Fyb3c7aSsrKQoJY2luPj50b3dhcltpXS5zZWNvbmQ+PnRvd2FyW2ldLmZpcnN0OwoJCglzb3J0KHRvd2FyLmJlZ2luKCksdG93YXIuZW5kKCksc29ydG93YW5pZSk7CgkKCWZvcihpbnQgaT0wO2k8aWxvc2NfdG93YXJvdztpKyspCgljb3V0PDx0b3dhcltpXS5zZWNvbmQ8PCcgJzw8dG93YXJbaV0uZmlyc3Q8PGVuZGw7Cn0=