#include <bits/stdc++.h>
using namespace std;
stack<int> stk;
string ans;
int main() {
  int n, f = 0, tmp, fl = 0;
  string c;
  string str;
  cin >> n;
  while (cin >> c) {
    if (fl) {
      puts("Error occurred");
      return 0;
    }
    str = c;
    if (str == "pair") {
      while (!stk.empty() && stk.top() == 2) {
        ans += ">";
        stk.pop();
      }
      if (stk.empty() && f) {
        puts("Error occurred");
        return 0;
      }
      if (!stk.empty()) {
        if (stk.top() == 1) ans += ",";
        tmp = stk.top();
        stk.pop();
        stk.push(tmp + 1);
      }
      stk.push(0);
      ans += "pair<";
    } else {
      while (!stk.empty() && stk.top() == 2) {
        ans += ">";
        stk.pop();
      }
      if (stk.empty() && f) {
        puts("Error occurred");
        return 0;
      }
      if (stk.empty())
        fl = 1;
      else {
        if (stk.top() == 1) ans += ",";
        tmp = stk.top();
        stk.pop();
        stk.push(tmp + 1);
      }
      ans += "int";
    }
    f = 1;
  }
  while (!stk.empty() && stk.top() == 2) {
    ans += ">";
    stk.pop();
  }
  if (!stk.empty()) {
    puts("Error occurred");
    return 0;
  }
  cout << ans << endl;
  return 0;
}
