#include <bits/stdc++.h>
using namespace std;
struct NODE {
  int ch[2];
  int x;
  void clear() { x = 0; }
} tr[1000000];
int sz;
char buf[1000000];
istringstream is;
bool dfs(NODE &p) {
  string w;
  for (int c = 0; c < (2); ++c) {
    if (c == 1 && (&p) == (&tr[0])) break;
    if (is >> w) {
      p.x = c + 1;
      p.ch[c] = sz;
      tr[sz++].clear();
      if (w[0] == 'p') {
        if (!dfs(tr[p.ch[c]])) return false;
      }
    } else {
      return false;
    }
  }
  if (&p == &tr[0] && is >> w) {
    return false;
  } else {
    return true;
  }
}
void show(int x) {
  if (tr[x].x == 0) {
    cout << "int";
    return;
  } else {
    cout << "pair<";
    show(tr[x].ch[0]);
    cout << ",";
    show(tr[x].ch[1]);
    cout << ">";
  }
}
int main() {
  int n;
  while (cin >> n) {
    is.clear();
    sz = 0;
    tr[sz++].clear();
    fgets(buf, sizeof(buf), stdin);
    fgets(buf, sizeof(buf), stdin);
    is.str(string(buf));
    if (dfs(tr[0]))
      show(tr[0].ch[0]), cout << "\n";
    else
      cout << "Error occurred\n";
  }
  return 0;
}
