#include <bits/stdc++.h>
int n, cnt, x = 1;
int a[2000000] = {0};
char in[10];
void go(int p) {
  if (p == 0) {
    printf("Error occurred");
    exit(0);
  }
  if (p == 2)
    ;
  else {
    go(a[++x]);
    go(a[++x]);
  }
}
void print(int p) {
  if (!p) return;
  if (p == 2) {
    printf("int");
  } else {
    printf("pair");
    printf("<");
    print(a[++x]);
    printf(",");
    print(a[++x]);
    printf(">");
  }
}
int main() {
  int i, j;
  scanf("%d", &n);
  while (scanf("%s", &in) != EOF) {
    if (in[0] == 'p') {
      a[++cnt] = 1;
    } else {
      a[++cnt] = 2;
    }
  }
  go(a[1]);
  if (x != cnt) {
    printf("Error occurred");
    return 0;
  }
  x = 1;
  print(a[1]);
  return 0;
}
