
let main n =
	if n>0 then Scanf.sscanf (read_line ()) "%d %d %d" (fun y m d ->
		print_int (196471-((y-1)*195)-(div (y-1) 3)*5-(m-1)*20+(if ((mod y 3)==0) then 0 else (div (m-1) 2))-d); print_string "\n";main (n-1)
	);;

let n = read_int() in main n;;