#include <bits/stdc++.h>
using namespace std;
int n;
string s, t, ans;
bool fail;
void get() {
  s = "";
  cin >> s;
  if (s == "int")
    ans += "int";
  else if (s == "pair") {
    ans += "pair<";
    get();
    ans += ",";
    get();
    ans += ">";
  } else
    fail = 1;
}
void solve() {
  cin >> s;
  get();
  if (fail) ans = "Error occurred";
  s = "";
  cin >> s;
  if (s.size()) ans = "Error occurred";
  cout << ans;
}
int main() {
  int T;
  T = 1;
  while (T--) solve();
  return 0;
}
