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