#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[2];
  long long n, a, res;
  scanf("%lld", &n);
  while (n--) {
    operator[0] = '\0';
    scanf("%lld", &res);
    while (1) {
      scanf("%s", operator);
      if (operator[0] == '=') {
        break;
      }
      scanf("%lld", &a);
      switch (operator[0]) {
      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,-0x6(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    -0x6(%rbp),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x6(%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 -0x6(%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    0xe(%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,0xe(%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,0xe(%rsp)
je     1190 <main+0x70>
mov    %r15,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movsbl 0xe(%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 [2 x 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 = %44, %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 %47
11: ; preds = %7
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
store i8 0, i8* %12
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %5)
br label %14
14: ; preds = %11, %43
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 61
br i1 %20, label %21, label %22
21: ; preds = %14
br label %44
22: ; preds = %14
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %4)
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
switch i32 %26, label %43 [
i32 43, label %27
i32 45, label %31
i32 42, label %35
i32 47, label %39
]
27: ; preds = %22
%28 = load i64, i64* %4
%29 = load i64, i64* %5
%30 = add nsw i64 %29, %28
store i64 %30, i64* %5
br label %43
31: ; preds = %22
%32 = load i64, i64* %4
%33 = load i64, i64* %5
%34 = sub nsw i64 %33, %32
store i64 %34, i64* %5
br label %43
35: ; preds = %22
%36 = load i64, i64* %4
%37 = load i64, i64* %5
%38 = mul nsw i64 %37, %36
store i64 %38, i64* %5
br label %43
39: ; preds = %22
%40 = load i64, i64* %4
%41 = load i64, i64* %5
%42 = sdiv i64 %41, %40
store i64 %42, i64* %5
br label %43
43: ; preds = %22, %39, %35, %31, %27
br label %14
44: ; preds = %21
%45 = load i64, i64* %5
%46 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %45)
br label %7
47: ; 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 [2 x i8]
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%6 = bitcast i64* %2 to i8*
%7 = bitcast i64* %3 to i8*
%8 = bitcast i64* %4 to i8*
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
%10 = load i64, i64* %2
%11 = add nsw i64 %10, -1
store i64 %11, i64* %2
%12 = icmp eq i64 %10, 0
br i1 %12, label %48, label %13
13: ; preds = %0, %42
store i8 0, i8* %5
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %4)
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%16 = load i8, i8* %5
%17 = icmp eq i8 %16, 61
br i1 %17, label %42, label %18
18: ; preds = %13, %38
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %3)
%20 = load i8, i8* %5
%21 = sext i8 %20 to i32
switch i32 %21, label %38 [
i32 43, label %22
i32 45, label %26
i32 42, label %30
i32 47, label %34
]
22: ; preds = %18
%23 = load i64, i64* %3
%24 = load i64, i64* %4
%25 = add nsw i64 %24, %23
store i64 %25, i64* %4
br label %38
26: ; preds = %18
%27 = load i64, i64* %3
%28 = load i64, i64* %4
%29 = sub nsw i64 %28, %27
store i64 %29, i64* %4
br label %38
30: ; preds = %18
%31 = load i64, i64* %3
%32 = load i64, i64* %4
%33 = mul nsw i64 %32, %31
store i64 %33, i64* %4
br label %38
34: ; preds = %18
%35 = load i64, i64* %3
%36 = load i64, i64* %4
%37 = sdiv i64 %36, %35
store i64 %37, i64* %4
br label %38
38: ; preds = %18, %34, %30, %26, %22
%39 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%40 = load i8, i8* %5
%41 = icmp eq i8 %40, 61
br i1 %41, label %42, label %18
42: ; preds = %38, %13
%43 = load i64, i64* %4
%44 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %43)
%45 = load i64, i64* %2
%46 = add nsw i64 %45, -1
store i64 %46, i64* %2
%47 = icmp eq i64 %45, 0
br i1 %47, label %48, label %13
48: ; preds = %42, %0
ret i32 0
}