#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
string s[1001];
bool visited[1001];
void dfs(vector<vector<int> > &g, string *s, int depth, int node){
  if(visited[node])return;
  visited[node] = true;
  for (int i = 0; i < depth; i++)
    std::cout << ".";

  std::cout << s[node] << std::endl;
  for (int i = 0; i < g[node].size(); i++) {
    dfs(g, s, depth + 1, g[node][i]);
  }
  return;
}

int main(int argc, char *argv[]){
  int n;
  cin >> n;
  vector<vector<int> > g;
  g.resize(n + 1);
  int k;
  cin >> k >> s[0];
  for (int i = 1; i < n; i++) {
    cin >> k >> s[i];
    g[k - 1].push_back(i);
  }
  dfs(g, s, 0, 0);
  return 0;
}