#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
string nxt() {
  string s;
  if (cin >> s) {
    return s;
  } else {
    return "";
  }
}
struct node {
  int l, r;
  node() { l = r = 0; }
} a[1000010];
int write(int x) {
  if (a[x].l == 0) {
    cout << "int";
  } else {
    cout << "pair<";
    write(a[x].l);
    cout << ",";
    write(a[x].r);
    cout << ">";
  }
}
int cnt = 0;
int n;
int x = -1;
int parse() {
  x++;
  string s = nxt();
  if (s == "") {
    puts("Error occurred");
    exit(0);
  } else {
    if (s == "pair") {
      a[x].l = x + 1;
      a[x].r = parse() + 1;
      int kkkkk = parse();
    } else {
      cnt++;
    }
  }
  return x;
}
int main() {
  cin >> n;
  parse();
  if (nxt() != "") {
    puts("Error occurred");
  } else {
    write(0);
    puts("");
  }
  return 0;
}
