import scala.io.StdIn._

object PaizaScala {
  def differential2(s: String): Int = s.sortWith(_>_).toInt - s.sorted.toInt

  def results(n: Int, result: Vector[Int] = Vector()): Vector[Int] =
    if (n > 0) results(n - 1, result :+ differential2(readLine()))
    else result

  def main(args: Array[String]) = results(readInt()).foreach(println)
}