#include <bits/stdc++.h>
using namespace std;
#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))
int n;
vector<vector<int>> v;
vector<string> w;
void foo(int a,int b){
    cout<<string(a,'.')<<w[b]<<endl;
    for(int x:v[b]){
        foo(a+1,x);
    }
}
int main(){
    cin>>n;
    v.resize(n);
    w.resize(n);
    rep(i,n){
        int t;
        cin>>t;
        cin>>w[i];
        if(t==0) continue;
        v[t-1].push_back(i);
    }
    foo(0,0);
}