#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, long long);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int i, j, len, num, temp, t, res;
  long long int x, y, sum;
  char c;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld", &x);
    sum = x;
    scanf(" %c", &c);
    while (c != '=') {
      scanf("%lld", &x);
      if (c == '+')
        sum += x;
      else if (c == '*')
        sum *= x;
      else if (c == '-')
        sum -= x;
      else
        sum /= x;
      scanf(" %c", &c);
    }
    printf("%lld\n", sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     1245 <main+0x125>
lea    0xea7(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xe92(%rip),%rdi
lea    -0x39(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x39(%rbp),%eax
cmp    $0x3d,%eax
je     1230 <main+0x110>
lea    0xe6e(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x39(%rbp),%eax
cmp    $0x2b,%eax
jne    11be <main+0x9e>
mov    -0x28(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1219 <main+0xf9>
movsbl -0x39(%rbp),%eax
cmp    $0x2a,%eax
jne    11dd <main+0xbd>
mov    -0x28(%rbp),%rax
imul   -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1214 <main+0xf4>
movsbl -0x39(%rbp),%eax
cmp    $0x2d,%eax
jne    11fe <main+0xde>
mov    -0x28(%rbp),%rcx
mov    -0x38(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    120f <main+0xef>
mov    -0x28(%rbp),%rcx
mov    -0x38(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x38(%rbp)
jmp    1214 <main+0xf4>
jmp    1219 <main+0xf9>
lea    0xde8(%rip),%rdi
lea    -0x39(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
jmp    1181 <main+0x61>
mov    -0x38(%rbp),%rsi
lea    0xdd1(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0x14(%rsp)
jae    1159 <main+0x39>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xea3(%rip),%r14
lea    0x8(%rsp),%r15
lea    0xe9c(%rip),%r12
lea    0x7(%rsp),%rbx
lea    0xe94(%rip),%r13
jmp    1192 <main+0x72>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
subl   $0x1,0x14(%rsp)
jb     1148 <main+0x28>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%rbp
jmp    11b5 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
sub    0x8(%rsp),%rbp
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpb   $0x3d,0x7(%rsp)
je     1180 <main+0x60>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movzbl 0x7(%rsp),%eax
cmp    $0x2a,%al
je     11f0 <main+0xd0>
cmp    $0x2d,%al
je     11b0 <main+0x90>
cmp    $0x2b,%al
jne    1200 <main+0xe0>
add    0x8(%rsp),%rbp
jmp    11b5 <main+0x95>
xchg   %ax,%ax
imul   0x8(%rsp),%rbp
jmp    11b5 <main+0x95>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rcx
mov    %rbp,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     121e <main+0xfe>
mov    %rbp,%rax
cqto
idiv   %rcx
mov    %rax,%rbp
jmp    11b5 <main+0x95>
mov    %ebp,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%ebp
jmp    11b5 <main+0x95>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8
store i32 0, i32* %1
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
br label %14
14: ; preds = %59, %0
%15 = load i32, i32* %7
%16 = add nsw i32 %15, -1
store i32 %16, i32* %7
%17 = icmp ne i32 %15, 0
br i1 %17, label %18, label %62
18: ; preds = %14
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %9)
%20 = load i64, i64* %9
store i64 %20, i64* %11
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %22
22: ; preds = %57, %18
%23 = load i8, i8* %12
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 61
br i1 %25, label %26, label %59
26: ; preds = %22
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %9)
%28 = load i8, i8* %12
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 43
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i64, i64* %9
%33 = load i64, i64* %11
%34 = add nsw i64 %33, %32
store i64 %34, i64* %11
br label %57
35: ; preds = %26
%36 = load i8, i8* %12
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 42
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i64, i64* %9
%41 = load i64, i64* %11
%42 = mul nsw i64 %41, %40
store i64 %42, i64* %11
br label %56
43: ; preds = %35
%44 = load i8, i8* %12
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 45
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = load i64, i64* %9
%49 = load i64, i64* %11
%50 = sub nsw i64 %49, %48
store i64 %50, i64* %11
br label %55
51: ; preds = %43
%52 = load i64, i64* %9
%53 = load i64, i64* %11
%54 = sdiv i64 %53, %52
store i64 %54, i64* %11
br label %55
55: ; preds = %51, %47
br label %56
56: ; preds = %55, %39
br label %57
57: ; preds = %56, %31
%58 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %22
59: ; preds = %22
%60 = load i64, i64* %11
%61 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %60)
br label %14
62: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8
%4 = bitcast i32* %1 to i8*
%5 = bitcast i64* %2 to i8*
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = add nsw i32 %7, -1
store i32 %8, i32* %1
%9 = icmp eq i32 %7, 0
br i1 %9, label %43, label %10
10: ; preds = %0, %37
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%12 = load i64, i64* %2
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%14 = load i8, i8* %3
%15 = icmp eq i8 %14, 61
br i1 %15, label %37, label %16
16: ; preds = %10, %32
%17 = phi i64 [ %33, %32 ], [ %12, %10 ]
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%19 = load i8, i8* %3
switch i8 %19, label %29 [
i8 43, label %20
i8 42, label %23
i8 45, label %26
]
20: ; preds = %16
%21 = load i64, i64* %2
%22 = add nsw i64 %21, %17
br label %32
23: ; preds = %16
%24 = load i64, i64* %2
%25 = mul nsw i64 %24, %17
br label %32
26: ; preds = %16
%27 = load i64, i64* %2
%28 = sub nsw i64 %17, %27
br label %32
29: ; preds = %16
%30 = load i64, i64* %2
%31 = sdiv i64 %17, %30
br label %32
32: ; preds = %23, %29, %26, %20
%33 = phi i64 [ %22, %20 ], [ %25, %23 ], [ %28, %26 ], [ %31, %29 ]
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%35 = load i8, i8* %3
%36 = icmp eq i8 %35, 61
br i1 %36, label %37, label %16
37: ; preds = %32, %10
%38 = phi i64 [ %12, %10 ], [ %33, %32 ]
%39 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %38)
%40 = load i32, i32* %1
%41 = add nsw i32 %40, -1
store i32 %41, i32* %1
%42 = icmp eq i32 %40, 0
br i1 %42, label %43, label %10
43: ; preds = %37, %0
ret i32 0
}