#include <bits/stdc++.h>
using namespace std;
vector<string> v;
vector<char> res;
map<char, string> m1;
bool judge(int& cur, int site) {
  bool ans = true;
  if (v[cur] == "int") {
    if (cur == 0) return false;
    res.push_back('i');
  } else {
    res.push_back('p');
    res.push_back('<');
    if ((cur + 1) >= (int)v.size()) return false;
    ans = ans && judge(++cur, 0);
    res.push_back(',');
    if ((cur + 1) >= (int)v.size()) return false;
    ans = ans && judge(++cur, 1);
    res.push_back('>');
  }
  return ans;
}
int main() {
  int n;
  m1['i'] = "int";
  m1['p'] = "pair";
  m1['<'] = "<";
  m1['>'] = ">";
  m1[','] = ",";
  while (cin >> n) {
    int cnt = 0;
    string s;
    v.clear();
    res.clear();
    while (cin >> s) {
      if (s == "int") cnt++;
      v.push_back(s);
    }
    if (cnt == 1 && v[0] == "int" && v.size() == 1) {
      cout << "int" << endl;
      continue;
    }
    int cur = 0;
    if (judge(cur, 1) && cur + 1 == (int)v.size()) {
      for (int i = 0; i < (int)res.size(); i++) cout << m1[res[i]];
      cout << endl;
    } else {
      cout << "Error occurred" << endl;
    }
  }
  return 0;
}
