https://www.acmicpc.net/problem/15953
n=int(input())
for i in range(n):
a,b=map(int,input().split())
na=0
nb=0
if a==0: na=0
elif a==1: na=5000000
elif a<=3: na=3000000
elif a<=6: na=2000000
elif a<=10: na=500000
elif a<=15: na=300000
elif a<=21: na=100000
if b==0: nb=0
elif b==1: nb=5120000
elif b<=3: nb=2560000
elif b<=7: nb=1280000
elif b<=15: nb=640000
elif b<=31: nb=320000
print(na+nb)