#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef stringstream ss;
typedef priority_queue<pii, vector<pii>, greater<pii> > PQ;

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define clr(t,v) memset((t),(v),sizeof(t))
#define p(a) cout << #a << ": " << a << endl;

#define rep(i,n) for(int i=0,_##i=(n);i<_##i;++i)
#define dwn(i,n) for(int i=(n);--i>=0;)
#define repr(i,l,r) for(int i=(l),_##i=(r);i<_##i;++i)
#define dwnr(i,l,r) for(int i=(r),_##i=(l);--i>=_##i;)
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(),_##i=(a).end();i!=_##i;++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(),_##i=(a).rend();i!=_##i;++i)
const int inf = 1 << 30;
char buf[1000];
string nextLine(int length = 100) {
	cin.getline(buf, length);
	string s(buf);
	return s;
}
string next(int length = 100) {
	string tmp;
	cin >> tmp;
	return tmp;
}

int nextInt() {
	int tmp;
	scanf("%d", &tmp);
	return tmp;
}
vector<string> tokens;
bool done = false;
string ret;
int find(int ind) {
	if (ind >= sz(tokens)) {
		done = true;
	}
	if (done) {
		return 0;
	}
	if (tokens[ind] == "int") {
		ret += "int";
		return ind + 1;
	} else {
		ret += "pair<";
		int p = find(ind + 1);
		ret += ",";
		int p2 = find(p);
		ret += ">";
		return p2;
	}
}
int main() {
	int n = nextInt();
	int c = 0;
	while (c < n) {
		string n = next();
		if (n == "int") {
			c++;
		}
		tokens.pb(n);
	}
	if (find(0) == sz(tokens) && !done) {
		cout << ret << endl;
	} else {
		cout << "Error occurred" << endl;
	}
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef stringstream ss;
typedef priority_queue<pii, vector<pii>, greater<pii> > PQ;

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define clr(t,v) memset((t),(v),sizeof(t))
#define p(a) cout << #a << ": " << a << endl;

#define rep(i,n) for(int i=0,_##i=(n);i<_##i;++i)
#define dwn(i,n) for(int i=(n);--i>=0;)
#define repr(i,l,r) for(int i=(l),_##i=(r);i<_##i;++i)
#define dwnr(i,l,r) for(int i=(r),_##i=(l);--i>=_##i;)
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(),_##i=(a).end();i!=_##i;++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(),_##i=(a).rend();i!=_##i;++i)
const int inf = 1 << 30;
char buf[1000];
string nextLine(int length = 100) {
	cin.getline(buf, length);
	string s(buf);
	return s;
}
string next(int length = 100) {
	string tmp;
	cin >> tmp;
	return tmp;
}

int nextInt() {
	int tmp;
	scanf("%d", &tmp);
	return tmp;
}
string bro() {
	int n = nextInt();
	int c = 1, c2 = 0;
	string s, sep;
	string ret;
	while (c2 < n) {
		if ((s = next()) == "pair") {
			sep = "<";
			c++;
		} else {
			if (sep == "<")
				sep = ",";
			else
				sep = ">,";
			c--;
			c2++;
		}
		if (c <= 0) {
			return "Error occurred";
		}
		ret += s;
		ret += sep;
	}
	if (c)
		return "Error occurred";
	return ret.substr(0, ret.size() - 1);
}

int main() {
	cout << bro() << endl;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef stringstream ss;
typedef priority_queue<pii, vector<pii>, greater<pii> > PQ;

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define clr(t,v) memset((t),(v),sizeof(t))
#define p(a) cout << #a << ": " << a << endl;

#define rep(i,n) for(int i=0,_##i=(n);i<_##i;++i)
#define dwn(i,n) for(int i=(n);--i>=0;)
#define repr(i,l,r) for(int i=(l),_##i=(r);i<_##i;++i)
#define dwnr(i,l,r) for(int i=(r),_##i=(l);--i>=_##i;)
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(),_##i=(a).end();i!=_##i;++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(),_##i=(a).rend();i!=_##i;++i)
const int inf = 1 << 30;
char buf[1000];
string nextLine(int length = 100) {
	cin.getline(buf, length);
	string s(buf);
	return s;
}
string next(int length = 100) {
	string tmp;
	cin >> tmp;
	return tmp;
}

int nextInt() {
	int tmp;
	scanf("%d", &tmp);
	return tmp;
}
vector<string> tokens;
bool done = false;
pair<string, int> find(int ind) {
	if (ind >= sz(tokens)) {
		cout << "Error occurred" << endl;
		done = true;
	}
	if (done) {
		return mp(string(), 0);
	}
	if (tokens[ind] == "int")
		return pair<string, int>(tokens[ind], ind + 1);
	else {
		string ret = "pair<";
		pair<string, int> p = find(ind + 1);
		pair<string, int> p2 = find(p.se);
		ret += p.fi + "," + p2.fi + ">";
		return mp(ret, p2.se);
	}
}
int main() {
	int n = nextInt();
	int c = 0;
	while (c < n) {
		string n = next();
		if (n == "int") {
			c++;
		}
		tokens.pb(n);
	}
	pair<string, int> p = find(0);
	if (!done) {
		if (p.se == sz(tokens)) {
			cout << "Error occurred" << endl;
		}
		cout << p.fi<<endl;
	}
}


#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
string s,x;
int t;
void f()
{
	if(cin>>s)
	{
		x+=s;
		if(s=="pair")
		{
			x+="<";
			f();
			x+=",";
			f();
			x+=">";
		}
	}
	else
		t=1;
}
int main()
{
	int q;
	cin>>q;
	cin>>s;
	f();
	if(t||cin>>s)
		puts("Error occurred");
	else
		puts(x.c_str());
	return 0;
}


#include<cstdlib>
#include<numeric>
#include<memory>
#include<new>
#include<typeinfo>
#include<functional>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<deque>
#include<exception>
#include<iterator>
#include<cctype>
#include<sstream>
#include<list>
#include<stdexcept>
#include<utility>
#include<map>
#include<set>
#include<fstream>
#include<stdexcept>
#include<queue>
#include<cstddef>
#include<string>
#include<cstring>
#include<stdio.h>
#include<vector>
#include<cstdio>
using namespace std;
int k,n,m,x,y,minutes;
char aa[20][20][20];
void cqy(int a,int b,int c)
{
	if(a<0||b<0||c<0||a>=k||b>=n||c>=m||aa[a][b][c]=='#')
		return;
	minutes++;
	cqy(a+1,b,c);
	cqy(a-1,b,c);
	cqy(a,b-1,c);
	cqy(a,b+1,c);
	cqy(a,b,c+1);
	cqy(a,b,c-1);
}
int main()
{
	cin>>k>>n>>m;
	for(int i=0;i<k;i++)
	{
		for(int j=0;j<n;j++)
			cin>>aa[i][j];
	}
	cin>>x>>y;
	cqy(0,x-1,y-1);
	cout<<minutes<<"\n";
	return 0;
}


#include <cmath>
#include <math.h>
#include <ctype.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define LL long long
using namespace std;
int n,c,q;
string s,a[100005],ans;
void hhh(){
//	if(ans=="Error occurred") return;
	q++;
	if(q>c){
		ans="Error occurred";
		return;
	}
	ans+=a[q];
	if(a[q]=="pair"){
		ans+='<';
		hhh();
		if(ans=="Error occurred") return;
		ans+=',';
		hhh();
		if(ans=="Error occurred") return;
		ans+='>';
	}
}
int main(){
	getline(cin,s);
	getline(cin,s);
	for(int i=0;i<s.size();i++){
		if(s[i]==' ') c++;
		else a[c]+=s[i];
	}
	if(a[0]=="int"&&c>0){
		cout<<"Error occurred\n";
		return 0;
	}
	q=-1;
	hhh();
	cout<<ans<<endl;
	return 0;
}


#include <cmath>
#include <math.h>
#include <ctype.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define LL long long
using namespace std;
stack<int> stk;
string ans;
int main(){
	int n,tmp,f=0,f1=0;
	char c[10];
	string str;
	cin>>n;
	while(scanf("%s",&c)==1){
		if(f1){
			printf("Error occurred\n");
			return 0;
		}
		str=c;
		if(str=="pair"){
			while(!stk.empty()&&stk.top()==2){
				ans+=">";
				stk.pop();
			}
			if(stk.empty()&&f){
				printf("Error occurred\n");
				return 0;
			}
			if(!stk.empty()){
				if(stk.top()==1) ans+=",";
				tmp=stk.top();
				stk.pop();
				stk.push(tmp+1);
			}
			stk.push(0);
			ans+="pair<";
		}
		else{
			while(!stk.empty()&&stk.top()==2){
				ans+=">";
				stk.pop();
			}
			if(stk.empty()&&f){
				printf("Error occurred\n");
				return 0;
			}
			if(stk.empty()) f1=1;
			else{
				if(stk.top()==1) ans+=",";
				tmp=stk.top();
				stk.pop();
				stk.push(tmp+1);
			}
			ans+="int";
		}
		f=1;
	}
	while(!stk.empty()&&stk.top()==2){
		ans+=">";
		stk.pop();
	}
	if(!stk.empty()){
		printf("Error occurred\n");
		return 0;
	}
	cout<<ans;
	return 0;
}


#include <cmath>
#include <math.h>
#include <ctype.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define LL long long
using namespace std;
int n,c,q;
string s,a[100005],ans;
void hhh(){
//	if(ans=="Error occurred") return;
	q++;
	if(q>c){
		ans="Error occurred";
		return;
	}
	ans+=a[q];
	if(a[q]=="pair"){
		ans+='<';
		hhh();
		if(ans=="Error occurred") return;
		ans+=',';
		hhh();
		if(ans=="Error occurred") return;
		ans+='>';
	}
}
int main(){
	getline(cin,s);
	getline(cin,s);
	for(int i=0;i<s.size();i++){
		if(s[i]==' ') c++;
		else a[c]+=s[i];
	}
	if(a[0]=="int"){
		cout<<"Error occurred\n";
		return 0;
	}
	q=-1;
	hhh();
	cout<<ans<<endl;
	return 0;
}


#include <cmath>
#include <math.h>
#include <ctype.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define LL long long
using namespace std;
stack<int> stk;
string ans,str;
int n,f,ff,tmp;
char c[10];
int main(){
	scanf("%d",&n);
	while(scanf("%s",&c)){
		if(ff){
			printf("Error occurred\n");
			return 0;
		}
		str=c;
		if(str=="pair"){
			while(!stk.empty()&&stk.top()==2){
				ans+=">";
				stk.pop();
			}
			if(stk.empty()&&f){
				printf("Error occurred\n");
				return 0;
			}
			if(!stk.empty()){
				if(stk.top()==1) ans+=",";
				tmp=stk.top();
				stk.pop();
				stk.push(tmp+1);
			}
			stk.push(0);
			ans+="pair<";
		}
		else{
			while(!stk.empty()&&stk.top()==2){
				ans+=">";
				stk.pop();
			}
			if(stk.empty()&&f){
				printf("Error occurred\n");
				return 0;
			}
			if(stk.empty()) ff=1;
			else{
				if(stk.top()==1) ans+=",";
				tmp=stk.top();
				stk.pop();
				stk.push(tmp+1);
			}
			ans+="int";
		}
		f=1;
	}
	while(!stk.empty()&&stk.top()==2){
		ans+=">";
		stk.pop();
	}
	if(stk.empty()&&f){
		printf("Error occurred\n");
		return 0;
	}
	puts(ans.c_str());
	return 0;
}


#include <cmath>
#include <math.h>
#include <ctype.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define LL long long
using namespace std;
int n,c,q;
string s,a[100005],ans;
void hhh(){
//	if(ans=="Error occurred") return;
	q++;
	if(q>c){
		ans="Error occurred";
		return;
	}
	ans+=a[q];
	if(a[q]=="pair"){
		ans+='<';
		hhh();
		if(ans=="Error occurred") return;
		ans+=',';
		hhh();
		if(ans=="Error occurred") return;
		ans+='>';
	}
}
int main(){
	getline(cin,s);
	getline(cin,s);
	for(int i=0;i<s.size();i++){
		if(s[i]==' ') c++;
		else a[c]+=s[i];
	}
//	if(a[0]=="int"){
//		cout<<"Error occurred\n";
//		return 0;
//	}
	q=-1;
	hhh();
	cout<<ans<<endl;
	return 0;
}


#include <cmath>
#include <math.h>
#include <ctype.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define LL long long
using namespace std;
stack<int> stk;
string ans,str;
int n,f,ff,tmp;
char c[10];
int main(){
	scanf("%d",&n);
	while(scanf("%s",&c)){
		if(ff){
			printf("Error occurred\n");
			return 0;
		}
		str=c;
		if(str=="pair"){
			while(!stk.empty()&&stk.top()==2){
				ans+=">";
				stk.pop();
			}
			if(stk.empty()&&f){
				printf("Error occurred\n");
				return 0;
			}
			if(!stk.empty()){
				if(stk.top()==1) ans+=",";
				tmp=stk.top();
				stk.pop();
				stk.push(tmp+1);
			}
			stk.push(0);
			ans+="pair<";
		}
		else{
			while(!stk.empty()&&stk.top()==2){
				ans+=">";
				stk.pop();
			}
			if(stk.empty()&&f){
				printf("Error occurred\n");
				return 0;
			}
			if(stk.empty()) ff=1;
			else{
				if(stk.top()==1) ans+=",";
				tmp=stk.top();
				stk.pop();
				stk.push(tmp+1);
			}
			ans+="int";
		}
		f=1;
	}
	while(!stk.empty()&&stk.top()==2){
		ans+=">";
		stk.pop();
	}
	if(!stk.empty()){
		printf("Error occurred\n");
		return 0;
	}
	puts(ans.c_str());
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
struct arr {
    int x;
    string s;
};
string res;
struct arr func(vector <string> a, int i) {
    int n = a.size();
    struct arr t;
    t.s = "";
    t.x = -1;
    if (i >= n) {
        //cout << i << " 1" << endl;
        t.x = -1;
        t.s = "";
        return t;
    }
    if (i + 2 < n && a[i] == "pair" && a[i + 1] == "int" && a[i + 2] == "int") {
        //cout << i << " 2" << endl;
        res += "pair<int,int>";
        t.s = "pair<int,int>";
        t.x = i + 3;
        return t;
    }
    if (a[i] == "int") {
        //cout << i << " 3" << endl;
        t.s = "int";
        t.x = i + 1;
        return t;
    }
    if (a[i] == "pair") {
        struct arr l = func(a, i + 1);
        if (l.x == -1) {
            //cout << i << " 4" << endl;
            t.x = -1;
            t.s = "";
            return t;
        }
        struct arr r = func(a, l.x);
        if (r.x == -1) {
            //cout << i << " 5" << endl;
            t.x = -1;
            t.s = "";
            return t;
        }
        //cout << i << "6 " << endl;
        t.s = "pair<" + l.s + "," + r.s + ">";
        t.x = r.x;
        return t;
    }
    //cout << i << " 7" << endl;
    t.x = -1;
    t.s = "";
    return t;
}
int main() {
    vector <string> a;
    string s, str;
    char c;
    int i, j, m;
    cin >> m;
    getchar();
    while (true) {
        c = getchar();
        if (c == '\n')
            break;
        if (c == ' ') {
            a.push_back(str);
            str = "";
        }
        else
            str += c;
    }
    if ((int)str.size()){
        a.push_back(str);
    }
    /*for (i = 0; i < a.size(); i++) {
        cout << a[i] << " ";
    }
    cout << endl;*/
    //cout << a.size() << "--> " << endl;
    struct arr ans = func(a, 0);
    if (ans.x == -1) {
        cout << "Error occurred" << endl;
    }
    else {
        cout << ans.s << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
struct arr {
    int x;
    string s;
};
string a[100005];
int n;
struct arr func(int i) {
    struct arr t;
    t.s = "";
    t.x = -1;
    if (i >= n) {
        //cout << i << " 1" << endl;
        t.x = -1;
        t.s = "";
        return t;
    }
    if (i + 2 < n && a[i] == "pair" && a[i + 1] == "int" && a[i + 2] == "int") {
        //cout << i << " 2" << endl;
        t.s = "pair<int,int>";
        t.x = i + 3;
        return t;
    }
    if (a[i] == "int") {
        //cout << i << " 3" << endl;
        t.s = "int";
        t.x = i + 1;
        return t;
    }
    if (a[i] == "pair") {
        struct arr l = func(i + 1);
        if (l.x == -1) {
            //cout << i << " 4" << endl;
            t.x = -1;
            t.s = "";
            return t;
        }
        struct arr r = func(l.x);
        if (r.x == -1) {
            //cout << i << " 5" << endl;
            t.x = -1;
            t.s = "";
            return t;
        }
        //cout << i << "6 " << endl;
        t.s = "pair<" + l.s + "," + r.s + ">";
        t.x = r.x;
        return t;
    }
    //cout << i << " 7" << endl;
    t.x = -1;
    t.s = "";
    return t;
}
int main() {
    string s, str;
    char c;
    int i, j, m;
    cin >> m;
    getchar();
    j = 0;
    while (true) {
        c = getchar();
        if (c == '\n')
            break;
        if (c == ' ') {
            a[j++] = str;;
            str = "";
        }
        else
            str += c;
    }
    if ((int)str.size()){
        a[j++] = str;
    }
    n = j;
    /*for (i = 0; i < a.size(); i++) {
        cout << a[i] << " ";
    }
    cout << endl;*/
    //cout << a.size() << "--> " << endl;
    struct arr ans = func(0);
    if (ans.x == -1) {
        cout << "Error occurred" << endl;
    }
    else {
        cout << ans.s << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
int p;
string s;
vector <string> a;
int r, d, q;
void func() {
    string b;
    if (cin >> b) {
        s = s + b;
        if (b == "pair") {
            s = s + "<";
            func();
            s = s + ",";
            func();
            s = s + ">";
        }
    }
    else
        q = 1;
}
int main() {
    q = 0;
    int n;
    string b;
    cin >> n;
    func();
    cout << "yes" << endl;
    if (q || cin >> b) {
        cout << "Error occurred" << endl;
    }
    else
        cout << s << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
int p;
string s;
vector <string> a;
int r, d, q;
void func() {
    string b;
    if (cin >> b) {
        s = s + b;
        if (b == "pair") {
            s = s + "<";
            func();
            s = s + ",";
            func();
            s = s + ">";
        }
    }
    else
        q = 1;
}
int main() {
    q = 0;
    int n;
    string b;
    cin >> n;
    func();
//  cout << "yes" << endl;
    if (q || cin >> b) {
        cout << "Error occurred" << endl;
    }
    else
        cout << s << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
struct arr {
    int x;
    string s;
};
vector <string> a;
struct arr func(int i) {
    int n = a.size();
    struct arr t;
    t.s = "";
    t.x = -1;
    if (i >= n) {
        //cout << i << " 1" << endl;
        t.x = -1;
        t.s = "";
        return t;
    }
    if (i + 2 < n && a[i] == "pair" && a[i + 1] == "int" && a[i + 2] == "int") {
        //cout << i << " 2" << endl;
        t.s = "pair<int,int>";
        t.x = i + 3;
        return t;
    }
    if (a[i] == "int") {
        //cout << i << " 3" << endl;
        t.s = "int";
        t.x = i + 1;
        return t;
    }
    if (a[i] == "pair") {
        struct arr l = func(i + 1);
        if (l.x == -1) {
            //cout << i << " 4" << endl;
            t.x = -1;
            t.s = "";
            return t;
        }
        struct arr r = func(l.x);
        if (r.x == -1) {
            //cout << i << " 5" << endl;
            t.x = -1;
            t.s = "";
            return t;
        }
        //cout << i << "6 " << endl;
        t.s = "pair<" + l.s + "," + r.s + ">";
        t.x = r.x;
        return t;
    }
    //cout << i << " 7" << endl;
    t.x = -1;
    t.s = "";
    return t;
}
int main() {
    string s, str;
    char c;
    int i, j, m;
    cin >> m;
    getchar();
    while (true) {
        c = getchar();
        if (c == '\n')
            break;
        if (c == ' ') {
            a.push_back(str);
            str = "";
        }
        else
            str += c;
    }
    if ((int)str.size()){
        a.push_back(str);
    }
    /*for (i = 0; i < a.size(); i++) {
        cout << a[i] << " ";
    }
    cout << endl;*/
    //cout << a.size() << "--> " << endl;
    struct arr ans = func(0);
    if (ans.x == -1) {
        cout << "Error occurred" << endl;
    }
    else {
        cout << ans.s << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
string s, z;
int t;
void f()
{
    if (cin >> s)
    {
        z += s;
        if (s == "pair")
            z += "<", f(), z += ",", f(), z += ">";
    }
    else
        t = 1;
}
int main()
{
    cin >> s;
    f();
    if (t || cin >> s)
        puts("Error occurred");
    else
        puts(z.c_str());
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
int p;
string s;
vector <string> a;
int r, d, q;
void display(int n) {
    if (p >= n)
        return;
    int f = 0;
    if (a[p] == "pair") {
        s += "pair<";
        //      cout << "pair<" << endl;
        p++;
        r++;
        display(n);
    }
    else if (a[p] == "int") {
        s += "int";
        //  cout << "int" << endl;
        p++;
        f = 1;
    }
    if (p >= n) {
        if (f == 1)
            q = 1;
        return;
    }
    if (a[p] == "pair") {
        s += ",pair<";
        //      cout << ",pair<" << endl;
        p++;
        r++;
        display(n);
    }
    else if (a[p] == "int") {
        //  cout << ",int" << endl;
        s += ",int";
        p++;
    }
    s += ">";
    d++;
    return;
}
int main() {
    int i, j;
    string str;
    int n;
    char c;
    r = 0;
    d = 0;
    q = 0;
    scanf("%d\n", &j);
    while (true) {
        c = getchar();
        if (c == '\n')
            break;
        if (c == ' ') {
            a.push_back(str);
            str = "";
        }
        else
            str = str + c;
    }
    if (str != "") {
        a.push_back(str);
    }
    n = a.size();
    display(n);
    if (r != d || q == 1) {
        cout << "Error occurred" << endl;
        return 0;
    }
    //  cout << n << endl;
    cout << s << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
int p;
string s;
vector <string> a;
int r, d, q;
void display(int n) {
    if (p >= n)
        return;
    int f = 0;
    if (a[p] == "pair") {
        s = s + "pair<";
//      cout << "pair<" << endl;
        p++;
        r++;
        display(n);
    }
    else if (a[p] == "int") {
        s = s + "int";
    //  cout << "int" << endl;
        p++;
        f = 1;
    }
    if (p >= n ) {
        if (f == 1)
            q = 1;
        return;
    }
    if (a[p] == "pair") {
        s = s + ",pair<";
//      cout << ",pair<" << endl;
        p++;
        r++;
        display(n);
    }
    else if (a[p] == "int") {
    //  cout << ",int" << endl;
        s = s + ",int";
        p++;
    }
    s = s + ">";
    d++;
    return;
}
int main() {
    int i, j;
    string str;
    int n;
    char c;
    r = 0;
    d = 0;
    q = 0;
    scanf("%d\n", &j);
    while (true) {
        c = getchar();
        if (c == '\n')
            break;
        if (c == ' ') {
            a.push_back(str);
            str = "";
        }
        else
            str = str + c;
    }
    if (str != "") {
        a.push_back(str);
    }
    n = a.size();
    display(n);
    if (r != d || q == 1) {
        cout << "Error occurred" << endl;
        return 0;
    }
//  cout << n << endl;
    cout << s << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
string sss, z;
int t;
void f()
{
    if (cin >> sss)
    {
        z += sss;
        if (sss == "pair")
            z += "<", f(), z += ",", f(), z += ">";
    }
    else
        t = 1;
}
int main()
{
    cin >> sss;
    f();
    if (t || cin >> sss)
        puts("Error occurred");
    else
        puts(z.c_str());
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
string s, b;
int q;
void func() {
    if (cin >> b) {
        s = s + b;
        if (b == "pair") {
            s = s + "<";
            func();
            s = s + ",";
            func();
            s = s + ">";
        }
    }
    else
        q = 1;
}
int main() {
    cin >> b;
    func();
    if (q || cin >> b)
        puts("Error occurred");
    else
        puts(s.c_str());
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
int p;
string s;
vector <string> a;
int r, d, q;
void func() {
    string b;
    if (cin >> b) {
        s = s + b;
        if (b == "pair") {
            s = s + "<";
            func();
            s = s + ",";
            func();
            s = s + ">";
        }
    }
    else
        q = 1;
}
int main() {
    q = 0;
    int n;
    string b;
    cin >> n;
    func();
//  cout << "yes" << endl;
    if (q || cin >> b)
        puts("Error occurred");
    else
        puts(s.c_str());
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
int p;
string s;
vector <string> a;
int r, d, q;
void display(int n) {
    if (p >= n)
        return;
    int f = 0;
    if (a[p] == "pair") {
        s += "pair<";
        //      cout << "pair<" << endl;
        p++;
        r++;
        display(n);
    }
    else if (a[p] == "int") {
        s += "int";
        //  cout << "int" << endl;
        p++;
        f = 1;
    }
    if (p >= n) {
        if (f == 1)
            q = 1;
        return;
    }
    if (a[p] == "pair") {
        s += ",pair<";
        //      cout << ",pair<" << endl;
        p++;
        r++;
        display(n);
    }
    else if (a[p] == "int") {
        //  cout << ",int" << endl;
        s += ",int";
        p++;
    }
    s += ">";
    d++;
    return;
}
int main() {
    int i, j;
    string str;
    int n;
    char c;
    r = 0;
    d = 0;
    q = 0;
    scanf("%d\n", &j);
    while (true) {
        c = getchar();
        if (c == '\n')
            break;
        if (c == ' ') {
            a.push_back(str);
            str = "";
        }
        else
            str = str + c;
    }
    if (str != "") {
        a.push_back(str);
    }
    n = a.size();
    display(n);
    if (r != d || q == 1) {
        if (!(n == 1 && a[0] == "int")) {
            cout << "Error occurred" << endl;
            return 0;
        }
    }
    //  cout << n << endl;
    cout << s << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
string s, b;
int q;
void func() {
    if (cin >> b) {
        s = s + b;
        if (b == "pair") {
            s += "<", func(), s += ",", func(), s += ">";
        }
    }
    else
        q = 1;
}
int main() {
    cin >> b;
    func();
    if (q || cin >> b)
        puts("Error occurred");
    else
        puts(s.c_str());
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
int p;
string s;
vector <string> a;
int r, d, q;
void display(int n) {
    if (p >= n)
        return;
    int f = 0;
    if (a[p] == "pair") {
        s += "pair<";
        //      cout << "pair<" << endl;
        p++;
        r++;
        display(n);
    }
    else if (a[p] == "int") {
        s += "int";
        //  cout << "int" << endl;
        p++;
        f = 1;
    }
    if (p >= n) {
        if (f == 1)
            q = 1;
        return;
    }
    if (a[p] == "pair") {
        s += ",pair<";
        //      cout << ",pair<" << endl;
        p++;
        r++;
        display(n);
    }
    else if (a[p] == "int") {
        //  cout << ",int" << endl;
        s += ",int";
        p++;
    }
    s += ">";
    d++;
    return;
}
int main() {
    int i, j;
    string str;
    int n;
    char c;
    r = 0;
    d = 0;
    q = 0;
    scanf("%d\n", &j);
    while (true) {
        c = getchar();
        if (c == '\n')
            break;
        if (c == ' ') {
            a.push_back(str);
            str = "";
        }
        else
            str = str + c;
    }
    if (str != "") {
        a.push_back(str);
    }
    n = a.size();
    display(n);
    if (r != d || q == 1 || (r == 0 && d == 0)) {
        cout << "Error occurred" << endl;
        return 0;
    }
    //  cout << n << endl;
    cout << s << endl;
    return 0;
}


#include<stdio.h>
#include<iostream>
using namespace std;
string s,z;
int t;
void f()
{
    if(cin>>s)
    {
        z+=s;
        if(s=="pair")
            z+="<",f(),z+=",",f(),z+=">";
    }
    else
    t=1;
}
int main()
{
    cin>>s;
    f();
    if(t||cin>>s)
    puts("Error occurred");
    else
    puts(z.c_str());
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;
string s, z;
int t;
void f()
{
    if (cin >> s)
    {
        z = z + s;
        if (s == "pair")
            z += "<", f(), z += ",", f(), z += ">";
    }
    else
        t = 1;
}
int main()
{
    cin >> s;
    f();
    if (t || cin >> s)
        puts("Error occurred");
    else
        puts(z.c_str());
    return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
string x,d;
int t;
void dfs()
{
     if(cin>>x)
     {
               d+=x;
               if(x=="pair")
               {
                         d+="<",dfs(),d+=",",dfs(),d+=">";
               }
     }
     else
            t=1;
 }
int main()
{
	int o;
	cin>>o;
    getline(cin,x);
    dfs();
    if(t||cin>>x)
    	cout<<"Error occurred";
    else
    	cout<<d;
    return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
string x,d;
int t;
void f()
{
    if(cin>>x)
    {
        d+=x;
        if(x=="pair")
        {
            d=d+"<",f(),d=d+",",f(),d=d+">";
        }
    }
    else
        t=1;
}

int main()
{
    int o;
    cin>>o;
    getline(cin,x);
    f();
    if(t||cin>>x)
        cout<<"Error occurred";
    else
        cout<<d;
    return 0;
}


#include<iostream>
using namespace std;

int o;
int t;
string ans;

void f()
{
    string x;
    if(cin>>x)
    {
        ans+=x;
        if(x=="pair")ans+='<',f(),ans+=',',f(),ans+='>';
    }
    else
    t=1;
}

int main()
{
    cin>>o;
    f();
    string x;
    if(t==1 || cin>>x) cout<<"Error occurred"; else cout<<ans;
    return 0;
}


#include<iostream>
using namespace std;

int o;
int t;
string ans;

void f()
{
    string x;
    if(cin>>x)
    {
        ans+=x;
        if(x=="pair")ans+='<',f(),ans+=',',f(),ans+='>';
    }
    else
    t=1;
}

int main()
{
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    cin>>o;
    f();
    string x;
    if(t==1 || cin>>x) cout<<"Error occurred"; else cout<<ans;
    return 0;
}


#include<iostream>
using namespace std;

string x,ans;
bool t;

void f()
{
    if(cin>>x)
    {
        if(x=="1") t=1;
        ans+=x;
        if(x=="pair")
        ans+="<",f(),ans+=",",f(),ans+=">";
    }
    else if(x!="pair" && x!="int")
    {
        t=1;
    }
}

int main()
{
    int o;
    cin>>o;
    f();
    if(cin>>x || t==1) cout<<"Error occurred"; else cout<<ans;
    return 0;
}


#include<iostream>
using namespace std;

string d;
int t;

void f()
{
    string x;
    if(cin>>x)
    {
    d=d+x;
    if(x=="pair") d=d+"pair<";f();d=d+",";f();d=d+">";
    }
    else t=1;
}

int main()
{
    int o;
    cin>>o;
    f();
    string x;
    if(t==1 || cin>>x) cout<<"Error occurred"; else cout<<d;
    return 0;
}


#include<iostream>
using namespace std;

string d;
int t;

void f()
{
	string x;
	if(cin>>x)
	{
	d=d+x;
	if(x=="pair") d=d+"<",f(),d=d+",",f(),d=d+">";
    }
    else t=1;
}

int main()
{
	int o;
	cin>>o;
	f();
	string x;
	if(t==1 || cin>>x) cout<<"Error occurred"; else cout<<d;
	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
string x,d;
int t;
void dfs()
{
    if(cin>>x)
    {
        d+=x;
        if(x=="pair")
        {
            d=d+"<",dfs(),d=d+",",dfs(),d=d+">";
        }
    }
    else
        t=1;
}

int main()
{
    int o;
    cin>>o;
    getline(cin,x);
    dfs();
    if(t||cin>>x)
        cout<<"Error occurred";
    else
        cout<<d;
    return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
string x,d;
int t;
void dfs()
{
     if(cin>>x)
     {
               d+=x;
               if(x=="pair")
               {
                         d+="<",dfs(),d+=",",dfs(),d+=">";
               }
     }
     else
     {
               t=1;
     }
}
int main()
{
    int o;
    cin>>o;
    getline(cin,x);
    dfs();
    if(t||cin>>x)
        cout<<"Error occurred";
    else
        cout<<d;
    return 0;
}


#include<iostream>
using namespace std;

string d,x;
int t;

void f()
{
	if(cin>>x)
	{
	d=d+x;
	if(x=="pair") d=d+"<",f(),d=d+",",f(),d=d+">";
    }
    else t=1;
}

int main()
{
	int o;
	cin>>o;
	getline(cin,x);
	f();
	if(t==1 || cin>>x) cout<<"Error occurred"; else cout<<d;
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;

string d,x;
int t;

void f()
{
	if(cin>>x)
	{
		d+=x;
		if(x=="pair")
		{
			d=d+"<",f(),d=d+",",f(),d=d+">";
		}
    }
    else t=1;
}

int main()
{
	int o;
	cin>>o;
	f();
	if(t||cin>>x) cout<<"Error occurred"; else cout<<d;
	return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
string x,d;
int t;
void dfs()
{
     if(cin>>x)
     {
               d+=x;
               if(x=="pair")
               {
                         d+="<",dfs(),d+=",",dfs(),d+=">";
               }
     }
     else
            t=1;
 }
int main()
{
    int o;
    cin>>o;
    dfs();
    if(t||cin>>x)
        cout<<"Error occurred";
    else
        cout<<d;
    return 0;
}


#include<iostream>
using namespace std;

string x,ans;
int t;

void f()
{
    if(cin>>x)
    {
        ans+=x;
        if(x=="pair")
        ans+="<",f(),ans+=",",f(),ans+=">";
    }
    else
    {
        t=1;
    }
}

int main()
{
    int o;
    cin>>o;
    f();
    if(cin>>x || t) cout<<"Error occurred"; else cout<<ans;
    return 0;
}


#include<iostream>
using namespace std;

string d,x;
int t;

void f()
{
    if(cin>>x)
    {
    d=d+x;
    if(x=="pair") d=d+"<",f(),d=d+",",f(),d=d+">";
    }
    else t=1;
}

int main()
{
    int o;
    cin>>o;
    f();
    if(t==1 || cin>>x) cout<<"Error occurred"; else cout<<d;
    return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
string x,d;
int t;
void dfs()
{
     if(cin>>x)
     {
               d=d+x;
               if(x=="pair")
               {
                         d+="<",dfs(),d+=",",dfs(),d+=">";
               }
     }
     else
            t=1;
 }
int main()
{
    int o;
    cin>>o;
    getline(cin,x);
    dfs();
    if(t||cin>>x)
        cout<<"Error occurred";
    else
        cout<<d;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
#pragma comment(linker, "/STACK:50000000 ")
using namespace std;
vector<int> v;
vector<int>::iterator it;
int flag=1;
void search()
{
    if (*it==1) return;
    if (it>=v.end()){
        flag=0;
        return;
    }
    it++;
     search();
     it++;
     search();
     return ;
}
void print()
{
    if (*it==1) {printf("int");return;}
    printf("pair<");
    it++;
     print();
     printf(",");it++;
     print();
     printf(">");
     //if(it!=v.end()-1) printf(",");
     return ;
}
int main()
{
    #ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

    int n,x;
    char s[100];
    while(cin>>n)
    {
        flag=1;
        v.clear();
        x=n;
        while(x)
        {
        scanf("%s",s);
        if(s[0]=='p')
        v.push_back(0);
        else
        {
            x--;
            v.push_back(1);
        }}
        it=v.begin();
        search();
        if(it!=v.end()-1||flag==0)
        cout<<"Error occurred"<<endl;
        else
        {
        it=v.begin();
        print();
        cout<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
using namespace std;
vector<int> v;
vector<int>::iterator it;
int flag=1;
void search()
{
    if (*it==1) return;
    if (it>=v.end()){
        flag=0;
        return;
    }
    it++;
     search();
     it++;
     search();
     return ;
}
void print()
{
    if (*it==1) {printf("int");return;}
    printf("pair<");
    it++;
     print();
     printf(",");it++;
     print();
     printf(">");
     //if(it!=v.end()-1) printf(",");
     return ;
}
int main()
{
    #ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

    int n,x;
    char s[100];
    while(cin>>n)
    {
        flag=1;
        v.clear();
        x=n;
        while(x)
        {
        scanf("%s",s);
        if(s[0]=='p')
        v.push_back(0);
        else
        {
            x--;
            v.push_back(1);
        }}
        it=v.begin();
        search();
        if(it!=v.end()-1||flag==0)
        cout<<"Error occurred"<<endl;
        else
        {
        it=v.begin();
        print();
        cout<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
#include<string>
#pragma comment(linker, "/STACK:10600000777216")
using namespace std;
vector<int> v;
int flag=1;
int it;string ans;
void print()
{
    if(it==v.size()){flag=0;return ;}
    if (v[it]==1) {ans+="int";return;}
    ans+="pair<";
     it++;
     print();
     ans+=',';
     it++;
     print();
     ans+=">";
     return;
}
char s[500];int n,x;
int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
    while(cin>>n)
    {
        ans.clear();
        flag=1;
        v.clear();
        x=n;
        while(x)
        {
        flag++;
        scanf("%s",s);
        if(s[0]=='p')
        v.push_back(0);
        else
        {
            x--;
            v.push_back(1);
        }}
        it=0;
        print();
        if(it!=v.size()-1||flag==0)
        cout<<"Error occurred"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
#include<string>
#pragma comment(linker, "/STACK:500000000")
using namespace std;
vector<int> v;
int flag=0;
string ans;vector<int>::iterator it;
void print()
{
    if(it==v.end())return ;
    flag--;
    if (*it==1) {ans+="int";return;}
    ans+="pair<";
    it++;
     print();
     ans+=',';it++;
     print();
     ans+=">";
     //if(it!=v.end()-1) printf(",");
     return ;
}

int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

    int n,x;
    char s[100];
    while(cin>>n)
    {
        flag=0;
        ans.clear();
        flag=1;
        v.clear();
        x=n;
        while(x)
        {
        flag++;
        scanf("%s",s);
        if(s[0]=='p')
        v.push_back(0);
        else
        {
            x--;
            v.push_back(1);
        }}
        it=v.begin();
        print();
        if(flag!=1)
        cout<<"Error occurred"<<flag<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
vector<int> v;
vector<int>::iterator it;
int flag=1;
void search()
{
    if (*it==1) return;
    if (it>=v.end()){
        flag=0;
        return;
    }
    it++;
     search();
     it++;
     search();
     return ;
}
void print()
{
    if (*it==1) {printf("int");return;}
    printf("pair<");
    it++;
     print();
     printf(",");it++;
     print();
     printf(">");
     //if(it!=v.end()-1) printf(",");
     return ;
}
int main()
{
    #ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

    int n,x;
    char s[100];
    while(cin>>n)
    {
        flag=1;
        v.clear();
        x=n;
        while(x)
        {
        scanf("%s",s);
        if(s[0]=='p')
        v.push_back(0);
        else
        {
            x--;
            v.push_back(1);
        }}
        it=v.begin();
        search();
        if(it!=v.end()-1||flag==0)
        cout<<"Error occurred"<<endl;
        else
        {
        it=v.begin();
        print();
        }
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
#include<string>
#pragma comment(linker, "/STACK:10600000777216")
using namespace std;
int v[1000000];
int flag=1;int c;
int it;string ans;
void print()
{
    if(it==c){flag=0;return ;}
    if (v[it]==1) {ans+="int";return;}
    ans+="pair<";
     it++;
     print();
     ans+=',';
     it++;
     print();
     ans+=">";
     return;
}
char s[500];int n,x;
int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
    while(cin>>n)
    {
         c=0;
        ans.clear();
        flag=1;
        x=n;
        while(x)
        {
        scanf("%s",s);
        if(s[0]=='p')
        v[c++]=0;
        else
        {
            x--;
            v[c++]=1;
        }}
        it=0;
        print();
        if(it!=c-1||flag==0)
        cout<<"Error occurred"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
#include<string>
#pragma comment(linker, "/STACK:500000000")
using namespace std;
vector<int> v;
int flag=1;
string ans;
void search(vector<int>::iterator it)
{
    if (*it==1)
    {
        ans+="int";
        return;
    }
    if (it>=v.end()){
        flag=0;
        return;
    }
     ans+="pair<";
     search(++it);
     ans+=',';
     search(++it);
     ans+=">";
     return ;
}

int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

    int n,x;
    char s[100];
    while(cin>>n)
    {
        ans.clear();
        flag=1;
        v.clear();
        x=n;
        while(x)
        {
        scanf("%s",s);
        if(s[0]=='p')
        v.push_back(0);
        else
        {
            x--;
            v.push_back(1);
        }}
        vector<int>::iterator it=v.begin();
        search(it);
        if(flag==0)
        cout<<"Error occurred"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
#include<string>
#pragma comment(linker, "/STACK:500000000")
using namespace std;
vector<int> v;
int flag=1;
string ans;vector<int>::iterator it;
void print()
{
    if(it==v.end()){flag=0;return ;}

    if (*it==1) {ans+="int";return;}
    ans+="pair<";
    it++;
     print();
     ans+=',';it++;
     print();
     ans+=">";
     //if(it!=v.end()-1) printf(",");
     return ;
}

int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

    int n,x;
    char s[100];
    while(cin>>n)
    {

        ans.clear();
        flag=1;
        v.clear();
        x=n;
        while(x)
        {
        flag++;
        scanf("%s",s);
        if(s[0]=='p')
        v.push_back(0);
        else
        {
            x--;
            v.push_back(1);
        }}
        it=v.begin();
        print();
        if(it!=v.end()-1||flag==0)
        cout<<"Error occurred"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
#include<string>
#pragma comment(linker, "/STACK:106777216")
using namespace std;
vector<int> v;
int flag=1;
string ans;vector<int>::iterator it;
void print()
{
    if(it==v.end()){flag=0;return ;}

    if (*it==1) {ans+="int";return;}
    ans+="pair<";
    it++;
     print();
     ans+=',';it++;
     print();
     ans+=">";
     //if(it!=v.end()-1) printf(",");
     return ;
}

int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

    int n,x;
    char s[100];
    while(cin>>n)
    {

        ans.clear();
        flag=1;
        v.clear();
        x=n;
        while(x)
        {
        flag++;
        scanf("%s",s);
        if(s[0]=='p')
        v.push_back(0);
        else
        {
            x--;
            v.push_back(1);
        }}
        it=v.begin();
        print();
        if(it!=v.end()-1||flag==0)
        cout<<"Error occurred"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
#include<string>
using namespace std;
int v[1000000];
int flag=1;int c;
int it;string ans;
void print()
{
    if(it==c){flag=0;return ;}
    if (v[it++]==1) {ans+="int";return;}
    ans+="pair<";print();ans+=",";print();ans+=">";
    return;
}
char s[500];int n,x;
int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
    while(cin>>n)
    {
         c=0;
        ans.clear();
        flag=1;
        x=n;
        while(x)
        {
        scanf("%s",s);
        if(s[0]=='p')
        v[c++]=0;
        else
        {
            x--;
            v[c++]=1;
        }}
        it=0;
        print();
        if(it!=c||flag==0)
        cout<<"Error occurred"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
#include<string>
using namespace std;
int v[1000000];
int flag=1;int c;
int it;string ans;
void print()
{
    if(it==c){flag=0;return ;}
    if (v[it++]==1) {ans+="int";return;}
    ans+="pair<";print();ans+=",";print();ans+=">";
    return;
}
char s[500];int n,x;
int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
    while(cin>>n)
    {
         c=0;
        ans.clear();
        flag=1;
        x=n;
        while(scanf("%s",s)==1)
        {
        if(s[0]=='p')
        v[c++]=0;
        else
        {
            x--;
            v[c++]=1;
        }}
        it=0;
        print();
        if(it!=c||flag==0)
        cout<<"Error occurred"<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
#include<string>
#pragma comment(linker, "/STACK:500000000")
using namespace std;
vector<int> v;
int flag=1;
string ans;vector<int>::iterator it;
void print()
{
    if(it==v.end()){flag=0;return ;}

    if (*it==1) {ans+="int";return;}
    ans+="pair<";
    it++;
     print();
     ans+=',';it++;
     print();
     ans+=">";
     //if(it!=v.end()-1) printf(",");
     return ;
}

int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

    int n,x;
    char s[100];
    while(cin>>n)
    {

        ans.clear();
        flag=1;
        v.clear();
        x=n;
        while(x)
        {
        flag++;
        scanf("%s",s);
        if(s[0]=='p')
        v.push_back(0);
        else
        {
            x--;
            v.push_back(1);
        }}
        it=v.begin();
        print();
        if(it!=v.end()-1||flag==0)
        cout<<"Error occurred"<<flag<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
#pragma comment(linker, "/STACK:500000000 ")
using namespace std;
vector<int> v;
vector<int>::iterator it;
int flag=1;
void search()
{
    if (*it==1) return;
    if (it>=v.end()){
        flag=0;
        return;
    }
    it++;
     search();
     it++;
     search();
     return ;
}
void print()
{
    if (*it==1) {printf("int");return;}
    printf("pair<");
    it++;
     print();
     printf(",");it++;
     print();
     printf(">");
     //if(it!=v.end()-1) printf(",");
     return ;
}
int main()
{
    #ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

    int n,x;
    char s[100];
    while(cin>>n)
    {
        flag=1;
        v.clear();
        x=n;
        while(x)
        {
        scanf("%s",s);
        if(s[0]=='p')
        v.push_back(0);
        else
        {
            x--;
            v.push_back(1);
        }}
        it=v.begin();
        search();
        if(it!=v.end()-1||flag==0)
        cout<<"Error occurred"<<endl;
        else
        {
        it=v.begin();
        print();
        cout<<endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>

using namespace std;

stack<int>a;
int b[50001],symbol[50001]={0};
string s[30001];

int main()
{    // freopen("STL.in","r",stdin);

      int i,j=0,n,m,x,y,z,k=0;
      cin>>n;
	  /*getchar();
      getline(cin,s);
	  m=s.length();*/
	  //cout<<m<<endl;
      //for(i=0;i<m;i++)cout<<s[i]<<endl;
      int p=1;
      while(cin>>s[p]){
      	p++;
      }
      //cout<<p-1<<endl;

      for(i=1;i<p;i++){
      	//cout<<"+1"<<endl;
      	//cout<<i<<endl;
      	//bool f=false;
      	//cout<<s[i]<<s[i+1]<<endl;
      	if(s[i]=="pair")a.push(1),b[++k]=1;
      	if(s[i]=="int")a.push(2),b[++k]=2;
      	//cout<<a.top()<<endl;
      	//cout<<"size:"<<a.size()<<endl;
      	/*if(!f){
		  //cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
		  continue;
		  }*/
      	if(a.size()<=2){
		  //cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
		  continue;
		  }
      	//cout<<"size:"<<a.size()<<endl;
        x=a.top();
		//cout<<x<<endl;
		a.pop();
		//for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		//cout<<endl;
      	if(x==2){
      		y=a.top();
			//cout<<y<<endl;
			a.pop();
      		if(y==2){
      			z=a.top();
				//cout<<z<<endl;
				a.pop();
      			if(z==1){
				  a.push(2);
				  symbol[i]++;
				  //cout<<"YES"<<endl;
		  	            }
      			  else{
					 a.push(z);//,cout<<"NOZZZZ"<<endl;
					 a.push(y);
					 a.push(x);
					 continue;
				     }
					}
      		  else{
				 a.push(y);//,cout<<"NOYYY"<<endl;
      		     a.push(x);
      		     continue;
      		     }
				}
      	  else {
			a.push(x);//,cout<<"NOXX"<<endl;
			continue;
		    }
      while(a.size()>2){
	    x=a.top();
		  //cout<<x<<endl;
		  a.pop();
		  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		  //cout<<endl;
      	  if(x==2){
      		  y=a.top();
			  //cout<<y<<endl;
			  a.pop();
      		  if(y==2){
      			  z=a.top();
				  //cout<<z<<endl;
				  a.pop();
      			  if(z==1){
				    a.push(2);
				    symbol[k]++;
				    //cout<<symbol[k]<<endl;
				    //cout<<"YES"<<endl;
		  	        }
      			    else{
					   a.push(z);//,cout<<"NOZZZZ"<<endl;
					   a.push(y);
					   a.push(x);
					   break;
				       }
					  }
      		    else{
				   a.push(y);//,cout<<"NOYYY"<<endl;
      		       a.push(x);
      		       break;
      		       }
				  }
      	    else {
			  a.push(x);//,cout<<"NOXX"<<endl;
			  break;
		      }
      	}
      //cout<<endl<<"............................................."<<endl;
	  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
	  /*int a1,a2,a3;
	  a1=a.top();
	  cout<<a1<<' ';
	  a.pop();
	  a2=a.top();
	  cout<<a2<<' ';
	  a.pop();
	  a3=a.top();
	  cout<<a3<<' ';
	  a.pop();
	  a.push(a3);
	  a.push(a2);
	  a.push(a1);*/
	  }
	  //cout<<a.size()<<endl;

	  while(a.size()>2){
	    x=a.top();
		  //cout<<x<<endl;
		  a.pop();
		  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		  //cout<<endl;
      	  if(x==2){
      		  y=a.top();
			  //cout<<y<<endl;
			  a.pop();
      		  if(y==2){
      			  z=a.top();
				  //cout<<z<<endl;
				  a.pop();
      			  if(z==1){
				    a.push(2);
				    symbol[k]++;
				    //cout<<symbol[k]<<endl;
				    //cout<<"YES"<<endl;
		  	        }
      			    else{
					   a.push(z);//,cout<<"NOZZZZ"<<endl;
					   a.push(y);
					   a.push(x);
					   break;
				       }
					  }
      		    else{
				   a.push(y);//,cout<<"NOYYY"<<endl;
      		       a.push(x);
      		       break;
      		       }
				  }
      	    else {
			  a.push(x);//,cout<<"NOXX"<<endl;
			  break;
		      }
      	}

      //for(i=1;i<=k;i++)cout<<b[i]<<endl;
      //cout<<"size:"<<a.size()<<endl;
      //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
      //cout<<endl;
      /*for(i=1;i<=3;i++){
      	cout<<a.top()<<endl;
      	a.pop();
        }*/
	  //int sum=0;
	  //cout<<symbol[k]<<endl;

      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=k;i++){
      	   if(b[i]==1&&b[i-1]!=2)cout<<"pair<";
      	     else if(b[i]==1&&b[i-1]==2)cout<<",pair<";
      	     else if(n>=2){
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int";
		   while(symbol[i]>0){
		   	cout<<">";
		   	symbol[i]--;
		     }
		  }
	     }
		cout<<endl;
	    }
		else cout<<"Error occurred"<<endl;

	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
stack<int>a;
int b[500010];
string s[300001];
int main()
{     //freopen("STL.in","r",stdin);
      int i,j=0,n,m,x,y,z,k=0;
      cin>>n;
	  /*getchar();
      getline(cin,s);
	  m=s.length();*/
	  //cout<<m<<endl;
      //for(i=0;i<m;i++)cout<<s[i]<<endl;
      int p=1;
      while(cin>>s[p]){
      	p++;
      }
      for(i=1;i<=p;i++){
      	//cout<<"+1"<<endl;
      	//cout<<i<<endl;
      	//bool f=false;
      	//cout<<s[i]<<s[i+1]<<endl;
      	if(s[i]=="pair")a.push(1),b[++k]=1;
      	if(s[i]=="int")a.push(2),b[++k]=2;
      	//cout<<"size:"<<a.size()<<endl;
      	/*if(!f){
		  //cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
		  continue;
		  }*/
      	if(a.size()<=2){
		  //cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
		  continue;
		  }
      	//cout<<"size:"<<a.size()<<endl;
        x=a.top();
		//cout<<x<<endl;
		a.pop();
		//for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		//cout<<endl;
      	if(x==2){
      		y=a.top();
			//cout<<y<<endl;
			a.pop();
      		if(y==2){
      			z=a.top();
				//cout<<z<<endl;
				a.pop();
      			if(z==1){
				  a.push(2);
				  //cout<<"YES"<<endl;
		  	            }
      			  else{
					 a.push(z);//,cout<<"NOZZZZ"<<endl;
					 a.push(y);
					 a.push(x);
				     }
					}
      		  else{
				 a.push(y);//,cout<<"NOYYY"<<endl;
      		     a.push(x);
      		     }
				}
      	  else a.push(x);//,cout<<"NOXX"<<endl;
      //cout<<endl<<"............................................."<<endl;
	  }
      //for(i=1;i<=k;i++)cout<<b[i]<<endl;
      //cout<<"size:"<<a.size()<<endl;
      //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
      //cout<<endl;
      /*for(i=1;i<=3;i++){
      	cout<<a.top()<<endl;
      	a.pop();
        }*/
      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=k;i++)
      	   if(b[i]==1&&b[i-1]!=2)cout<<"pair<";
      	     else if(b[i]==1&&b[i-1]==2)cout<<",pair<";
      	     else if(n>=2){
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int>";
			   }
		cout<<endl;
		}
		else cout<<"Error occurred"<<endl;
	  return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
int n;
stack <int> st;
string str,ans;
int main(){
	//freopen("STL.in","r",stdin);
	cin>>n;
	while(cin>>str){
		while(!st.empty()&&st.top()==2){
			st.pop();
			ans+=">";
		}

		if(!st.empty())if(st.top()==1)ans+=",";
		if(!st.empty()){
		  int a=st.top();
			a++;
			st.pop();
			st.push(a);
		}
		else if(str=="int"&&!ans.empty()){
		  cout<<"Error occurred\n";
		  return 0;
		}

		if(str=="pair"){
			st.push(0);
			ans+="pair<";
		}
		else{
			ans+="int";
		}
	}
	while(!st.empty()&&st.top()==2){
		st.pop();
		ans+=">";
	}
	if(!st.empty())cout<<"Error occurred\n";
	else cout<<ans<<endl;

  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
stack<int>a;
int b[500010];
char s[500010];
int main()
{     int i,j=0,n,x,y,z,k=0;
      cin>>n;
      while(cin>>s[++j]){
      	if(s[j]=='i'&&s[j-1]=='p')a.push(1),b[++k]=1;
      	if(s[j]=='n'&&s[j-1]=='i')a.push(2),b[++k]=2;
      	x=a.top();a.pop();
      	if(x==2){
      		y=a.top();a.pop();
      		if(y==2){
      			z=a.top();a.pop();
      			if(z==1)a.push(2);
      			  else a.push(z);}
      		  else a.push(y);}
      	  else a.push(x);}
      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=k;i++)
      	   if(b[i]==1)cout<<"pair<";
      	     else{
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int>"<<endl;
			   }
		cout<<endl;
		}
		else cout<<"Error occurred"<<endl;
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
stack<int>a;
int b[500010];
string s[300001];
int main()
{     //freopen("STL.in","r",stdin);
      int i,j=0,n,m,x,y,z,k=0;
      cin>>n;
	  /*getchar();
      getline(cin,s);
	  m=s.length();*/
	  //cout<<m<<endl;
      //for(i=0;i<m;i++)cout<<s[i]<<endl;
      int p=1;
      while(cin>>s[p]){
      	p++;
      }
      for(i=1;i<=p;i++){
      	//cout<<"+1"<<endl;
      	//cout<<i<<endl;
      	//bool f=false;
      	//cout<<s[i]<<s[i+1]<<endl;
      	if(s[i]=="pair")a.push(1),b[++k]=1;
      	if(s[i]=="int")a.push(2),b[++k]=2;
      	//cout<<"size:"<<a.size()<<endl;
      	/*if(!f){
		  //cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
		  continue;
		  }*/
      	if(a.size()<=2){
		  //cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
		  continue;
		  }
      	//cout<<"size:"<<a.size()<<endl;
        x=a.top();
		//cout<<x<<endl;
		a.pop();
		//for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		//cout<<endl;
      	if(x==2){
      		y=a.top();
			//cout<<y<<endl;
			a.pop();
      		if(y==2){
      			z=a.top();
				//cout<<z<<endl;
				a.pop();
      			if(z==1){
				  a.push(2);
				  //cout<<"YES"<<endl;
		  	            }
      			  else{
					 a.push(z);//,cout<<"NOZZZZ"<<endl;
					 a.push(y);
					 a.push(x);
				     }
					}
      		  else{
				 a.push(y);//,cout<<"NOYYY"<<endl;
      		     a.push(x);
      		     }
				}
      	  else a.push(x);//,cout<<"NOXX"<<endl;
      //cout<<endl<<"............................................."<<endl;
	  }
      //for(i=1;i<=k;i++)cout<<b[i]<<endl;
      //cout<<"size:"<<a.size()<<endl;
      //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
      //cout<<endl;
      /*for(i=1;i<=3;i++){
      	cout<<a.top()<<endl;
      	a.pop();
        }*/
      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=k;i++)
      	   if(b[i]==1)cout<<"pair<";
      	     else if(n>=2){
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int>";
			   }
		cout<<endl;
		}
		else cout<<"Error occurred"<<endl;
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
stack<short>a;
short b[500010],symbol[500010]={0};
string s[300001];
int main()
{    // freopen("STL.in","r",stdin);
      int i,j=0,n,m,x,y,z,k=0;
      cin>>n;
	  /*getchar();
      getline(cin,s);
	  m=s.length();*/
	  //cout<<m<<endl;
      //for(i=0;i<m;i++)cout<<s[i]<<endl;
      int p=1;
      while(cin>>s[p]){
      	p++;
      }
      for(i=1;i<p;i++){
      	//cout<<"+1"<<endl;
      	//cout<<i<<endl;
      	//bool f=false;
      	//cout<<s[i]<<s[i+1]<<endl;
      	if(s[i]=="pair")a.push(1),b[++k]=1;
      	if(s[i]=="int")a.push(2),b[++k]=2;
      	//cout<<a.top()<<endl;
      	//cout<<"size:"<<a.size()<<endl;
      	/*if(!f){
		  //cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
		  continue;
		  }*/
      	if(a.size()<=2){
		  //cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
		  continue;
		  }
      	//cout<<"size:"<<a.size()<<endl;
        x=a.top();
		//cout<<x<<endl;
		a.pop();
		//for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		//cout<<endl;
      	if(x==2){
      		y=a.top();
			//cout<<y<<endl;
			a.pop();
      		if(y==2){
      			z=a.top();
				//cout<<z<<endl;
				a.pop();
      			if(z==1){
				  a.push(2);
				  symbol[i]++;
				  //cout<<"YES"<<endl;
		  	            }
      			  else{
					 a.push(z);//,cout<<"NOZZZZ"<<endl;
					 a.push(y);
					 a.push(x);
				     }
					}
      		  else{
				 a.push(y);//,cout<<"NOYYY"<<endl;
      		     a.push(x);
      		     }
				}
      	  else a.push(x);//,cout<<"NOXX"<<endl;
      //cout<<endl<<"............................................."<<endl;
	  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
	  /*int a1,a2,a3;
	  a1=a.top();
	  cout<<a1<<' ';
	  a.pop();
	  a2=a.top();
	  cout<<a2<<' ';
	  a.pop();
	  a3=a.top();
	  cout<<a3<<' ';
	  a.pop();
	  a.push(a3);
	  a.push(a2);
	  a.push(a1);*/
	  }
	  //cout<<a.size()<<endl;
	  if(a.size()>2){
	    x=a.top();
		  //cout<<x<<endl;
		  a.pop();
		  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		  //cout<<endl;
      	  if(x==2){
      		  y=a.top();
			  //cout<<y<<endl;
			  a.pop();
      		  if(y==2){
      			  z=a.top();
				  //cout<<z<<endl;
				  a.pop();
      			  if(z==1){
				    a.push(2);
				    symbol[k]++;
				    //cout<<symbol[k]<<endl;
				    //cout<<"YES"<<endl;
		  	        }
      			    else{
					   a.push(z);//,cout<<"NOZZZZ"<<endl;
					   a.push(y);
					   a.push(x);
				       }
					  }
      		    else{
				   a.push(y);//,cout<<"NOYYY"<<endl;
      		       a.push(x);
      		       }
				  }
      	    else a.push(x);//,cout<<"NOXX"<<endl;
      	}
      //for(i=1;i<=k;i++)cout<<b[i]<<endl;
      //cout<<"size:"<<a.size()<<endl;
      //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
      //cout<<endl;
      /*for(i=1;i<=3;i++){
      	cout<<a.top()<<endl;
      	a.pop();
        }*/
	  int sum=0;
	  //cout<<symbol[k]<<endl;
      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=k;i++){
      	   if(b[i]==1&&b[i-1]!=2)cout<<"pair<",sum++;
      	     else if(b[i]==1&&b[i-1]==2)cout<<",pair<",sum++;
      	     else if(n>=2){
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int",sum--;
		   while(symbol[i]>0){
		   	cout<<">";
		   	symbol[i]--;
		     }
		  }
	     }
		cout<<endl;
	    }
		else cout<<"Error occurred"<<endl;
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
stack<int>a;
int b[500010];
string s;
int main()
{     int i,j=0,n,m,x,y,z,k=0;
      cin>>n;
      getchar();
      getline(cin,s);m=s.length();//cout<<m<<endl;
      for(i=0;i<m;i++){
      	if(s[i]=='i'&&s[i-1]=='p')a.push(1),b[++k]=1;
      	if(s[i]=='n'&&s[i-1]=='i')a.push(2),b[++k]=2;
      	x=a.top();a.pop();
      	if(x==2){
      		y=a.top();a.pop();
      		if(y==2){
      			z=a.top();a.pop();
      			if(z==1)a.push(2);
      			  else a.push(z);}
      		  else a.push(y);}
      	  else a.push(x);}
      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=k;i++)
      	   if(b[i]==1)cout<<"pair<";
      	     else{
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int>"<<endl;
			   }
		cout<<endl;
		}
		else cout<<"Error occurred"<<endl;
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>

using namespace std;

stack<int>a;
int b[50001],symbol[50001]={0};
string s[30001];

int main()
{     //freopen("STL.in","r",stdin);

      int i,j=0,n,m,x,y,z,k=0;
      cin>>n;
	  /*getchar();
      getline(cin,s);
	  m=s.length();*/
	  //cout<<m<<endl;
      //for(i=0;i<m;i++)cout<<s[i]<<endl;
      int p=1;
      while(cin>>s[p]){
      	p++;
      }
      //cout<<p-1<<endl;

      for(i=1;i<p;i++){
      	//cout<<"+1"<<endl;
      	//cout<<i<<endl;
      	//bool f=false;
      	//cout<<s[i]<<s[i+1]<<endl;
      	if(s[i]=="pair")a.push(1),b[++k]=1;
      	if(s[i]=="int")a.push(2),b[++k]=2;
      	//cout<<a.top()<<endl;
      	//cout<<"size:"<<a.size()<<endl;
      	/*if(!f){
		  //cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
		  continue;
		  }*/
      	if(a.size()<=2){
		  //cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
		  continue;
		  }
      	//cout<<"size:"<<a.size()<<endl;
        x=a.top();
		//cout<<x<<endl;
		a.pop();
		//for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		//cout<<endl;
      	if(x==2){
      		y=a.top();
			//cout<<y<<endl;
			a.pop();
      		if(y==2){
      			z=a.top();
				//cout<<z<<endl;
				a.pop();
      			if(z==1){
				  a.push(2);
				  symbol[i]++;
				  //cout<<"YES"<<endl;
		  	            }
      			  else{
					 a.push(z);//,cout<<"NOZZZZ"<<endl;
					 a.push(y);
					 a.push(x);
					 continue;
				     }
					}
      		  else{
				 a.push(y);//,cout<<"NOYYY"<<endl;
      		     a.push(x);
      		     continue;
      		     }
				}
      	  else {
			a.push(x);//,cout<<"NOXX"<<endl;
			continue;
		    }
      /*while(a.size()>2){
	    x=a.top();
		  //cout<<x<<endl;
		  a.pop();
		  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		  //cout<<endl;
      	  if(x==2){
      		  y=a.top();
			  //cout<<y<<endl;
			  a.pop();
      		  if(y==2){
      			  z=a.top();
				  //cout<<z<<endl;
				  a.pop();
      			  if(z==1){
				    a.push(2);
				    symbol[k]++;
				    //cout<<symbol[k]<<endl;
				    cout<<"YES"<<endl;
		  	        }
      			    else{
					   a.push(z);//,cout<<"NOZZZZ"<<endl;
					   a.push(y);
					   a.push(x);
					   break;
				       }
					  }
      		    else{
				   a.push(y);//,cout<<"NOYYY"<<endl;
      		       a.push(x);
      		       break;
      		       }
				  }
      	    else {
			  a.push(x);//,cout<<"NOXX"<<endl;
			  break;
		      }
      	}*/
      //cout<<endl<<"............................................."<<endl;
	  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
	  /*int a1,a2,a3;
	  a1=a.top();
	  cout<<a1<<' ';
	  a.pop();
	  a2=a.top();
	  cout<<a2<<' ';
	  a.pop();
	  a3=a.top();
	  cout<<a3<<' ';
	  a.pop();
	  a.push(a3);
	  a.push(a2);
	  a.push(a1);*/
	  }
	  //cout<<a.size()<<endl;

	  while(a.size()>2){
	    x=a.top();
		  //cout<<x<<endl;
		  a.pop();
		  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		  //cout<<endl;
      	  if(x==2){
      		  y=a.top();
			  //cout<<y<<endl;
			  a.pop();
      		  if(y==2){
      			  z=a.top();
				  //cout<<z<<endl;
				  a.pop();
      			  if(z==1){
				    a.push(2);
				    symbol[k]++;
				    //cout<<symbol[k]<<endl;
				    //cout<<"YES"<<endl;
		  	        }
      			    else{
					   a.push(z);//,cout<<"NOZZZZ"<<endl;
					   a.push(y);
					   a.push(x);
					   break;
				       }
					  }
      		    else{
				   a.push(y);//,cout<<"NOYYY"<<endl;
      		       a.push(x);
      		       break;
      		       }
				  }
      	    else {
			  a.push(x);//,cout<<"NOXX"<<endl;
			  break;
		      }
      	}

      //for(i=1;i<=k;i++)cout<<b[i]<<endl;
      //cout<<"size:"<<a.size()<<endl;
      //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
      //cout<<endl;
      /*for(i=1;i<=3;i++){
      	cout<<a.top()<<endl;
      	a.pop();
        }*/
	  //int sum=0;
	  //cout<<symbol[k]<<endl;

      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=k;i++){
      	   if(b[i]==1&&b[i-1]!=2)cout<<"pair<";
      	     else if(b[i]==1&&b[i-1]==2)cout<<",pair<";
      	     else if(n>=2){
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int";
		   while(symbol[i]>0){
		   	cout<<">";
		   	symbol[i]--;
		     }
		  }
	     }
		cout<<endl;
	    }
		else cout<<"Error occurred"<<endl;

	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
stack<short>a;
short b[500010],symbol[500010]={0};
string s[300001];
int main()
{     //freopen("STL.in","r",stdin);
      int i,j=0,n,m,x,y,z,k=0;
      cin>>n;
	  /*getchar();
      getline(cin,s);
	  m=s.length();*/
	  //cout<<m<<endl;
      //for(i=0;i<m;i++)cout<<s[i]<<endl;
      int p=1;
      while(cin>>s[p]){
      	p++;
      }
      for(i=1;i<p;i++){
      	//cout<<"+1"<<endl;
      	//cout<<i<<endl;
      	//bool f=false;
      	//cout<<s[i]<<s[i+1]<<endl;
      	if(s[i]=="pair")a.push(1),b[++k]=1;
      	if(s[i]=="int")a.push(2),b[++k]=2;
      	//cout<<a.top()<<endl;
      	//cout<<"size:"<<a.size()<<endl;
      	/*if(!f){
		  //cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
		  continue;
		  }*/
      	if(a.size()<=2){
		  //cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
		  continue;
		  }
      	//cout<<"size:"<<a.size()<<endl;
        x=a.top();
		//cout<<x<<endl;
		a.pop();
		//for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		//cout<<endl;
      	if(x==2){
      		y=a.top();
			//cout<<y<<endl;
			a.pop();
      		if(y==2){
      			z=a.top();
				//cout<<z<<endl;
				a.pop();
      			if(z==1){
				  a.push(2);
				  symbol[i]++;
				  //cout<<"YES"<<endl;
		  	            }
      			  else{
					 a.push(z);//,cout<<"NOZZZZ"<<endl;
					 a.push(y);
					 a.push(x);
				     }
					}
      		  else{
				 a.push(y);//,cout<<"NOYYY"<<endl;
      		     a.push(x);
      		     }
				}
      	  else a.push(x);//,cout<<"NOXX"<<endl;
      //cout<<endl<<"............................................."<<endl;
	  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
	  /*int a1,a2,a3;
	  a1=a.top();
	  cout<<a1<<' ';
	  a.pop();
	  a2=a.top();
	  cout<<a2<<' ';
	  a.pop();
	  a3=a.top();
	  cout<<a3<<' ';
	  a.pop();
	  a.push(a3);
	  a.push(a2);
	  a.push(a1);*/
	  }
	  //cout<<a.size()<<endl;
	  while(a.size()>2){
	    x=a.top();
		  //cout<<x<<endl;
		  a.pop();
		  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		  //cout<<endl;
      	  if(x==2){
      		  y=a.top();
			  //cout<<y<<endl;
			  a.pop();
      		  if(y==2){
      			  z=a.top();
				  //cout<<z<<endl;
				  a.pop();
      			  if(z==1){
				    a.push(2);
				    symbol[k]++;
				    //cout<<symbol[k]<<endl;
				    //cout<<"YES"<<endl;
		  	        }
      			    else{
					   a.push(z);//,cout<<"NOZZZZ"<<endl;
					   a.push(y);
					   a.push(x);
				       }
					  }
      		    else{
				   a.push(y);//,cout<<"NOYYY"<<endl;
      		       a.push(x);
      		       }
				  }
      	    else a.push(x);//,cout<<"NOXX"<<endl;
      	}
      //for(i=1;i<=k;i++)cout<<b[i]<<endl;
      //cout<<"size:"<<a.size()<<endl;
      //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
      //cout<<endl;
      /*for(i=1;i<=3;i++){
      	cout<<a.top()<<endl;
      	a.pop();
        }*/
	  int sum=0;
	  //cout<<symbol[k]<<endl;
      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=k;i++){
      	   if(b[i]==1&&b[i-1]!=2)cout<<"pair<",sum++;
      	     else if(b[i]==1&&b[i-1]==2)cout<<",pair<",sum++;
      	     else if(n>=2){
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int",sum--;
		   while(symbol[i]>0){
		   	cout<<">";
		   	symbol[i]--;
		     }
		  }
	     }
		cout<<endl;
	    }
		else cout<<"Error occurred"<<endl;
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>

using namespace std;

stack<int>a;
int b[50001],symbol[50001]={0};
string s[30001];

int main()
{     freopen("STL.in","r",stdin);

      int i,j=0,n,m,x,y,z,k=0;
      cin>>n;
	  /*getchar();
      getline(cin,s);
	  m=s.length();*/
	  //cout<<m<<endl;
      //for(i=0;i<m;i++)cout<<s[i]<<endl;
      int p=1;
      while(cin>>s[p]){
      	p++;
      }
      //cout<<p-1<<endl;

      for(i=1;i<p;i++){
      	//cout<<"+1"<<endl;
      	//cout<<i<<endl;
      	//bool f=false;
      	//cout<<s[i]<<s[i+1]<<endl;
      	if(s[i]=="pair")a.push(1),b[++k]=1;
      	if(s[i]=="int")a.push(2),b[++k]=2;
      	//cout<<a.top()<<endl;
      	//cout<<"size:"<<a.size()<<endl;
      	/*if(!f){
		  //cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
		  continue;
		  }*/
      	if(a.size()<=2){
		  //cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
		  continue;
		  }
      	//cout<<"size:"<<a.size()<<endl;
        x=a.top();
		//cout<<x<<endl;
		a.pop();
		//for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		//cout<<endl;
      	if(x==2){
      		y=a.top();
			//cout<<y<<endl;
			a.pop();
      		if(y==2){
      			z=a.top();
				//cout<<z<<endl;
				a.pop();
      			if(z==1){
				  a.push(2);
				  symbol[i]++;
				  //cout<<"YES"<<endl;
		  	            }
      			  else{
					 a.push(z);//,cout<<"NOZZZZ"<<endl;
					 a.push(y);
					 a.push(x);
					 continue;
				     }
					}
      		  else{
				 a.push(y);//,cout<<"NOYYY"<<endl;
      		     a.push(x);
      		     continue;
      		     }
				}
      	  else {
			a.push(x);//,cout<<"NOXX"<<endl;
			continue;
		    }
      /*while(a.size()>2){
	    x=a.top();
		  //cout<<x<<endl;
		  a.pop();
		  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		  //cout<<endl;
      	  if(x==2){
      		  y=a.top();
			  //cout<<y<<endl;
			  a.pop();
      		  if(y==2){
      			  z=a.top();
				  //cout<<z<<endl;
				  a.pop();
      			  if(z==1){
				    a.push(2);
				    symbol[k]++;
				    //cout<<symbol[k]<<endl;
				    cout<<"YES"<<endl;
		  	        }
      			    else{
					   a.push(z);//,cout<<"NOZZZZ"<<endl;
					   a.push(y);
					   a.push(x);
					   break;
				       }
					  }
      		    else{
				   a.push(y);//,cout<<"NOYYY"<<endl;
      		       a.push(x);
      		       break;
      		       }
				  }
      	    else {
			  a.push(x);//,cout<<"NOXX"<<endl;
			  break;
		      }
      	}*/
      //cout<<endl<<"............................................."<<endl;
	  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
	  /*int a1,a2,a3;
	  a1=a.top();
	  cout<<a1<<' ';
	  a.pop();
	  a2=a.top();
	  cout<<a2<<' ';
	  a.pop();
	  a3=a.top();
	  cout<<a3<<' ';
	  a.pop();
	  a.push(a3);
	  a.push(a2);
	  a.push(a1);*/
	  }
	  //cout<<a.size()<<endl;

	  while(a.size()>2){
	    x=a.top();
		  //cout<<x<<endl;
		  a.pop();
		  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		  //cout<<endl;
      	  if(x==2){
      		  y=a.top();
			  //cout<<y<<endl;
			  a.pop();
      		  if(y==2){
      			  z=a.top();
				  //cout<<z<<endl;
				  a.pop();
      			  if(z==1){
				    a.push(2);
				    symbol[k]++;
				    //cout<<symbol[k]<<endl;
				    //cout<<"YES"<<endl;
		  	        }
      			    else{
					   a.push(z);//,cout<<"NOZZZZ"<<endl;
					   a.push(y);
					   a.push(x);
					   break;
				       }
					  }
      		    else{
				   a.push(y);//,cout<<"NOYYY"<<endl;
      		       a.push(x);
      		       break;
      		       }
				  }
      	    else {
			  a.push(x);//,cout<<"NOXX"<<endl;
			  break;
		      }
      	}

      //for(i=1;i<=k;i++)cout<<b[i]<<endl;
      //cout<<"size:"<<a.size()<<endl;
      //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
      //cout<<endl;
      /*for(i=1;i<=3;i++){
      	cout<<a.top()<<endl;
      	a.pop();
        }*/
	  //int sum=0;
	  //cout<<symbol[k]<<endl;

      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=k;i++){
      	   if(b[i]==1&&b[i-1]!=2)cout<<"pair<";
      	     else if(b[i]==1&&b[i-1]==2)cout<<",pair<";
      	     else if(n>=2){
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int";
		   while(symbol[i]>0){
		   	cout<<">";
		   	symbol[i]--;
		     }
		  }
	     }
		cout<<endl;
	    }
		else cout<<"Error occurred"<<endl;

	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
stack<short>a;
short b[500010],symbol[500010]={0};
string s[300001];
int main()
{     freopen("STL.in","r",stdin);
      int i,j=0,n,m,x,y,z,k=0;
      cin>>n;
	  /*getchar();
      getline(cin,s);
	  m=s.length();*/
	  //cout<<m<<endl;
      //for(i=0;i<m;i++)cout<<s[i]<<endl;
      int p=1;
      while(cin>>s[p]){
      	p++;
      }
      for(i=1;i<p;i++){
      	//cout<<"+1"<<endl;
      	//cout<<i<<endl;
      	//bool f=false;
      	//cout<<s[i]<<s[i+1]<<endl;
      	if(s[i]=="pair")a.push(1),b[++k]=1;
      	if(s[i]=="int")a.push(2),b[++k]=2;
      	//cout<<a.top()<<endl;
      	//cout<<"size:"<<a.size()<<endl;
      	/*if(!f){
		  //cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
		  continue;
		  }*/
      	if(a.size()<=2){
		  //cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
		  continue;
		  }
      	//cout<<"size:"<<a.size()<<endl;
        x=a.top();
		//cout<<x<<endl;
		a.pop();
		//for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		//cout<<endl;
      	if(x==2){
      		y=a.top();
			//cout<<y<<endl;
			a.pop();
      		if(y==2){
      			z=a.top();
				//cout<<z<<endl;
				a.pop();
      			if(z==1){
				  a.push(2);
				  symbol[i]++;
				  //cout<<"YES"<<endl;
		  	            }
      			  else{
					 a.push(z);//,cout<<"NOZZZZ"<<endl;
					 a.push(y);
					 a.push(x);
				     }
					}
      		  else{
				 a.push(y);//,cout<<"NOYYY"<<endl;
      		     a.push(x);
      		     }
				}
      	  else a.push(x);//,cout<<"NOXX"<<endl;
      //cout<<endl<<"............................................."<<endl;
	  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
	  /*int a1,a2,a3;
	  a1=a.top();
	  cout<<a1<<' ';
	  a.pop();
	  a2=a.top();
	  cout<<a2<<' ';
	  a.pop();
	  a3=a.top();
	  cout<<a3<<' ';
	  a.pop();
	  a.push(a3);
	  a.push(a2);
	  a.push(a1);*/
	  }
	  //cout<<a.size()<<endl;
	  while(a.size()>2){
	    x=a.top();
		  //cout<<x<<endl;
		  a.pop();
		  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		  //cout<<endl;
      	  if(x==2){
      		  y=a.top();
			  //cout<<y<<endl;
			  a.pop();
      		  if(y==2){
      			  z=a.top();
				  //cout<<z<<endl;
				  a.pop();
      			  if(z==1){
				    a.push(2);
				    symbol[k]++;
				    //cout<<symbol[k]<<endl;
				    //cout<<"YES"<<endl;
		  	        }
      			    else{
					   a.push(z);//,cout<<"NOZZZZ"<<endl;
					   a.push(y);
					   a.push(x);
				       }
					  }
      		    else{
				   a.push(y);//,cout<<"NOYYY"<<endl;
      		       a.push(x);
      		       }
				  }
      	    else a.push(x);//,cout<<"NOXX"<<endl;
      	}
      //for(i=1;i<=k;i++)cout<<b[i]<<endl;
      //cout<<"size:"<<a.size()<<endl;
      //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
      //cout<<endl;
      /*for(i=1;i<=3;i++){
      	cout<<a.top()<<endl;
      	a.pop();
        }*/
	  int sum=0;
	  //cout<<symbol[k]<<endl;
      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=k;i++){
      	   if(b[i]==1&&b[i-1]!=2)cout<<"pair<",sum++;
      	     else if(b[i]==1&&b[i-1]==2)cout<<",pair<",sum++;
      	     else if(n>=2){
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int",sum--;
		   while(symbol[i]>0){
		   	cout<<">";
		   	symbol[i]--;
		     }
		  }
	     }
		cout<<endl;
	    }
		else cout<<"Error occurred"<<endl;
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
stack<int>a;
int b[500010];
string s[300001];
int main()
{     //freopen("STL.in","r",stdin);
      int i,j=0,n,m,x,y,z,k=0;
      cin>>n;
	  /*getchar();
      getline(cin,s);
	  m=s.length();*/
	  //cout<<m<<endl;
      //for(i=0;i<m;i++)cout<<s[i]<<endl;
      int p=1;
      while(cin>>s[p]){
      	p++;
      }
      for(i=1;i<=p;i++){
      	//cout<<"+1"<<endl;
      	//cout<<i<<endl;
      	//bool f=false;
      	//cout<<s[i]<<s[i+1]<<endl;
      	if(s[i]=="pair")a.push(1),b[i]=1;
      	if(s[i]=="int")a.push(2),b[i]=2;
      	//cout<<"size:"<<a.size()<<endl;
      	/*if(!f){
		  //cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
		  continue;
		  }*/
      	if(a.size()<=2){
		  //cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
		  continue;
		  }
      	//cout<<"size:"<<a.size()<<endl;
        x=a.top();
		//cout<<x<<endl;
		a.pop();
		//for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		//cout<<endl;
      	if(x==2){
      		y=a.top();
			//cout<<y<<endl;
			a.pop();
      		if(y==2){
      			z=a.top();
				//cout<<z<<endl;
				a.pop();
      			if(z==1){
				  a.push(2);
				  //cout<<"YES"<<endl;
		  	            }
      			  else{
					 a.push(z);//,cout<<"NOZZZZ"<<endl;
					 a.push(y);
					 a.push(x);
				     }
					}
      		  else{
				 a.push(y);//,cout<<"NOYYY"<<endl;
      		     a.push(x);
      		     }
				}
      	  else a.push(x);//,cout<<"NOXX"<<endl;
      //cout<<endl<<"............................................."<<endl;
	  }
	  if(a.size()>2){
	    x=a.top();
		  //cout<<x<<endl;
		  a.pop();
		  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		  //cout<<endl;
      	  if(x==2){
      		  y=a.top();
			  //cout<<y<<endl;
			  a.pop();
      		  if(y==2){
      			  z=a.top();
				  //cout<<z<<endl;
				  a.pop();
      			  if(z==1){
				    a.push(2);
				    //cout<<"YES"<<endl;
		  	              }
      			    else{
					   a.push(z);//,cout<<"NOZZZZ"<<endl;
					   a.push(y);
					   a.push(x);
				       }
					  }
      		    else{
				   a.push(y);//,cout<<"NOYYY"<<endl;
      		       a.push(x);
      		       }
				  }
      	    else a.push(x);
      	}
      //for(i=1;i<=k;i++)cout<<b[i]<<endl;
      //cout<<"size:"<<a.size()<<endl;
      //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
      //cout<<endl;
      /*for(i=1;i<=3;i++){
      	cout<<a.top()<<endl;
      	a.pop();
        }*/
      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=p;i++)
      	   if(b[i]==1&&b[i-1]!=2)cout<<"pair<";
      	     else if(b[i]==1)cout<<",pair<";
      	     else {
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int>";
			   }
		cout<<endl;
		}
		else cout<<"Error occurred"<<endl;
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
stack<short>a;
short b[500010],symbol[500010]={0};
string s[300001];
int main()
{     //freopen("STL.in","r",stdin);
      int i,j=0,n,m,x,y,z,k=0;
      cin>>n;
	  /*getchar();
      getline(cin,s);
	  m=s.length();*/
	  //cout<<m<<endl;
      //for(i=0;i<m;i++)cout<<s[i]<<endl;
      int p=1;
      while(cin>>s[p]){
      	p++;
      }
      for(i=1;i<p;i++){
      	//cout<<"+1"<<endl;
      	//cout<<i<<endl;
      	//bool f=false;
      	//cout<<s[i]<<s[i+1]<<endl;
      	if(s[i]=="pair")a.push(1),b[++k]=1;
      	if(s[i]=="int")a.push(2),b[++k]=2;
      	//cout<<a.top()<<endl;
      	//cout<<"size:"<<a.size()<<endl;
      	/*if(!f){
		  //cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
		  continue;
		  }*/
      	if(a.size()<=2){
		  //cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
		  continue;
		  }
      	//cout<<"size:"<<a.size()<<endl;
        x=a.top();
		//cout<<x<<endl;
		a.pop();
		//for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		//cout<<endl;
      	if(x==2){
      		y=a.top();
			//cout<<y<<endl;
			a.pop();
      		if(y==2){
      			z=a.top();
				//cout<<z<<endl;
				a.pop();
      			if(z==1){
				  a.push(2);
				  symbol[i]++;
				  //cout<<"YES"<<endl;
		  	            }
      			  else{
					 a.push(z);//,cout<<"NOZZZZ"<<endl;
					 a.push(y);
					 a.push(x);
				     }
					}
      		  else{
				 a.push(y);//,cout<<"NOYYY"<<endl;
      		     a.push(x);
      		     }
				}
      	  else a.push(x);//,cout<<"NOXX"<<endl;
      while(a.size()>2){
	    x=a.top();
		  //cout<<x<<endl;
		  a.pop();
		  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		  //cout<<endl;
      	  if(x==2){
      		  y=a.top();
			  //cout<<y<<endl;
			  a.pop();
      		  if(y==2){
      			  z=a.top();
				  //cout<<z<<endl;
				  a.pop();
      			  if(z==1){
				    a.push(2);
				    symbol[k]++;
				    //cout<<symbol[k]<<endl;
				    //cout<<"YES"<<endl;
		  	        }
      			    else{
					   a.push(z);//,cout<<"NOZZZZ"<<endl;
					   a.push(y);
					   a.push(x);
					   break;
				       }
					  }
      		    else{
				   a.push(y);//,cout<<"NOYYY"<<endl;
      		       a.push(x);
      		       break;
      		       }
				  }
      	    else {
			  a.push(x);//,cout<<"NOXX"<<endl;
			  break;
		      }
      	}
      //cout<<endl<<"............................................."<<endl;
	  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
	  /*int a1,a2,a3;
	  a1=a.top();
	  cout<<a1<<' ';
	  a.pop();
	  a2=a.top();
	  cout<<a2<<' ';
	  a.pop();
	  a3=a.top();
	  cout<<a3<<' ';
	  a.pop();
	  a.push(a3);
	  a.push(a2);
	  a.push(a1);*/
	  }
	  //cout<<a.size()<<endl;
	  while(a.size()>2){
	    x=a.top();
		  //cout<<x<<endl;
		  a.pop();
		  //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		  //cout<<endl;
      	  if(x==2){
      		  y=a.top();
			  //cout<<y<<endl;
			  a.pop();
      		  if(y==2){
      			  z=a.top();
				  //cout<<z<<endl;
				  a.pop();
      			  if(z==1){
				    a.push(2);
				    symbol[k]++;
				    //cout<<symbol[k]<<endl;
				    //cout<<"YES"<<endl;
		  	        }
      			    else{
					   a.push(z);//,cout<<"NOZZZZ"<<endl;
					   a.push(y);
					   a.push(x);
					   break;
				       }
					  }
      		    else{
				   a.push(y);//,cout<<"NOYYY"<<endl;
      		       a.push(x);
      		       break;
      		       }
				  }
      	    else {
			  a.push(x);//,cout<<"NOXX"<<endl;
			  break;
		      }
      	}
      //for(i=1;i<=k;i++)cout<<b[i]<<endl;
      //cout<<"size:"<<a.size()<<endl;
      //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
      //cout<<endl;
      /*for(i=1;i<=3;i++){
      	cout<<a.top()<<endl;
      	a.pop();
        }*/
	  int sum=0;
	  //cout<<symbol[k]<<endl;
      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=k;i++){
      	   if(b[i]==1&&b[i-1]!=2)cout<<"pair<",sum++;
      	     else if(b[i]==1&&b[i-1]==2)cout<<",pair<",sum++;
      	     else if(n>=2){
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int",sum--;
		   while(symbol[i]>0){
		   	cout<<">";
		   	symbol[i]--;
		     }
		  }
	     }
		cout<<endl;
	    }
		else cout<<"Error occurred"<<endl;
	  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
stack<int>a;
int b[500010];
string s[300001];
int main()
{     //freopen("STL.in","r",stdin);
      int i,j=0,n,m,x,y,z,k=0;
      cin>>n;
	  /*getchar();
      getline(cin,s);
	  m=s.length();*/
	  //cout<<m<<endl;
      //for(i=0;i<m;i++)cout<<s[i]<<endl;
      int p=1;
      while(cin>>s[p]){
      	p++;
      }
      for(i=1;i<=p;i++){
      	//cout<<"+1"<<endl;
      	//cout<<i<<endl;
      	//bool f=false;
      	//cout<<s[i]<<s[i+1]<<endl;
      	if(s[i]=="pair")a.push(1),b[++k]=1;
      	if(s[i]=="int")a.push(2),b[++k]=2;
      	//cout<<"size:"<<a.size()<<endl;
      	/*if(!f){
		  //cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;
		  continue;
		  }*/
      	if(a.size()<=2){
		  //cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
		  continue;
		  }
      	//cout<<"size:"<<a.size()<<endl;
        x=a.top();
		//cout<<x<<endl;
		a.pop();
		//for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
		//cout<<endl;
      	if(x==2){
      		y=a.top();
			//cout<<y<<endl;
			a.pop();
      		if(y==2){
      			z=a.top();
				//cout<<z<<endl;
				a.pop();
      			if(z==1){
				  a.push(2);
				  //cout<<"YES"<<endl;
		  	            }
      			  else{
					 a.push(z);//,cout<<"NOZZZZ"<<endl;
					 a.push(y);
					 a.push(x);
				     }
					}
      		  else{
				 a.push(y);//,cout<<"NOYYY"<<endl;
      		     a.push(x);
      		     }
				}
      	  else a.push(x);//,cout<<"NOXX"<<endl;
      //cout<<endl<<"............................................."<<endl;
	  }
      //for(i=1;i<=k;i++)cout<<b[i]<<endl;
      //cout<<"size:"<<a.size()<<endl;
      //for(j=0;j<a.size();j++)cout<<a.top()<<' ',a.pop();
      //cout<<endl;
      /*for(i=1;i<=3;i++){
      	cout<<a.top()<<endl;
      	a.pop();
        }*/
      int sum=0;
      if(a.size()==1&&a.top()==2){
      	for(i=1;i<=k;i++)
      	   if(b[i]==1&&b[i-1]!=2)cout<<"pair<",sum++;
      	     else if(b[i]==1&&b[i-1]==2)cout<<",pair<",sum++;
      	     else if(n>=2){
			     if(b[i-1]==1)cout<<"int";
			       else cout<<",int>",sum--;
			   }
		if(sum>0){
			cout<<">";
			sum--;
		}
		cout<<endl;
		}
		else cout<<"Error occurred"<<endl;
	  return 0;
}