#include <iostream>
#include <cstring>
using namespace std;
const int N = 100010;
string ans;
bool dfs()
{
char str[5];
if(scanf("%s", str) == -1) return false; //如果没有读到字符串,证明无解
if(!strcmp(str, "pair"))
{
ans += str;
ans += "<";
if(!dfs()) return false;
ans += ",";
if(!dfs()) return false;
ans += ">";
}
else ans += str;
return true;
}
int main()
{
scanf("%*d"); // 过滤一个整数型的输入,也就是n
if(dfs() && scanf("%*s") == -1) cout << ans;
else puts("Error occurred");
return 0;
}