#include <bits/stdc++.h>
using namespace std;
string s;
string a;
bool k = true;
void dfs() {
  if (cin >> a) {
    if (a == "pair") {
      s += "pair<";
      dfs();
      s += ",";
      dfs();
      s += ">";
    } else if (a == "int") {
      s += "int";
    }
  } else
    k = false;
}
int main() {
  getline(cin, a);
  dfs();
  if (!k) {
    cout << "Error occurred" << endl;
    return 0;
  }
  getline(cin, a);
  if (a.size()) {
    cout << "Error occurred" << endl;
    return 0;
  }
  cout << s << endl;
}
