#include <iostream>
#include <utility>
using namespace std;
int partition(int a[], int l,int r){
int v = a[l];
while ( l < r ){
while ( l < r && a[r] >= v ) r--;
a[l] = a[r];
while ( l < r && a[l] <= v ) l++;
a[r] = a[l];
}
a[l] = v;
return l;
}
void qsort(int a[], int l, int r){
if ( l >= r ) return;
int mid = partition( a,l,r );
qsort( a,l,mid - 1 );
qsort( a,mid + 1,r );
}
struct student{
int fenshu;
string name;
};
int main(){
int n;
cin >> n;
student a[105];
//pair<pair <int ,int >, string >a[105];
//for (int i = 1 ; i <= n;i++){
// cin >> a[i].second;
// cin >> a[i].first.first;
// a[i].first.second = i;
//}
//qsort(a,1,n - 1);
for (int i = 1; i <= n;i++){
cin >> a[i].name >> a[i].fenshu;
}
for (int j = 0; j < n; j++){
for (int i = 1; i < n - j;i++){
if (a[i].fenshu < a[i + 1].fenshu){
student b;
b.name = a[i].name;
b.fenshu = a[i].fenshu;
a[i].name = a[i + 1].name;
a[i].fenshu = a[i + 1].fenshu;
a[i + 1].name = b.name;
a[i + 1].fenshu = b.fenshu;
}
}
}
for (int i = 1; i <= n;i++){
cout << a[i].name << " " <<a[i].fenshu << endl;
}
}