#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

struct Thread {
    int id, children;
    string s;
};

int main() {
    int n;
    cin >> n;
    vector<Thread> th;
    vi indent(n+1);
    FOR(id, 1, n+1) {
        int k;
        string s;
        cin >> k >> s;

        bool inserted = false;
        REP(i, SZ(th)) {
            Thread& t = th[i];
            if (t.id == k) {
                int level = t.children;
                FOR(j, i+1, SZ(th)) {
                    if (indent[th[j].id] <= indent[t.id]) break;
                    level += th[j].children;
                }

                t.children++;
                th.insert(th.begin()+i+1+level, {id, 0, s});
                inserted = true;
                break;
            }
        }
        if (!inserted) {
            th.push_back({id, 0, s});
        }
        if (k == 0) {
            indent[id] = 0;
        } else {
            indent[id] = indent[k] + 1;
        }
//        for (auto t : th) {
//            REP(i, indent[t.id]) {
//                LOG(".");
//            }
//            LOG("%s (%d)\n", t.s.c_str(), t.children);
//        }
//        LOG("---------------\n");
    }

    for (auto t : th) {
        REP(i, indent[t.id]) {
            cout << ".";
        }
        cout << t.s << endl;
    }
}