#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

vector<string> name;
vector<vector<int>> G;
void rec(int n,int dep){
    cout << string(dep,'.') << name[n] << endl;
    for(auto next:G[n]){
        rec(next,dep+1);
    }
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    name.resize(n);
    G.resize(n);
    for(int i = 0; i < n;i++){
        int p; cin >> p;
        string S; cin >> S;
        name[i] = S;
        if(p == 0) continue;
        p--;
        G[p].push_back(i);
    }
    rec(0,0);
    return 0;
}

