```go
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var t int
fmt.Fscan(reader, &t)
for i := 0; i < t; i++ {
var s string
fmt.Fscan(reader, &s)
ans := len(s)
targets := []string{"00", "25", "50", "75"}
for _, sub := range targets {
r := strings.LastIndexByte(s, sub[1])
if r != -1 {
l := strings.LastIndexByte(s[:r], sub[0])
if l != -1 {
moves := len(s) - l - 2
if moves < ans {
ans = moves
}
}
}
}
fmt.Fprintln(writer, ans)
}
}
```