#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 6;
typedef struct typ {
  int ty;
  int nex[2];
} typ;
typ t[maxn];
char s[20];
int n, temp1, temp2, ans;
stack<int> sta;
void output(int x);
int main() {
  scanf("%d", &n);
  n = 0;
  while (~scanf("%s", s + 1)) {
    n++;
    if (s[1] == 'i') {
      t[n].ty = 1;
    } else {
      t[n].ty = 2;
    }
  }
  if (n == 1 && t[1].ty == 1) {
    printf("int");
    return 0;
  }
  for (int i = n; i >= 1; i--) {
    if (t[i].ty == 1) {
      if (sta.empty() && i != n) {
        printf("Error occurred\n");
        return 0;
      }
      sta.push(i);
      continue;
    }
    if (sta.empty()) {
      printf("Error occurred\n");
      return 0;
    }
    temp1 = sta.top();
    sta.pop();
    if (sta.empty()) {
      printf("Error occurred\n");
      return 0;
    }
    temp2 = sta.top();
    sta.pop();
    t[i].nex[0] = temp1, t[i].nex[1] = temp2;
    sta.push(i);
  }
  if (sta.size() != 1) {
    printf("Error occurred\n");
    return 0;
  }
  ans = sta.top();
  sta.pop();
  output(ans);
  return 0;
}
void output(int x) {
  if (t[x].ty == 1) {
    printf("int");
    return;
  }
  printf("pair<");
  output(t[x].nex[0]);
  printf(",");
  output(t[x].nex[1]);
  printf(">");
  return;
}
