```/*
cODED by-

__                         __
|  | ____ __  ____________ |__|____
|  |/ /  |  \/  ___/\____ \|  \__  \
|    <|  |  /\___ \ |  |_> >  |/ __ \_
|__|_ \____//____  >|   __/|__(____  /
\/          \/ |__|           \/

*/

#include <bits/stdc++.h>
using namespace std;
//
#define ll long long int
#define ld  double
#define l1(x,y) for(ll i=x;i<y;i++)
#define l2(x,y) for(ll j=x;j<y;j++)
#define l3(x,y) for(ll k=x;k<y;k++)
#define l4(x,y,uu) for(ll o=x;o<y;o+=uu)
#define lminus(x,y) for(ll zz=x;zz>y;zz--)
#define mkp make_pair
#define fi first
#define si second
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define lc <<"\n"
#define esz .size()
#define clr .clear()
#define vii vector<int>
#define vll vector<ll>
#define all(x) x.begin(),x.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//
#define pi 3.141592653589793
#define MOD 1000000007
#define maa LLONG_MAX
#define mii LLONG_MIN
//
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lll ll t;cin>>t; while(t--)
#define kuspia int main()
#define ok return

void aent (  ll *a , ll n )
{
l1(0,n)cin>>a[i];
}

string arrtostr ( ll *a , ll n )
{
ostringstream os;l1(0,n)os<<a[i];string str(os.str());return str;
}

///////////////

kuspia
{
io;

lll
{
ll n ;
cin>>n;

if(n%25 == 0)
{
cout<< 0 lc ;
continue ;
}
string s =  to_string(n) ;
string rs = string ( s.rbegin() , s.rend()) ;
vll v ;
ll f1  = int(rs.find('0'));
ll f2  = int(rs.find('0' , f1+1));
if (f1 != string::npos && f2 != string::npos )
{
v.pb(f2-1);

// cout<<f1 << " " <<f2 lc ;

}

f1  = int(rs.find('5'));
f2  = int(rs.find('7' , f1+1));
if (f1 != string::npos && f2 != string::npos )
{
v.pb(f2-1);

//  cout<<f1 << " " <<f2 lc ;

}

f1  = int(rs.find('0'));
f2  = int(rs.find('5' , f1+1));
if (f1 != string::npos && f2 != string::npos )
{
v.pb(f2-1);

}

f1  = int(rs.find('5'));
f2  = int(rs.find('2' , f1+1));
if (f1 != string::npos && f2 != string::npos )
{
v.pb(f2-1);
//cout<<f1 << " " <<f2 lc ;

}
sort(v.begin() , v.end()) ;
if ( v esz )
cout<<v[0] lc ;

}
}```

```0
3
1
3
2
```