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

let n = read_int() in main n;;