#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() {
  char operator;
  long long n, a, res;
  scanf("%lld", &n);
  while (n--) {
    operator= 0;
    scanf("%lld", &res);
    while (1) {
      scanf("%s", &operator);
      if (operator== '=') {
        break;
      }
      scanf("%lld", &a);
      switch (operator) {
      case '+':
        res += a;
        break;
      case '-':
        res -= a;
        break;
      case '*':
        res *= a;
        break;
      case '/':
        res /= a;
        break;
      }
    }
    printf("%lld\n", res);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xee2(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     1232 <main+0x112>
movb   $0x0,-0x5(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xea6(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x3d,%eax
jne    1194 <main+0x74>
jmp    121d <main+0xfd>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x5(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5,%eax
ja     1218 <main+0xf8>
mov    -0x28(%rbp),%rax
lea    0xe39(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1218 <main+0xf8>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1218 <main+0xf8>
mov    -0x18(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1218 <main+0xf8>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
jmp    1170 <main+0x50>
mov    -0x20(%rbp),%rsi
lea    0xdf8(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xee3(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subq   $0x1,0x20(%rsp)
jae    115a <main+0x3a>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xeb7(%rip),%r15
lea    0xeb5(%rip),%r12
lea    0xf(%rsp),%rbx
lea    0xeac(%rip),%r13
lea    0x18(%rsp),%rbp
lea    0xe80(%rip),%r14
jmp    11a5 <main+0x85>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%rsp),%rsi
mov    %r13,%rdi
call   1030 <printf@plt>
subq   $0x1,0x20(%rsp)
jb     1149 <main+0x29>
movb   $0x0,0xf(%rsp)
mov    %r15,%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
jmp    11d0 <main+0xb0>
mov    0x18(%rsp),%rax
sub    %rax,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpb   $0x3d,0xf(%rsp)
je     1190 <main+0x70>
mov    %r15,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movsbl 0xf(%rsp),%eax
add    $0xffffffd6,%eax
cmp    $0x5,%eax
ja     11d0 <main+0xb0>
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
mov    0x10(%rsp),%rax
imul   0x18(%rsp),%rax
mov    %rax,0x10(%rsp)
jmp    11d0 <main+0xb0>
mov    0x18(%rsp),%rax
add    %rax,0x10(%rsp)
jmp    11d0 <main+0xb0>
mov    0x18(%rsp),%rcx
mov    0x10(%rsp),%rax
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1247 <main+0x127>
cqto
idiv   %rcx
mov    %rax,0x10(%rsp)
jmp    11d0 <main+0xb0>
xor    %edx,%edx
div    %ecx
mov    %rax,0x10(%rsp)
jmp    11d0 <main+0xb0>

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

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