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

void print(int node, int d, vector<vector<int> > adjlist, vector<string> name){

    for(int i = 0; i < d; i++) cout << '.';
    cout << name[node] << endl;
    for(int i = 0; i < adjlist[node].size(); i++){
        print(adjlist[node][i], d + 1, adjlist, name);
    }

}

int main(){

    int n; cin >> n;
    vector<string> name(n);
    vector<vector<int> > adjlist(n);

    for(int i = 0; i < n; i++){
        int a; string s; cin >> a >> s;
        
        a--;
        name[i] = s;
        if(a == -1) continue;
        adjlist[a].push_back(i);
    }

    print(0, 0, adjlist, name);
    return 0;
}
