#include<map>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

struct Letter{
	bool re;
	int num;
	string s;
};

Letter L[100000];
bool used[100000];
map< pair<string,int>,vector<int> > Pos;
map< pair<string,int>,vector<int> >::iterator it;
vector<int>::iterator jt;

void dfs(int i){
	used[i]=true;
	printf("%d\n",i+1);

	if(i>0 && L[i-1].re && !used[i-1]) dfs(i-1);

	pair<string,int> next(L[i].s,L[i].num+1);
	if((it=Pos.find(next))!=Pos.end()){
		jt=lower_bound(it->second.begin(),it->second.end(),i);
		if(jt!=it->second.begin()){
			int j=*--jt;
			it->second.erase(jt);
			dfs(j);
			return;
		}
	}
}

int main(){
	for(int n;cin>>n,n;){
		Pos.clear();
		rep(i,n){
			used[i]=false;
			string s; cin>>s;

			bool re;
			if(*s.rbegin()=='v'){
				re=true;
				s.erase(--s.end());
			}
			else re=false;

			int j;
			for(j=(int)s.length()-1;j>=0&&isdigit(s[j]);j--);
			int num=-1;
			if(j<(int)s.length()-1) num=atoi(s.c_str()+j+1);
			s=s.substr(0,j+1);

			L[i]=(Letter){re,num,s};

			if(L[i].num>1) Pos[make_pair(L[i].s,L[i].num)].push_back(i);
		}

		rep(i,n) if(!L[i].re && L[i].num<=1 && !used[i]) dfs(i);
	}

	return 0;
}