#include <bits/stdc++.h>
using namespace std;
template <typename... T>
inline void inp(T &...args) {
  ((cin >> args), ...);
}
template <typename T>
inline istream &operator>>(istream &in, vector<T> &a) {
  for (auto &x : a) in >> x;
  return in;
}
template <typename T, typename U>
inline istream &operator>>(istream &in, pair<T, U> &a) {
  in >> a.first >> a.second;
  return in;
}
long long int n;
string ans;
bool err;
int dfs() {
  11;
  string s;
  if (cin >> s) {
    if (s == "pair") {
      ans += "pair<";
      if (dfs()) {
        err = true;
        return 1;
      }
      ans += ",";
      if (dfs()) {
        err = true;
        return 1;
      }
      ans += ">";
    } else {
      n--;
      ans += "int";
    }
    return 0;
  }
  return 1;
}
void solve(long long int &T) {
  cin >> n;
  ans.clear();
  err = false;
  dfs();
  string s;
  if (cin >> s) err = true;
  if (n != 0) err = true;
  cout << (err ? "Error occurred" : ans) << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  for (long long int i = (1); i < (t + 1); i++) {
    if (0) cerr << "Case #" << i << "\n";
    solve(i);
  }
  return 0;
}
