#include <bits/stdc++.h>
using namespace std;
string result;
bool check() {
  static string str;
  if (cin >> str) {
    if (str == "pair") {
      result += "pair<";
      check();
      result += ',';
      return check() ? result += '>', true : false;
    } else if (str == "int")
      return result += "int", true;
  }
  return false;
}
int main() {
  string tmp;
  return cin >> tmp && check() && !(cin >> tmp) ? puts(result.c_str()),
         0                                      : puts("Error occurred"), 0;
}
