#include <iostream>
using namespace std;
int f(int x)
{
int count=0, temp=x;
while(temp/2>0) {count++; temp/=2;}
temp=x;
while(temp/5>0) {count++; temp/=5;}
return count+1;
}
int main()
{
int m; cin>>m;
while(m--)
{
int n; cin>>n;
int sum=0;
while(n) {sum+=f(n); n/=10;}
cout << sum-1 << endl;
}
return 0;
}