#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	char buf[21];
	for(int n;scanf("%d ",&n),n;){
		vs lines(n);
		rep(i,n){
			gets(buf);
			lines[i]=buf;
		}
		
		vs tags(n);
		vi marks(n),isre(n);
		rep(i,n){
			int j=lines[i].size()-1;
			if(lines[i][j]=='v'){
				isre[i]=1;
				j--;
			}
			int k=j;
			while(k>=0 && isdigit(lines[i][k]))
				k--;
			k++;
			if(k<=j)
				marks[i]=atoi(lines[i].c_str()+k);
			tags[i]=lines[i].substr(0,k);
		}
		
		map<string,int> q;
		vi prev(n,-1);
		for(int i=n;i--;){
			if(marks[i]>0){
				int& cur=q[tags[i]];
				if(marks[i]>1)
					prev[i]=cur;
				cur=i;
			}
		}
		rep(i,n)
			if(isre[i])
				prev[i]=i+1;
		
		vvi paths;
		vi flgs(n);
		rep(i,n){
			if(flgs[i])
				continue;
			vi path;
			for(int j=i;j!=-1;j=prev[j]){
				path.push_back(j);
				flgs[j]=1;
			}
			reverse(allof(path));
			paths.push_back(path);
		}
		
		sort(allof(paths));
		
		vi perm(n);
		int k=0;
		rep(i,paths.size()) rep(j,paths[i].size())
			perm[k++]=paths[i][j];
		
		rep(i,n)
			printf("%d\n",perm[i]+1);
	}
	
	return 0;
}