module Yuki open System let solve ss = let num2Lis n = let rec f acc x = if x >= 10L then f ((x % 10L) :: acc ) (x / 10L) else x :: acc f [] n let horoscope n = let rec f = function | [] -> failwith "" | x :: [] -> x | xs -> let ns = xs |> List.pairwise |> List.map ((fun (a, b) -> a + b) >> num2Lis >> List.sum) f ns let ns = num2Lis n f ns let ns = ss |> List.map int64 ns |> List.map horoscope let T = Console.ReadLine() |> int let S = List.init T (fun _ -> Console.ReadLine()) solve S |> List.iter Console.WriteLine