#include <iostream>
#include <algorithm>
#define MAX_SIZE 50
using namespace std;

class InfixToPrePost{
public:
    /** Initialize your data structure here. */
    char a[MAX_SIZE];
	int top;
	
    InfixToPrePost() {
        top = -1;
    }
    
	void push(char c){
		if(top == MAX_SIZE - 1){
			cout<<"Stack is full\n";
			return;
		}
		
		a[++top] = c;
	}
	
	char topElement(){
		return a[top];
	}
	
	char pop(){
		return a[top--];
	}
	
	bool isEmpty(){
		return top == -1;
	}
	
	int priority(char c){
		if(c == '(')
			return 0;
		
		if(c == '+' || c== '-')
			return 1;
		
		if(c == '*' || c == '/' || c == '%')
			return 2;
		
		if(c == '^')
			return 3;
		
		return 0;
	}
	
	string convertToPostfix(string inp){
		string ans = "";
		
		for(int i = 0; i < inp.length(); ++i){
			
			if(isalnum(inp[i])){
				ans += inp[i];
			}
			else if(inp[i] == '('){
				push('(');
			}
			else if(inp[i] == ')'){
				char t;
				
				while((t = pop()) != '(')
					ans += t;
			}
			else{
				while(!isEmpty() && priority(topElement()) >= priority(inp[i])){
					ans += pop();
				}
				
				push(inp[i]);
			}
		}
		
		while(!isEmpty()){
			ans += pop();
		}
		
		return ans;
	}
	
	string convertToPrefix(string inp){
		
		int len = inp.length();
		
		for(int i = 0; i < len/2 + 1; ++i){
			char t = (inp[i] == '(' ? ')' : (inp[i] == ')' ? '(': inp[i]));
			inp[i] = (inp[len-i-1] == '(' ? ')' : (inp[len-i-1]  == ')' ? '(': inp[len-i-1]));
			inp[len-i-1] = t;
		}
		
		// cout<<inp<<"\n";
		
		inp = convertToPostfix(inp);
		
		reverse(inp.begin(), inp.end());
		
		return inp;
	}
};


int main() {
// 	ios::sync_with_stdio(0);
// 	cin.tie(0);
	
	string inp;
	
	cin>>inp;
	
	InfixToPrePost obj;
	
	cout<<"Postfix: "<<obj.convertToPostfix(inp)<<"\n";
	
	cout<<"Prefix: "<<obj.convertToPrefix(inp)<<"\n";
	
	return 0;
}