#include <bits/stdc++.h>
	    
	    
	    using namespace std;
	
	    #define ll long long
	    #define do double
	    #define ff first
	    #define ss second
	    #define FOR(a,n) for(i=0;i<n;i++){    cin>>a[i];}
	    #define pb push_back
	    #define mp make_pair
	    #define inf LONG_LONG_MAX
	    #define mod  1000000007
	    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	    
/*
	ll d,x,y;
	void extendedEuclid(ll A, ll B) 
	{
	    if(B == 0) {
	        d = A;
	        x = 1;
	        y = 0;
	    }
	    else {
	        extendedEuclid(B, A%B);
	        int temp = x;
	        x = y;
	        y = temp - (A/B)*y;
	    }
	}

	ll power(ll x,ll y, ll p) 
	{ 
	    ll res = 1; 
	    x = x % p;
	    while (y > 0) 
	    {  // If y is odd, multiply x with result 
	        if (y & 1) 
	            res = (res*x) % p;
	            
	        y = y>>1; 
	        x = (x*x) % p;   
	    } 
	    return res; 
	} 
	ll isPrime(ll n)
	        {
	            
	           if(n==0 || n==1)
	           return 0;
	            if (n%2 == 0) 
	                return 2;
	            
	            if(n%3==0)
	                return 3;
	         
	            for (ll i=5; i*i<=n; i=i+6)
	            {
	                if (n%i == 0)
	                   return i;
	                if (n%(i+2) == 0)
	                   return i+2;
	            }
	            
	            return n;
	        }



map<ll,ll> par,val;
void ini()
{
	for(ll i=0;i<500010;i++)
		{
			par[i]=i;
		}
}

ll root(ll x)
{
	while(par[x]!=x)
	{
		par[x]=par[par[x]];
		x=par[x];
	}
	return x;
}

void uni(ll x,ll y)
{
	x=root(x);
	y=root(y);
	if(val[x]<=val[y])
		par[y]=par[x];
	else
		par[x]=par[y];
	
}
vector<vector<pair<ll,ll> > > v(200010);
vector<ll> ans;
map<ll,ll> vis,dis;

ll bfs(ll n)
{
	vis[1]=1;
	dis[1]=0;
	ll f=0,i;
	queue<ll> q;
	q.push(1);
	ll ans=0;
	while(q.size()>0)
	{
		ll x=q.front();
		q.pop();
		for(i=0;i<v[x].size();i++)
		{
			if(!vis[v[x][i].ff])
			{
				dis[v[x][i].ff]=dis[x]+v[x][i].ss;
				ans=max(ans,dis[v[x][i].ff]);
				q.push(v[x][i].ff);
				vis[v[x][i].ff]=1;
			}
		}
	}
	return ans;
}
vector<ll> a(1000000);
vector<ll> spf(1000000),pr(2000000);
bool prime[1000000];
void sieve()
{
	ll i,j;
	memset(prime, true, sizeof(prime));
	prime[0]=prime[1]=false; 
	for(i=2;i*i<=1000000;i++)
	{
		if(prime[i]==true)
		{	pr.pb(i);
			for(j=i*i;j<=100000;j+=i)
			{
				prime[j]=false;
				if(spf[j]==0)
					spf[j]=i;
			}
		}
	}
	for(ll k=i;k<2000000;k++)
	{
		if(prime[k]==true)
		{
			pr.pb(k);
		}
	}
}

int gcdExtended(int a, int b, int *x, int *y) 
{ 

    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    int x1, y1;
    int gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1;
    return gcd; 
}  
int modInverse(int b, int m) 
{ 
    int x, y; 
    int g = gcdExtended(b, m, &x, &y); 
    if (g != 1) 
        return -1; 
    return (x%m + m) % m; 
}*/
vector<vector<ll> > v(2000000);
void bfs(ll n,ll m)
{
	map<ll,ll> level,fr;
	vector<ll> o,e;
	fr[n]=1;
	level[n]=0;
	e.pb(n);
	queue<ll> q;
	q.push(n);
	while(!q.empty())
	{
		ll x=q.front();
		q.pop();
		for(ll i=0;i<v[x].size();i++)
		{
			if(fr[v[x][i]]==0)
				{
					fr[v[x][i]]=1;
					level[v[x][i]]=level[x]+1;
					if(level[v[x][i]]%2==1)
						o.pb(v[x][i]);
					else
						e.pb(v[x][i]);
					q.push(v[x][i]);
				}
		}
	}

	if(e.size()<=m/2)
	{
		cout<<e.size()<<endl;
		for(ll i=0;i<e.size();i++)
			cout<<e[i]<<" ";
	}
	else
	{
		cout<<o.size()<<endl;
		for(ll i=0;i<o.size();i++)
			cout<<o[i]<<" ";
	}
	cout<<endl;
}
/*
FAST;
		sieve();
		ll n,m,k,i,j,h;
		ll t;
		cin>>t;
		cin>>n;
		std::vector<ll > a(2*n),b(2*n);
		for(i=0;i<n;i++)
		{
			cin>>a[i];
			if(spf[a[i]]==0)
			{
				b[i]= ({a[i],pr[a[i]-1]});
			}
			else
			{
				b[i]={a[i],a[i]/spf[a[i]]};
			}
		}
*/

int main()
{
		FAST;
		ll n,m,k,i,j,h;
		ll t;
		cin>>n;
		set<string> ss;
		map<string,vector<pair<ll,ll> > > fr;
		for(i=0;i<n;i++)
		{
			string s;
			cin>>s;
			cin>>k;
			ss.insert(s);
			fr[s].pb({k,i});
		}
		set<string>::iterator itr;
		
		for(itr=ss.begin();itr!=ss.end();itr++)
		{
			sort(fr[*itr].rbegin(),fr[*itr].rend());
			string t=*itr;
			for(i=0;i<fr[t].size();i++)
			{
				cout<<fr[t][i].ss+1<<endl;
			}
		}
		


		

}

Measured memory_bytes: 47104