#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
using namespace std;
struct cm{
	int id,t;
	char name[101];
}a[10001];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s %d",a[i].name,&a[i].t);a[i].id=i;
	}
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			if(!strcmp(a[i].name,a[j].name)&&a[i].t<a[j].t) {
				cm pt;
				pt=a[i];a[i]=a[j];a[j]=pt;
			}
			else{
				for(int p=0;p<=min(strlen(a[i].name),strlen(a[j].name));p++){
					if(a[i].name[p]>a[j].name[p]){
						//printf("%d   %s->%s\n",p,a[i].name,a[j].name );
					cm pt;
					pt=a[i];a[i]=a[j];a[j]=pt;
					break;
					}
					if(a[i].name[p]<a[j].name[p]) break;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",a[i].id );
	}
	return 0;
}