import sys

if sys.version_info[0]>=3: raw_input=input



n=int(input())

for i in range(0,n):

	a=[int(e) for e in input().split()]

	a[0]-=1;a[1]-=1

	print((196471-a[0]*195-a[0]//3*5-a[1]*20+(a[1]//2 if a[0]%3!=2 else 0)-a[2]))
n=int(input())

for i in range(0,n):

	y,m,d=[int(e) for e in input().split()]

	y-=1;m-=1

	print((196471-y*195-y//3*5-m*20+(m//2 if y%3!=2 else 0)-d))
import sys

if sys.version_info[0] >= 3:
    raw_input = input
n = int(input())
for i in range(0, n):
    a = [int(e) for e in input().split()]
    a[0] -= 1
    a[1] -= 1
    print(
        (
            196471
            - a[0] * 195
            - a[0] // 3 * 5
            - a[1] * 20
            + (a[1] // 2 if a[0] % 3 != 2 else 0)
            - a[2]
        )
    )

n = int(input())
for i in range(0, n):
    y, m, d = [int(e) for e in input().split()]
    y -= 1
    m -= 1
    print((196471 - y * 195 - y // 3 * 5 - m * 20 + (m // 2 if y % 3 != 2 else 0) - d))

-import sys - -if sys.version_info[0] >= 3: -    raw_input = input -    a = [int(e) for e in input().split()] -    a[0] -= 1 -    a[1] -= 1 -    print( -        ( -            196471 -            - a[0] * 195 -            - a[0] // 3 * 5 -            - a[1] * 20 -            + (a[1] // 2 if a[0] % 3 != 2 else 0) -            - a[2] -        ) -    ) +    y, m, d = [int(e) for e in input().split()] +    y -= 1 +    m -= 1 +    print((196471 - y * 195 - y // 3 * 5 - m * 20 + (m // 2 if y % 3 != 2 else 0) - d))