#include <string>
#include <iostream>
#include <vector>
using namespace std;
struct tr{
    vector<tr*> children;
    string name;
    int depth;
    void prt(){
        for(int i=0;i<depth;i++){cout<<".";}
        cout<<name<<endl;
        for(auto i=children.begin();i!=children.end();i++){
            (*i)->prt();
        }
    }        
};

int main(){
    int n,i,p;
    cin>>n;
    vector<tr> t(n);
    for(i=0;i<n;i++){
        tr buf;
        cin>>p;
        cin>>buf.name;
        if(!i){
            buf.depth=0;
            t[0]=buf;
        }        
        else{
            buf.depth=t[p-1].depth+1;
            t[i]=buf;
            t[p-1].children.push_back(&t[i]);
        }
    }
    t[0].prt();
    return 0;
}

