Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??´?????????
"""

while True:
    inp = input().strip().split(" ")
    n = int(inp[0]) + 1
    x = int(inp[1])
    cnt = 0
    if n < 1 and x < 1:
        break
    for i in range(1, n-2):
        for j in range(i + 1, n-1):
            for k in range(j + 1, n):
                t = i + j + k
                if t == x:
                    cnt = cnt + 1
                elif t > x:
                    break
    print(cnt)

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??´?????????
"""

while True:
    inp = input().strip().split(" ")
    n = int(inp[0]) + 1
    x = int(inp[1])
    cnt = 0
    if n < 2 and x < 1:
        break
    for i in range(1, n-2):
        for j in range(i + 1, n-1):
            for k in range(j + 1, n):
                t = i + j + k
                if t == x:
                    cnt = cnt + 1
                elif t > x:
                    break
    print(cnt)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??´?????????
"""
inp = input().strip().split(" ")
row = int(inp[0])
col = int(inp[1])

cells = [[0 for r in range(row+1)] for c in range(col+1)]
for r in range(row):
    inp = input().strip().split(" ")
    for c in range(col):
        cells[r][c] = int(inp[c])
        cells[row][c] += cells[r][c]
        cells[r][col] += cells[r][c]
    cells[row][col] += cells[r][col]

for r in range(row+1):
    print(" ".join(map(str,cells[r])))

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??´?????????
"""
inp = input().strip().split(" ")
row = int(inp[0])
col = int(inp[1])

cells = [[0 for r in range(col+1)] for c in range(row+1)]
for r in range(row):
    inp = input().strip().split(" ")
    for c in range(col):
        cells[r][c] = int(inp[c])
        cells[row][c] += cells[r][c]
        cells[r][col] += cells[r][c]
    cells[row][col] += cells[r][col]

for r in range(row+1):
    print(" ".join(map(str,cells[r])))
Buggy python submission (verdict: Time Limit Exceeded):
input()
s=map(int,raw_input().split())
input()
t=map(int,raw_input().split())

ans=0
for i in t:
    for k in s:
        if i==k:
            ans+=1
            break
print ans

Fixed submission:
n=input()
s=map(int,raw_input().split())
q=input()
t=map(int,raw_input().split())
s.sort()

count=0
for i in t:
    low=1
    hi=n-1
    ce=(low+hi)/2
    while low<=hi:
        if i==s[ce]:
            break
        elif i>s[ce]:
            low=ce+1
        elif i<s[ce]:
            hi=ce-1
        ce=(low+hi)/2
    if i==s[ce]:
        count+=1
print count
Buggy python submission (verdict: Runtime Error):
height = []
while 1:
    h = raw_input()
    if h == '': break
    h = int(h)
    height.append(h)
height.sort(reverse=True)
for i in range(3):
    print height[i]

Fixed submission:
height = []
while 1:
    try:
        height.append(input())
    except EOFError:
        break
height.sort(reverse=True)
for i in range(3):
    print height[i]
Buggy python submission (verdict: Runtime Error):
height = []
while 1:
    try:
        height.append(input())
    except EOFError:
        break
height.sort(reverse=True)
for i in range(3):
    print height[i]

Fixed submission:
while 1:
    try:
        a,b = map(int, raw_input().split())
        n = a+b
        print len(str(n))
    except EOFError:
        break
Buggy python submission (verdict: Runtime Error):
tracks = []
while 1:
    try:
        c = input()
        if c == 0:
            print tracks.pop()
        else:
            tracks.append(c)
    except EOFError:
        break

Fixed submission:
tracks = []
while 1:
    try:
        c0 = raw_input()
        if c0 == '':
            break
        c = int(c0)
        if c == 0:
            print tracks.pop()
        else:
            tracks.append(c)
    except EOFError:
        break

Buggy python submission (verdict: Runtime Error):
tracks = []
while 1:
    try:
        c = input()
        if c == 0:
            print tracks.pop()
        else:
            tracks.append(c)
    except EOFError:
        break

Fixed submission:
tracks = []
while 1:
    try:
        c0 = raw_input()
        if c0 == '':
            break
        c = int(c0)
        if c == 0:
            print tracks.pop()
        else:
            tracks.append(c)
    except EOFError:
        break

Buggy python submission (verdict: Runtime Error):
tracks = []
while 1:
    try:
        c = int(raw_input())
        if c == 0:
            print tracks.pop()
        else:
            tracks.append(c)
    except EOFError:
        break

Fixed submission:
tracks = []
while 1:
    try:
        c0 = raw_input()
        if c0 == '':
            break
        c = int(c0)
        if c == 0:
            print tracks.pop()
        else:
            tracks.append(c)
    except EOFError:
        break

Buggy python submission (verdict: Runtime Error):
tracks = []
while 1:
    try:
        c0 = raw_input()
        c = int(c0)
        if c == 0:
            print tracks.pop()
        else:
            tracks.append(c)
    except EOFError:
        break

Fixed submission:
tracks = []
while 1:
    try:
        c0 = raw_input()
        if c0 == '':
            break
        c = int(c0)
        if c == 0:
            print tracks.pop()
        else:
            tracks.append(c)
    except EOFError:
        break
Buggy python submission (verdict: Runtime Error):
while 1:
        n = input()
        a,b = (0,0)
        for i in range(n):
                x = map(int, raw_input().split())
                if x[0] > x[1]:
                        a += x[0] + x[1]
                elif x[0] < x[1]:
                        b += x[0] + x[1]
                else:
                        a += x[0]
                        b += x[0]
        print str(a) + ' ' + str(b)

Fixed submission:
while 1:
        n = input()
        if n == 0: break
        a,b = (0,0)
        for i in range(n):
                x = map(int, raw_input().split())
                if x[0] > x[1]:
                        a += x[0] + x[1]
                elif x[0] < x[1]:
                        b += x[0] + x[1]
                else:
                        a += x[0]
                        b += x[0]
        print str(a) + ' ' + str(b)
Buggy python submission (verdict: Runtime Error):
while 1:
    m = int(raw_input())
    if m == 0: break
    cm = [10, 50, 100, 500]
    c = map(int, raw_input().split())
    mintn = 81
    fc = [0 for i in xrange(4)]
    for i in xrange(c[0]+1):
        for j in xrange(c[1]+1):
            for k in xrange(c[2]+1):
                for l in xrange(c[3]+1):
                    t = i*cm[0] + j*cm[1] + k*cm[2] + l*cm[3]
                    if t >= m:
                        mc = [0 for n in xrange(4)]
                        mc = [c[0]-i,c[1]-j,c[2]-k,c[3]-l]
                        ch = t-m
                        for n in xrange(3,-1,-1):
                            while(ch >= cm[n]):
                                ch -= cm[n]
                                mc[n] += 1
                        tn = sum(mc)
                        if (tn < mintn):
                            mintn = tn
                            fc = [i,j,k,l]
    for i in xrange(4):
        if fc[i] != 0: print "%d %d" % (cm[i], fc[i])
    print ''

Fixed submission:
loop = False
while 1:
    m = int(raw_input())
    if m == 0: break
    if loop is True: print ''
    cm = [10, 50, 100, 500]
    c = map(int, raw_input().split())
    mintn = 81
    fc = [0 for i in xrange(4)]
    mc = [0 for i in xrange(4)]
    t = 0
    for i in xrange(4):
        t += c[i]*cm[i]
        ch = t-m
    for i in xrange(3,-1,-1):
        while(ch >= cm[i]):
            ch -= cm[i]
            mc[i] += 1
    for i in xrange(4):
        fc[i] = c[i] - mc[i]
        if fc[i] < 0: fc[i] = 0
    for i in xrange(4):
        if fc[i] != 0: print "%d %d" % (cm[i], fc[i])
    loop = True
Buggy python submission (verdict: Runtime Error):
while 1:
    n = int(raw_input())
    if not n: break
    cnt = 1
    t = [0 for i in xrange(24*60*60)]
    for i in xrange(n):
        a = raw_input().split()
        h,m,s = [0,0],[0,0],[0,0]
        for i in xrange(2):
            h[i],m[i],s[i] = map(int, a[i].split(':'))
        t1 = h[0]*60**2 + m[0]*60 + s[0]
        t2 = h[1]*60**2 + m[1]*60 + s[1]
        for i in xrange(t1,t2):
            t[i] += 1

    for i in xrange(24*60*60):
        cnt = max(t[i], cnt)

    print cnt

Fixed submission:
while 1:
    n = int(raw_input())
    if not n: break
    cnt = 0
    m = cnt
    t = []
    for i in xrange(n):
        a = raw_input().split()
        t.append((a[0],2))
        t.append((a[1],1))
    t.sort()
    for i in xrange(len(t)):
        #print t[i]
        if t[i][1] is 2: cnt += 1
        else: cnt -= 1

        m = max(m, cnt)

    print m
Buggy python submission (verdict: Runtime Error):
import sys

while 1:
    x = raw_input()
    if x == 0: break
    poyo = 0
    for i in xrange(len(x)):
        poyo += int(x[i])
    print poyo

Fixed submission:
import sys

while 1:
    x = raw_input()
    if x == '0': break
    poyo = 0
    for i in xrange(len(x)):
        poyo += int(x[i])
    print poyo
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = int(raw_input())
a = map(int, raw_input().split())
q = int(raw_input())
t = map(int, raw_input().split())
cnt = 0
for i in xrange(q-1, -1, -1):
    if t[i] in a:
        t.remove(t[i])
        cnt += 1
print cnt

Fixed submission:
import sys

n = int(raw_input())
a = set(map(int, raw_input().split()))
q = int(raw_input())
t = set(map(int, raw_input().split()))
cnt = 0
print len(t)-len(t-a)
Buggy python submission (verdict: Runtime Error):
import itertools

while True:
    n = int(raw_input())
    c = 0
    for a in itertools.product(range(10), repeat=4):
        if sum(a) == n:
            c += 1
    print c

Fixed submission:
import itertools

while True:
    try:
        n = int(raw_input())
        c = 0
        for a in itertools.product(range(10), repeat=4):
            if sum(a) == n:
                c += 1
        print c
    except EOFError:
        break
Buggy python submission (verdict: Time Limit Exceeded):
while True:
    n = int(raw_input())
    if n == 0:
        break
    a = [0] * n
    for i in range(n):
        a[i] = int(raw_input())
    r = a[0]
    for i in range(n+1):
        for j in range(i+1, n+1):
            r = max(r, sum(a[i:j]))
    print r

Fixed submission:
while True:
    n = int(raw_input())
    if n == 0:
        break
    a = [0] * n
    dp = [0] * n
    for i in range(n):
        a[i] = int(raw_input())
        if i == 0:
            dp[0] = a[0]
        else:
            dp[i] = max(dp[i-1]+a[i], a[i])
    print max(dp)
Buggy python submission (verdict: Runtime Error):
dp = [[0] * 1001 for i in range(11)]
dp[0][0] = 1
for i in range(101):
    for j in range(9, -1, -1):
        for k in range(0, 1001 - i):
            dp[j + 1][k + i] += dp[j][k]

while True:
    n, s = map(int, raw_input().split())
    print dp[n][s]

Fixed submission:
dp = [[0] * 1001 for i in range(11)]
dp[0][0] = 1
for i in range(101):
    for j in range(9, -1, -1):
        for k in range(0, 1001 - i):
            dp[j + 1][k + i] += dp[j][k]
 
while True:
    n, s = map(int, raw_input().split())
    if (n,s) == (0,0):
        break
    print dp[n][s]
Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
a = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n):
    aa = map(int, raw_input().split())
    for j in range(n):
        a[i + 1][j + 1] = a[i][j + 1] + a[i + 1][j] - a[i][j] + aa[j]
m = -10000 * 100 * 100
for i in range(n):
    for j in range(n):
        for k in range(i + 1, n + 1):
            for l in range(j + 1, n + 1):
                r = a[k][l] - a[k][j] - a[i][l] + a[i][j]
                m = max(m, r)
print m

Fixed submission:
n = int(raw_input())
a = [[0] * (n + 1) for _ in range(n + 1)]
m = -10000 * 100 * 100

for i in range(n):
    b = map(int, raw_input().split())
    for j in range(n):
        aa = 0
        for k in range(j, n):
            aa += b[k]
            a[j][k] = max(a[j][k], 0) + aa
            m = max(m, a[j][k])
print m

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
a = [[0] * (n + 1) for _ in range(n + 1)]
for i in xrange(n):
    aa = map(int, raw_input().split())
    for j in range(n):
        a[i + 1][j + 1] = a[i][j + 1] + a[i + 1][j] - a[i][j] + aa[j]
m = -10000 * 100 * 100
for i in xrange(n):
    for j in xrange(n):
        for k in xrange(i + 1, n + 1):
            for l in xrange(j + 1, n + 1):
                r = a[k][l] - a[k][j] - a[i][l] + a[i][j]
                m = max(m, r)
print m

Fixed submission:
n = int(raw_input())
a = [[0] * (n + 1) for _ in range(n + 1)]
m = -10000 * 100 * 100

for i in range(n):
    b = map(int, raw_input().split())
    for j in range(n):
        aa = 0
        for k in range(j, n):
            aa += b[k]
            a[j][k] = max(a[j][k], 0) + aa
            m = max(m, a[j][k])
print m
Buggy python submission (verdict: Runtime Error):
num = int(input()) + int(input())
print(len(str(num)))

Fixed submission:
import sys

for s in sys.stdin:
	a,b = map(int,s.split())
	print len(str(a+b))

Buggy python submission (verdict: Runtime Error):
num = int(input()) + int(input())
print(len(str(num)))

Fixed submission:
import sys

for s in sys.stdin:
	a,b = map(int,s.split())
	print len(str(a+b))
Buggy python submission (verdict: Runtime Error):
while True:
	try:
		list = [int(item) for item in raw_input().split()]
		list.sort()
		if list[0] ** 2 + list[1] ** 2 == list[2] ** 2 :
			print 'YES'
		else :
			print 'NO'
	except EOFError:
		break

Fixed submission:
for i in xrange(input()):
	i,j,k = sorted([int(i) for i in raw_input().split()])
	print "YES" if i**2 + j**2 == k**2 else "NO"
Buggy python submission (verdict: Runtime Error):
import sys

def gcd(a,b):
	if b == 0:
		return a
	else:
		return gcd(b,a%b)

def lcm(a,b):
	return a*b/gcd(a,b)

for s in sys.stdin:
	i = map(int,raw_input().split())
	print gcd(*i), lcm(*i)

Fixed submission:
import sys

def gcd(a,b):
	if b == 0:
		return a
	else:
		return gcd(b,a%b)

def lcm(a,b):
	return a*b/gcd(a,b)

for s in sys.stdin:
	i = map(int,s.split())
	print gcd(*i), lcm(*i)
Buggy python submission (verdict: Time Limit Exceeded):
import sys,random

rand = random.randint

def prime(n):
	if n == 2:
		return True
	if n == 1 or n & 1 == 0:
		return False
	d = n-1
	while d & 1 == 0:
		d >>= 1
	for i in range(20):
		a = rand(1,n-1)
		t = d
		y = pow(a, t, n)
		while t != n-1 and y != 1 and y != n-1:
			y = pow(y,2,n)
			t <<= 1
		if y != n-1 and t & 1 == 0:
			return False
	return True

a = [prime(i) for i in range(1000000)]

for s in sys.stdin:
	i = int(s)
	print(a[:i+1].count(True))

Fixed submission:
import sys

a = [True] * 1000000

for i in range(2,1000000):
	if(a[i-1]):
		for j in range(i**2-1, 1000000, i):
			a[j] = False

for s in sys.stdin:
	print(a[1:int(s)].count(True))

Buggy python submission (verdict: Runtime Error):
import sys

rand = random.randint

def prime(n):
	if n == 2: return True
	if n < 2 or n & 1 == 0: return False
	return pow(2, n-1, n) == 1

a = [prime(i) for i in range(1000000)]

for s in sys.stdin:
	i = int(s)
	print(a[:i+1].count(True))

Fixed submission:
import sys

a = [True] * 1000000

for i in range(2,1000000):
	if(a[i-1]):
		for j in range(i**2-1, 1000000, i):
			a[j] = False

for s in sys.stdin:
	print(a[1:int(s)].count(True))
Buggy python submission (verdict: Runtime Error):
import sys,string
a = string.ascii_lowercase
t = string.maketrans(a,a[1:]+a[0])
        
for s in sys.stdin:
    s = s.strip()
    while not ('the' in s or 'this' in s or 'that' in s):
        s = s.translate(t)
    print s

Fixed submission:
import sys,string
t = string.maketrans('abcdefghijklmnopqrstuvwxyz','bcdefghijklmnopqrstuvwxyza')
for s in sys.stdin:
	s = s.strip()
	while not ('the' in s or 'this' in s or 'that' in s):
		s = s.translate(t)
	print s
Buggy python submission (verdict: Runtime Error):
n = -1
while n != 0:
	n = int(raw_input())
	a = [map(int,raw_input().split()) for i in xrange(n)]
	a = [l + [sum(l)] for l in a]
	a.append([sum([l[i] for l in a]) for i in xrange(len(a[0]))])
	print '\n'.join([''.join([str(i).rjust(5) for i in l]) for l in a])

Fixed submission:
n = int(raw_input())
while n != 0:
	a = [map(int,raw_input().split()) for i in xrange(n)]
	a = [l + [sum(l)] for l in a]
	a.append([sum([l[i] for l in a]) for i in xrange(len(a[0]))])
	print '\n'.join([''.join([str(i).rjust(5) for i in l]) for l in a])
	n = int(raw_input())
Buggy python submission (verdict: Runtime Error):
import string

n = int(raw_input())
while n != 0:
	from = []
	to = []
	for i in xrange(n):
		l = raw_input().split()
		from.append(l[0])
		to.append(l[1])
	a = string.maketrans(''.join(from), ''.join(to))
	s = []
	for i in xrange(int(raw_input())):
		s.append(raw_input().strip())
	print s.translate(a)
	n = int(raw_input())

Fixed submission:
import string

n = int(raw_input())
while n != 0:
	l  = [raw_input().split() for i in xrange(n)]
	f = [i for i,j in l]
	t = [j for i,j in l]
	d = string.maketrans(''.join(f), ''.join(t))
	s = [raw_input().strip() for i in xrange(int(raw_input()))]
	print ''.join(s).translate(d)
	n = int(raw_input())
Buggy python submission (verdict: Runtime Error):
from sys import stdin
from itertools import groupby

a = ['_','.,!? ','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']
for i in input():
	b = [[i for i in j] for i,j in groupby(raw_input())]
	c = []
	d = ''
	for i in b:
		index = int(i[0])
		s = a[index][(len(i))%len(a[index])-1]
		if s == '_':
			d = d + ''.join(c)
			c = []
		else:
			c.append(s)
	if d != '':
		print d

Fixed submission:
from itertools import groupby

a = ['_','.,!? ','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']
for i in xrange(input()):
	b = [[i for i in j] for i,j in groupby(raw_input())]
	c = []
	d = ''
	for i in b:
		index = int(i[0])
		s = a[index][(len(i))%len(a[index])-1]
		if s == '_':
			d = d + ''.join(c)
			c = []
		else:
			c.append(s)
	print d
Buggy python submission (verdict: Runtime Error):
while True:
	try: a,b = map(int,input().split()) ; print len(a+b)
 	excpet EOFError: break

Fixed submission:
import sys
for i in sys.stdin:print len(str(sum(map(int,i.split()))))

Buggy python submission (verdict: Runtime Error):
while True:
	try: a,b = map(int,raw_input().split()) ;print len(a+b)
 	except EOFError: break

Fixed submission:
import sys
for i in sys.stdin:print len(str(sum(map(int,i.split()))))
Buggy python submission (verdict: Runtime Error):
a = raw_input().split()
b = [i for i in a if len(i)==3 or len(i)==4]
c = [i for i in b if ord(i[0])-ord(i[1]) == 12]
s = [ord('t')-ord(c[0][0]),1] if c[0][0]<'t' else [ord(c[0][0])-ord('t'),0]
q=''
for g,i in enumerate(a):
    if g==0:pass
    else: q+=' '
    for j in i:
        if j=='.':
            q+='.'
        elif s[1] == 0:
            q+=chr(ord(j)-s[0])
        elif s[0] == 1:
            q+=chr(ord(j)+s[0])
print q 

Fixed submission:
import sys
a=lambda x: [''.join([chr(97+(ord(i)-97+j)%26) if i.islower() else i for i in x]) for j in range(26)]
value=['this','that','the']
for s in sys.stdin:
    for i in a(s):
        if sum(map(i.count,value))>0:
            print(i[:-1])

Buggy python submission (verdict: Runtime Error):
while True:
    try:
        a = raw_input().split()
        b = [i for i in a if len(i)==3 or len(i)==4]
        c = [i for i in b if ord(i[0])-ord(i[1]) == 12]
        s = [ord('t')-ord(c[0][0]),1] if c[0][0]<'t' else [ord(c[0][0])-ord('t'),0]
        q=''
        for g,i in enumerate(a):
            if g==0:pass
            else: q+=' '
            for j in i:
                if j=='.':
                    q+='.'
                elif s[1] == 0:
                    q+=chr(ord(j)-s[0])
                elif s[0] == 1:
                    q+=chr(ord(j)+s[0])
        print q
    except EOFError:
        break

Fixed submission:
import sys
a=lambda x: [''.join([chr(97+(ord(i)-97+j)%26) if i.islower() else i for i in x]) for j in range(26)]
value=['this','that','the']
for s in sys.stdin:
    for i in a(s):
        if sum(map(i.count,value))>0:
            print(i[:-1])
Buggy python submission (verdict: Runtime Error):
ans ={}
for i in range(1,13):
    if i%2 !=0:
        ans[str(i)] = 31
    else:
        ans[str(i)] = 30
ans['2']=29 
while True:
    a,b=map(int,raw_input().split())
    day =b
    if a+b == 0: break;
    if a == 1:   day = b;
    elif a == 2: day+=31
    else:
        for i in range(a):
            if i ==0: pass;
            day += ans[str(i)]
    print ['Wednesday','Thurday','Friday',
            'Saturday','Sunday','Monday',
            'Tuesday'][day%7]

Fixed submission:
while True:
    q=map(int,raw_input().split())
    if sum(q) == 0: break
    print ['Wednesday','Thursday','Friday','Saturday','Sunday','Monday','Tuesday',0][(sum([0,31,29,31,30,31,30,31,31,30,31,30,31][:q[0]])+q[1])%7]
Buggy python submission (verdict: Runtime Error):
for i in range(input()):
 q,w=[0],[0]
 flag=0
 _L=map(int,raw_input().split())
 q.append(_L[0])
 for j in _L[1:]:
  if q[-1] > w[-1]:
    if q[-1] < j: q.append(j)
    elif w[-1] < j: w.append(j)
    else: 
        flag=1
        break
  if q[-1] < w[-1]:
    if w[-1] < j: w.append(j)
    elif q[-1] < j: q.append(j)
    else: 
        flag=1
        break
 print "YES" if flag==0 else "NO"

Fixed submission:
for i in range(input()):
 	q,w=[0],[0]
 	flag=0
 	_L=map(int,raw_input().split())
 	q.append(_L[0])
 	for j in _L[1:]:
  		if q[-1] > w[-1]:
    		 if q[-1] < j: q.append(j)
    		 elif w[-1] < j: w.append(j)
    		 else: 
        		  flag=1
        		  break
  		if q[-1] < w[-1]:
    		 if w[-1] < j: w.append(j)
    		 elif q[-1] < j: q.append(j)
    		 else: 
        		  flag=1
        		  break
 	print "YES" if flag==0 else "NO"
Buggy python submission (verdict: Runtime Error):
anb2 = lambda a,b: -(abs(int(1.0*a/b)))

def number(begin):
	global i
	
	if begin[i] == "(":
		i += 1
		res = expression(begin)
		i += 1 
		return res
	
	res = 0
	
	while begin[i].isdigit():
		res *= 10
		res += int(begin[i])
		i+=1
	
	return res
	
def term(begin):# your code goes here

	global i
	res = number(begin)
	
	while True:
		if begin[i] == "*":
			i += 1
			res *= number(begin)
		elif begin[i] == "/":
			i += 1
			num = number(begin)
			if res < 0 or num < 0:
				res = abs2(res,num)
			else:
				res /= num
		else:
			break
	return res
	
def expression(begin):
	
	global i
	res = term(begin)
	
	while True:
		if begin[i] == "+":
			i += 1
			res += term(begin)
			
		elif begin[i] == "-":
			i += 1
			res -= term(begin)
		else:
			break
	return res
	

def main():
	global i
	for j in range(input()):
			i = 0
			ex = raw_input() +"="
			ans = expression(ex)
	
			print ans
main()

Fixed submission:
abs2 = lambda a,b: -(abs(int(1.0*a/b)))

def number(begin):
	global i
	
	if begin[i] == "(":
		i += 1
		res = expression(begin)
		i += 1 
		return res
	
	res = 0
	
	while begin[i].isdigit():
		res *= 10
		res += int(begin[i])
		i+=1
	
	return res
	
def term(begin):# your code goes here

	global i
	res = number(begin)
	
	while True:
		if begin[i] == "*":
			i += 1
			res *= number(begin)
		elif begin[i] == "/":
			i += 1
			num = number(begin)
			if res < 0 or num < 0:
				res = abs2(res,num)
			else:
				res /= num
		else:
			break
	return res
	
def expression(begin):
	
	global i
	res = term(begin)
	
	while True:
		if begin[i] == "+":
			i += 1
			res += term(begin)
			
		elif begin[i] == "-":
			i += 1
			res -= term(begin)
		else:
			break
	return res
	

def main():
	global i
	for j in range(input()):
			i = 0
			ex = raw_input() +"="
			ans = expression(ex)
	
			print ans
main()