#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
 
using std::cout;
using std::cin;
using std::string;
using std::endl;
using std::vector;
 
struct aCustomer
{
	string mAddr;
	int purchase;
};
 
bool IsGreaterThanPurchase(const aCustomer &A,const  aCustomer &B)
{
	return(A.purchase > B.purchase);
}
 
int main() {
	vector<aCustomer> cList;
	int n;//客の数
 
	cin >> n;
	for(int i=0; i < n; i++)
	{
		aCustomer tmp;
		cin >>  tmp.purchase >> tmp.mAddr;
		cList.push_back(tmp);
	}
	std::sort(cList.begin(), cList.end(), IsGreaterThanPurchase);
 
	for(auto &e: cList)
	{
		cout << e.purchase << " " << e.mAddr << endl;		
	}
}