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