#include<cstdio>
const int maxn = 1011;
int main()
{
FILE* fp = fopen("input1.txt","r+");
char ss[maxn],ch;
int wordptr = 0,oldptr = 0,septr = 0;
int top = -1;
while(EOF != fscanf(fp,"%c",&ch))
{
if(ch != '!'&&ch != '*'&&ch != '>')
{
if(ch == ' ')
{
ss[++top] = ch;
//putchar(ch);
wordptr = top + 1;
continue;
}
if(ch == '\n')
{
ss[++top] = ch;
//printf("****!!!!*****");
oldptr = septr;
wordptr = septr = top + 1;
continue;
}
if(ch<= '9' &&ch >= '0')
{
continue;
}
else
{
ss[++top] = ch;
continue;
}
}
if(ch == '!')
{
top--;
continue;
}
if(ch == '*')
{
top = oldptr - 1;
wordptr = septr = top + 1;
continue;
}
if(ch == '>')
{
if('a' <= ss[wordptr] && ss[wordptr] <='z') ss[wordptr] += 'Z' - 'z';
else if('A' <= ss[wordptr] && ss[wordptr] <='Z') ss[wordptr] += 'z' - 'Z';
continue;
}
}
ss[++top] = '\0';
puts(ss);
return 0;