#include <bits/stdc++.h>
using namespace std;
const int MAX_L = (int)(1e5);
int L, p, q;
char buf[MAX_L + 1];
char ans[4 * MAX_L + 1];
void init() {
  scanf("%*d ");
  char tmp[20];
  for (; scanf(" %s ", tmp) != EOF;) {
    if (tmp[0] == 'p' || tmp[0] == 'i') {
      buf[L++] = tmp[0];
    }
  }
}
bool type() {
  if (buf[p] == 'p') {
    strcat(ans + q, "pair<");
    q += 5;
    ++p;
    if (!type()) {
      return false;
    }
    strcat(ans + q, ",");
    ++q;
    if (!type()) {
      return false;
    }
    strcat(ans + q, ">");
    ++q;
  } else if (buf[p] == 'i') {
    strcat(ans + q, "int");
    q += 3;
    ++p;
  } else {
    return false;
  }
  return true;
}
void solve() {
  if (type() && p == L) {
    puts(ans);
  } else {
    puts("Error occurred");
  }
}
int main() {
  init();
  solve();
  return 0;
}
