#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);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int m;
  scanf("%d", &m);
  while (m--) {
    long int tot = 0, num;
    char resign = '+', sign;
    while (resign != '=') {
      scanf("%d %c", &num, &sign);
      if (resign == '+')
        tot += num;
      else if (resign == '-')
        tot -= num;
      else if (resign == '*')
        tot *= num;
      else
        tot /= num;
      resign = sign;
    }
    printf("%d\n", tot);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     121d <main+0xfd>
movq   $0x0,-0x10(%rbp)
movb   $0x2b,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x3d,%eax
je     1208 <main+0xe8>
lea    0xe8e(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1a(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x19(%rbp),%eax
cmp    $0x2b,%eax
jne    11a2 <main+0x82>
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11fd <main+0xdd>
movsbl -0x19(%rbp),%eax
cmp    $0x2d,%eax
jne    11c3 <main+0xa3>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    11f8 <main+0xd8>
movsbl -0x19(%rbp),%eax
cmp    $0x2a,%eax
jne    11e2 <main+0xc2>
mov    -0x18(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11f3 <main+0xd3>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    11f8 <main+0xd8>
jmp    11fd <main+0xdd>
mov    -0x1a(%rbp),%al
mov    %al,-0x19(%rbp)
jmp    1161 <main+0x41>
mov    -0x10(%rbp),%rsi
lea    0xdf6(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x20,%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    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0xc(%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    0x10(%rsp),%r15
lea    0xb(%rsp),%r13
lea    0xe98(%rip),%r12
jmp    1192 <main+0x72>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
subl   $0x1,0xc(%rsp)
jb     1148 <main+0x28>
mov    $0x2b,%bl
xor    %ebp,%ebp
jmp    11af <main+0x8f>
nopl   0x0(%rax,%rax,1)
sub    0x10(%rsp),%rbp
movzbl 0xb(%rsp),%ebx
cmp    $0x3d,%bl
je     1180 <main+0x60>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x2a,%bl
je     11e0 <main+0xc0>
cmp    $0x2d,%bl
je     11a0 <main+0x80>
cmp    $0x2b,%bl
jne    11f0 <main+0xd0>
add    0x10(%rsp),%rbp
jmp    11a5 <main+0x85>
cs nopw 0x0(%rax,%rax,1)
nop
imul   0x10(%rsp),%rbp
jmp    11a5 <main+0x85>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rcx
mov    %rbp,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     120e <main+0xee>
mov    %rbp,%rax
cqto
idiv   %rcx
mov    %rax,%rbp
jmp    11a5 <main+0x85>
mov    %ebp,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%ebp
jmp    11a5 <main+0x85>

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

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