fork download
  1. # your code goes here
  2. import math
  3. for _ in range(int(input())):
  4. s=input()
  5. c=0
  6. x=10**9
  7. n=len(s)
  8. for i in range(0,10):
  9. for j in range(0,10):
  10. c=0
  11. f=0
  12. for k in range(0,n):
  13. if s[k]==str(i):
  14. f=1
  15. if s[k]==str(j) and f==1 and i!=j:
  16. f=0
  17. c+=2
  18. t=n-c
  19. x=min(x,t)
  20. for i in range(0,10):
  21. c=0
  22. for j in range(n):
  23. if s[j]==str(i):
  24. c+=1
  25. x=min(x,(n-c))
  26. print(x)
Success #stdin #stdout 0.02s 9360KB
stdin
3
95831
100120013
252525252525
stdout
3
5
0