#include <stdio.h>
#include <ctype.h>
#include <string.h>

#define MAX 100

// Function to evaluate a single postfix expression
void evaluatePostfix(char expr[]) {
    int stack[MAX];
    int top = -1;
    int i, a, b;

    for (i = 0; expr[i] != '\0'; i++) {
        char ch = expr[i];

        if (isdigit(ch)) {
            // push operand
            stack[++top] = ch - '0';
        } else if (ch == '+' || ch == '-' || ch == '*' || ch == '/') {
            // need at least 2 operands
            if (top < 1) {
                printf("Invalid input\n");
                return;
            }
            b = stack[top--];
            a = stack[top--];

            switch (ch) {
                case '+': stack[++top] = a + b; break;
                case '-': stack[++top] = a - b; break;
                case '*': stack[++top] = a * b; break;
                case '/':
                    if (b == 0) {
                        printf("Invalid input\n");
                        return;
                    }
                    stack[++top] = a / b;
                    break;
            }
        } else {
            // invalid character
            printf("Invalid input\n");
            return;
        }
    }

    // final result must be exactly one value
    if (top != 0) {
        printf("Invalid input\n");
    } else {
        printf("%d\n", stack[top]);
    }
}

int main() {
    int n, i;
    char expr[MAX + 1];

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%s", expr);
        evaluatePostfix(expr);
    }

    return 0;
}c