def exam(x):
if list1[1] < 16:
list1[0] = list1[0] - 10
if list1[0] <= 0:
print(0)
else:
print(list1[0])
elif list1[1] >=20:
list1[0] = list1[0] - list1[1] - 20
if list1[0] == 0:
print(0)
else:
print(list1[0])
else:
print(list1[0])
a = int(input())
for i in range(a):
list1 = list(map(int,input().split()))
exam(list1)