n = gets.to_i

n.times do
  f = 0
  even = 0
  odd = 0
  a = gets.chomp.split("").map(&:to_s).reverse!
  for i in 1..15
    case f
    when 0
      x = (a[i].to_i * 2).to_s
      if x.size > 1
        even += (x[0].to_i + x[1].to_i)
      else
        even += x.to_i
      end
      f = 1
    when 1
      odd += a[i].to_i
      f = 0
    end
  end
  sum = even + odd
  for i in 0..9
    if (sum + i) % 10 == 0
      puts i
      break
    end
  end
end