#include <bits/stdc++.h>
std::string Ans, Now;
int cnt = 1, Tol;
void DFS() {
  if (std::cin >> Now) {
    if (Now == "pair") {
      Ans += "pair<";
      DFS();
      Ans += ",";
      DFS();
      Ans += '>';
      ++cnt;
    } else if (Now == "int") {
      Ans += Now;
    }
  }
}
int main() {
  std::cin.sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cin >> Tol;
  DFS();
  if (cnt == Tol && std::cin >> Now) {
    std::puts("Error occurred");
  } else if (cnt == Tol) {
    std::cout << Ans << std::endl;
  } else {
    std::puts("Error occurred");
  }
  return 0;
}
