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