#include <bits/stdc++.h>
using namespace std;
string ans, s;
bool has = true;
void f() {
  if (cin >> s) {
    if (s == "pair") {
      ans += "pair<";
      f();
      ans += ",";
      f();
      ans += ">";
    } else {
      ans += "int";
    }
  } else {
    has = false;
  }
}
int main() {
  int n;
  cin >> n;
  f();
  string s;
  if (!has || cin >> s) {
    puts("Error occurred");
  } else {
    puts(ans.c_str());
  }
  return 0;
}
