use std::io::Read; fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let v = s.split_whitespace().skip(1); for s in v { let mut c: Vec<_> = s.chars().flat_map(|c| c.to_digit(10)).collect(); while c.len() > 1 { c = c .windows(2) .map(|n| (n[0] + n[1]) / 10 + (n[0] + n[1]) % 10) .collect(); } println!("{}", c[0]); } }