#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128000000")
using namespace std;
const int INF = 1000000000;
typedef struct zap {
  int p;
  zap *left, *right, *rod;
};
char s[100];
zap *top = 0, *temp = 0;
int dfs(zap *t) {
  if (t->p == 0) {
    printf("int");
    return 0;
  }
  printf("pair<");
  dfs(t->left);
  printf(",");
  dfs(t->right);
  printf(">");
  return 0;
}
int main() {
  int k, i, v, j, x, y, to, n, r, p, l, fl, m;
  scanf("%i", &n);
  fl = 0;
  while (scanf("%s", &s) != EOF) {
    if (fl) {
      printf("Error occurred\n");
      return 0;
    }
    if (!top) {
      top = new zap;
      top->left = top->rod = top->right = 0;
      if (s[0] == 'p')
        top->p = 1;
      else
        top->p = 0;
      temp = top;
      if (top->p == 0) fl = 1;
      continue;
    }
    zap *newe = new zap;
    if (s[0] == 'p')
      newe->p = 1;
    else
      newe->p = 0;
    newe->left = newe->right = newe->rod = 0;
    newe->rod = top;
    if (!top->left) {
      top->left = newe;
      top = newe;
    } else if (!top->right) {
      top->right = newe;
      top = newe;
    }
    while (top->p == 0 || (top->left && top->right)) {
      if (top == temp) {
        fl = 1;
        break;
      }
      top = top->rod;
    }
  }
  if (top != temp || (top->p && (!top->left || !top->right))) {
    printf("Error occurred\n");
    return 0;
  }
  dfs(top);
  return 0;
}
