#include <iostream>
#include <stdio.h>
#include <string.h>
#define ls t<<1
#define rs t<<1|1
#define midt (tr[t].l+tr[t].r)>>1
using namespace std;
const int maxn=65535+1000;
int que[maxn<<1],lon;
struct
{
int l,r;
int data,lazy,ture;
int hlazy;
}tr[maxn<<3];
void maketree(int t,int l,int r)
{
tr[t].l=l;
tr[t].r=r;
tr[t].data=0;
tr[t].lazy=-1;
tr[t].ture=1;
tr[t].hlazy=0;
if(l==r)
{
que[++lon]=t;
return;
}
int mid=midt;
maketree(ls,l,mid);
maketree(rs,mid+1,r);
}
void pushdown(int t)
{
tr[ls].hlazy=tr[rs].hlazy=0;
tr[ls].data=tr[rs].data=tr[t].lazy;
tr[ls].lazy=tr[rs].lazy=tr[t].lazy;
tr[ls].ture=tr[rs].ture=1;
tr[t].lazy=-1;
}
void pushdownh(int t)
{
tr[ls].data^=1;
tr[rs].data^=1;
if(tr[ls].lazy!=-1) tr[ls].lazy^=1;
else tr[ls].hlazy+=tr[t].hlazy;
if(tr[rs].lazy!=-1) tr[rs].lazy^=1;
else tr[rs].hlazy+=tr[t].hlazy;
tr[ls].hlazy&=1;
tr[rs].hlazy&=1;
tr[t].hlazy=0;
}
void modify(int t,int l,int r,int tmp)
{
if(l<=tr[t].l&&r>=tr[t].r)
{
if(tmp==1)
{
tr[t].ture=tr[t].data=tr[t].lazy=1;
tr[t].hlazy=0;
}
else if(tmp==2)
{
tr[t].ture=1;
tr[t].data=tr[t].lazy=0;
tr[t].hlazy=0;
}
else if(tr[t].ture)
{
tr[t].data^=1;
tr[t].lazy=tr[t].data;
tr[t].hlazy=0;
}
else
{
if(tr[t].lazy!=-1) tr[t].lazy^=1;
else tr[t].hlazy=(tr[t].hlazy+1)&1;
}
return;
}
if(tr[t].hlazy)
pushdownh(t);
if(tr[t].lazy!=-1)
pushdown(t);
int mid=midt;
if(l<=mid) modify(ls,l,r,tmp);
if(mid+1<=r) modify(rs,l,r,tmp);
if(tr[ls].ture&&tr[rs].ture&&(tr[ls].data==tr[rs].data))
{
tr[t].ture=1;
tr[t].data=tr[ls].data;
}
else
tr[t].ture=0;
}
int main()
{
//
freopen("in.txt","r",stdin);
lon=0;
maketree(1,1,65550*2);
char tmp[10],txt[10];
int l,r;
while(scanf("%s",tmp)!=EOF)
{
scanf(" %c%d,%d%c",&txt[0],&l,&r,&txt[4]);
l=(l+1)<<1;
r=(r+1)<<1;
r--;
if(txt[0]=='[')
l--;
if(txt[4]==')')
r--;
if(l>r)
{
if(tmp[0]=='I'||tmp[0]=='C')
{
modify(1,1,65550*2,2);
}
continue;
}
if(tmp[0]=='U')
{
modify(1,l,r,1);
}
else if(tmp[0]=='I')
{
modify(1,r+1,65550*2,2);
if(1<=l-1)
modify(1,1,l-1,2);
}
else if(tmp[0]=='D')
{
modify(1,l,r,2);
}
else if(tmp[0]=='C')
{
modify(1,l,r,3);
if(1<=l-1)
modify(1,1,l-1,2);
modify(1,r+1,65550*2,2);
}
else
{
modify(1,l,r,3);
}
}
for(int i=1;i<=65550*2*2;i++)
{
if(tr[i].hlazy) pushdownh(i);
if(tr[i].lazy!=-1) pushdown(i);
}
int k=1;
int ture=0;
while(k<=lon)
{
while(!tr[que[k]].data&&k<=lon) k++;
if(k>lon) break;
if(ture) printf(" ");
if(k%2==0) printf("(");
else printf("[");
printf("%d,",(k+1)/2-1);
while(tr[que[k]].data) k++;
printf("%d",(k+1)/2-1);
if((k-1)%2==0) printf(")");
else printf("]");
ture=1;
}
if(!ture)
printf("empty set");
return 0;
}