module Yuki open System let solve ss = let inline str2Lis (str : string) = str.ToCharArray() |> Array.map (string >> int) |> Array.toList let inline num2Lis n = let rec f acc x = if x >= 10 then f ((x % 10) :: acc ) (x / 10) else x :: acc f [] n let horoscope (str : string) = 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 = str2Lis str f ns ss |> List.map horoscope let T = Console.ReadLine() |> int let S = List.init T (fun _ -> Console.ReadLine()) solve S |> List.iter Console.WriteLine