rt
#include <bits/stdc++.h>
using namespace std;
#define F(i,j,k) for (signed i=signed(j);i<=signed(k);i++)
#define endl '\n'
int n;
string s;
string stk[100005];
int top;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
while(cin>>s){
stk[++top]=s;
if(s=="int"){
while(top>=3&&stk[top-1]!="pair"&&stk[top-2]=="pair"){
string tmp=stk[top-2]+"<"+stk[top-1]+","+stk[top]+">";
top-=2;
stk[top]=tmp;
stk[top+1]=stk[top+2]="";
}
}
}
cout<<(top==1?stk[top]:"Error occurred")<<endl;
return 0;
}