#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second > b.second;
}
using namespace std;
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans *= a;
    b = b / 2;
    a *= a;
  }
  return ans;
}
bool ok = true;
string s, ans;
void input() {
  if (cin >> s) {
    if (s == "pair") {
      ans += "pair<";
      input();
      ans += ",";
      input();
      ans += ">";
    } else if (s == "int")
      ans += "int";
  } else
    ok = false;
}
int main() {
  getline(cin, s);
  input();
  if (!ok) ans = "Error occurred";
  getline(cin, s);
  if (!s.empty()) ans = "Error occurred";
  cout << ans << endl;
}
