#include <bits/stdc++.h>
using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

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

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n;cin>>n && n;){
		vs lines(n);
		rep(i,n) cin>>lines[i];
		
		vi prev(n,-1);
		rep(i,n) if(lines[i].back()=='v'){
			prev[i]=i+1;
			//lines[i].pop_back();
			lines[i].erase(end(lines[i])-1);
		}
		map<string,int> f;
		per(i,n) if(lines[i].size() && isdigit(lines[i].back()))
			rep(j,lines[i].size())
				if(isdigit(lines[i][j])){
					string tag=lines[i].substr(0,j);
					int x=stoi(lines[i].substr(j));
					if(x>1) prev[i]=f[tag];
					f[tag]=i;
				}
		
		vvi pathes;
		vi vis(n);
		rep(i,n) if(!vis[i]){
			vi path;
			for(int v=i;v!=-1;v=prev[v]){
				path.push_back(v);
				vis[v]=1;
			}
			reverse(all(path));
			pathes.push_back(path);
		}
		sort(all(pathes));
		
		rep(i,pathes.size()) rep(j,pathes[i].size())
			cout<<pathes[i][j]+1<<endl;
	}
}