#include <bits/stdc++.h>
bool ok = true;
std::string s, ans;
void input() {
  if (std::cin >> s) {
    if (s == "pair") {
      ans += "pair<";
      input();
      ans += ",";
      input();
      ans += ">";
    } else if (s == "int")
      ans += "int";
  } else
    ok = false;
}
int main() {
  std::getline(std::cin, s);
  input();
  if (!ok) ans = "Error occurred";
  std::getline(std::cin, s);
  if (s.size()) ans = "Error occurred";
  std::cout << ans << std::endl;
}
