#include <bits/stdc++.h>
using namespace std;
string ans, s;
stack<int> stk;
int n;
bool push2() {
  if (stk.empty()) {
    stk.push(2);
    return true;
  }
  if (stk.top() == 1) {
    stk.pop();
    if (stk.empty()) return false;
    stk.pop();
    ans.append(">");
    return push2();
  } else if (stk.top() == 2) {
    stk.pop();
    if (stk.empty()) return false;
    stk.pop();
    ans.append(">");
    return push2();
  } else if (stk.top() == 3) {
    stk.push(2);
    return true;
  }
}
bool push1() {
  if (stk.empty()) {
    stk.push(1);
    ans.append("int");
    return true;
  }
  if (stk.top() == 1) {
    stk.pop();
    if (stk.empty()) return false;
    stk.pop();
    ans.append(",int>");
    return push2();
  } else if (stk.top() == 2) {
    stk.pop();
    if (stk.empty()) return false;
    stk.pop();
    ans.append(",int>");
    return push2();
  } else if (stk.top() == 3) {
    stk.push(1);
    ans.append("int");
    return true;
  }
}
bool push3() {
  if (stk.empty()) {
    stk.push(3);
    ans.append("pair<");
    return true;
  }
  if (stk.top() == 1) {
    stk.push(3);
    ans.append(",pair<");
    return true;
  } else if (stk.top() == 2) {
    stk.push(3);
    ans.append(",pair<");
    return true;
  } else if (stk.top() == 3) {
    stk.push(3);
    ans.append("pair<");
    return true;
  }
}
int main() {
  cin >> n;
  int sum = 0;
  bool flag = 0;
  while (cin >> s) {
    if (s == "pair") {
      if (!push3()) flag = 1;
    } else if (s == "int") {
      sum++;
      if (!push1()) flag = 1;
      if (sum == n) break;
    }
  }
  while (cin >> s) flag = 1;
  if (stk.size() != 1) flag = 1;
  if (flag == 1)
    cout << "Error occurred" << endl;
  else
    cout << ans << endl;
  return 0;
}
