object Main extends App {
  import scala.io.StdIn._


  val q = readLine.trim.toInt
  for (_ ← 0 until q){
    val Array(s, t) = readLine.trim.split(' ')
    println(
      s.indices.find(p ⇒ s(p) != t(p)) match {
        case Some(firstMismatch) ⇒ abs(firstMismatch - s.lastIndexOf('1')) + abs(firstMismatch - t.lastIndexOf('1'))
        case None ⇒ 0
      }
    )
  }
  def abs(num: Int): Int = if (num > 0) num else -num
  implicit class ScopeFunc[T](value: T){
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}
