#include <bits/stdc++.h>
using namespace std;
int n, flg;
string s, ans;
void make() {
  if (cin >> s) {
    ans += s;
    if (s == "pair") {
      ans += '<';
      make();
      ans += ',';
      make();
      ans += '>';
    }
    return;
  } else
    flg = 1;
  return;
}
int main() {
  cin >> n;
  ans = "";
  flg = 0;
  make();
  if (flg || cin >> s)
    cout << "Error occurred" << endl;
  else
    cout << ans << endl;
  return 0;
}
