New update is available. Click here to update.

PostFix To Prefix

Posted: 24 Jun, 2021
Difficulty: Easy

PROBLEM STATEMENT

Try Problem

Ninja has been given a Postfix expression and he needs your help in converting it to Prefix expression.

Postfix expression is an expression where the operator appears in the expression after the operands. Simply of the form (operand1 operand2 operator)

Prefix expression is an expression where the operator appears in the expression before the operands. Simply of the form (operator operand1 operand2)

For Example:

Postfix expression : (A B +)

Prefix expression : (+ A B)
Input Format:
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.

The first line of each test case contains a string ‘S’ which contains the Postfix expression.
Output Format:
For each case, you need to return a string in the prefix expression.

The output of each test case will be printed in a separate line.
Note:
You do not need to input or print anything, and it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 5
1 <= |S| <= 10^5

Timit Limit: 1 sec