#include <bits/stdc++.h>
using namespace std;
string nxt() {
  string s;
  if (!(cin >> s)) return "";
  return s;
}
struct node {
  node *l, *r;
  node() { l = r = 0; }
  void write() {
    if (l == 0)
      printf("int");
    else {
      printf("pair<");
      l->write();
      printf(",");
      r->write();
      printf(">");
    }
  }
};
int cnt;
node* parse() {
  string s = nxt();
  if (s == "") {
    puts("Error occurred");
    exit(0);
  }
  if (s == "int") {
    ++cnt;
    return new node;
  } else {
    node* t = new node;
    t->l = parse();
    t->r = parse();
    return t;
  }
}
int main() {
  int n;
  cin >> n;
  cnt = 0;
  node* t = parse();
  if (nxt() != "")
    puts("Error occurred");
  else {
    t->write();
    puts("");
  }
  delete t;
  return 0;
}
