description: You are given an integer n. In 1 move, you can do one of the following actions:
  
    * erase any digit of the number (it's acceptable that the number before the operation has exactly one digit and after the operation, it is "empty"); 
    * add one digit to the right. 
  
  
  
  The actions may be performed in any order any number of times.
  
  Note that if, after deleting some digit from a number, it will contain leading zeroes, they will not be deleted. E.g. if you delete from the number 301 the digit 3, the result is the number 01 (not 1).
  
  You need to perform the minimum number of actions to make the number any power of 2 (i.e. there's an integer k (k ≥ 0) such that the resulting number is equal to 2^k). The resulting number must not have leading zeroes.
  
  E.g. consider n=1052. The answer is equal to 2. First, let's add to the right one digit 4 (the result will be 10524). Then let's erase the digit 5, so the result will be 1024 which is a power of 2.
  
  E.g. consider n=8888. The answer is equal to 3. Let's erase any of the digits 8 three times. The result will be 8 which is a power of 2.
  
  Input
  
  The first line contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow.
  
  Each test case consists of one line containing one integer n (1 ≤ n ≤ 10^9).
  
  Output
  
  For each test case, output in a separate line one integer m — the minimum number of moves to transform the number into any power of 2.
  
  Example
  
  Input
  
  
  12
  1052
  8888
  6
  75
  128
  1
  301
  12048
  1504
  6656
  1000000000
  687194767
  
  
  Output
  
  
  2
  3
  1
  3
  0
  0
  2
  1
  3
  4
  9
  2
  
  Note
  
  The answer for the first test case was considered above.
  
  The answer for the second test case was considered above.
  
  In the third test case, it's enough to add to the right the digit 4 — the number 6 will turn into 64.
  
  In the fourth test case, let's add to the right the digit 8 and then erase 7 and 5 — the taken number will turn into 8.
  
  The numbers of the fifth and the sixth test cases are already powers of two so there's no need to make any move.
  
  In the seventh test case, you can delete first of all the digit 3 (the result is 01) and then the digit 0 (the result is 1).
solution: 
  import java.util.*;
  import java.lang.*;
  import java.io.*;
  import java.math.BigInteger;
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.DataInputStream;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.math.BigInteger;
  import java.util.List;
  import java.util.Map;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  public class third
  {	
  	 static class Reader {
  		 
  	        final private int BUFFER_SIZE = 1 << 16;
  	        private DataInputStream din;
  	        private byte[] buffer;
  	        private int bufferPointer, bytesRead;
  	 
  	        public Reader()
  	        {
  	            din = new DataInputStream(System.in);
  	            buffer = new byte[BUFFER_SIZE];
  	            bufferPointer = bytesRead = 0;
  	        }
  	 
  	        public Reader(String file_name) throws IOException
  	        {
  	            din = new DataInputStream(
  	                new FileInputStream(file_name));
  	            buffer = new byte[BUFFER_SIZE];
  	            bufferPointer = bytesRead = 0;
  	        }
  	 
  	        public String readLine() throws IOException
  	        {
  	            byte[] buf = new byte[64]; // line length
  	            int cnt = 0, c;
  	            while ((c = read()) != -1) {
  	                if (c == '\n') {
  	                    if (cnt != 0) {
  	                        break;
  	                    }
  	                    else {
  	                        continue;
  	                    }
  	                }
  	                buf[cnt++] = (byte)c;
  	            }
  	            return new String(buf, 0, cnt);
  	        }
  	 
  	        public int nextInt() throws IOException
  	        {
  	            int ret = 0;
  	            byte c = read();
  	            while (c <= ' ') {
  	                c = read();
  	            }
  	            boolean neg = (c == '-');
  	            if (neg)
  	                c = read();
  	            do {
  	                ret = ret * 10 + c - '0';
  	            } while ((c = read()) >= '0' && c <= '9');
  	 
  	            if (neg)
  	                return -ret;
  	            return ret;
  	        }
  	 
  	        public long nextLong() throws IOException
  	        {
  	            long ret = 0;
  	            byte c = read();
  	            while (c <= ' ')
  	                c = read();
  	            boolean neg = (c == '-');
  	            if (neg)
  	                c = read();
  	            do {
  	                ret = ret * 10 + c - '0';
  	            } while ((c = read()) >= '0' && c <= '9');
  	            if (neg)
  	                return -ret;
  	            return ret;
  	        }
  	 
  	        public double nextDouble() throws IOException
  	        {
  	            double ret = 0, div = 1;
  	            byte c = read();
  	            while (c <= ' ')
  	                c = read();
  	            boolean neg = (c == '-');
  	            if (neg)
  	                c = read();
  	 
  	            do {
  	                ret = ret * 10 + c - '0';
  	            } while ((c = read()) >= '0' && c <= '9');
  	 
  	            if (c == '.') {
  	                while ((c = read()) >= '0' && c <= '9') {
  	                    ret += (c - '0') / (div *= 10);
  	                }
  	            }
  	 
  	            if (neg)
  	                return -ret;
  	            return ret;
  	        }
  	 
  	        private void fillBuffer() throws IOException
  	        {
  	            bytesRead = din.read(buffer, bufferPointer = 0,
  	                                 BUFFER_SIZE);
  	            if (bytesRead == -1)
  	                buffer[0] = -1;
  	        }
  	 
  	        private byte read() throws IOException
  	        {
  	            if (bufferPointer == bytesRead)
  	                fillBuffer();
  	            return buffer[bufferPointer++];
  	        }
  	 
  	        public void close() throws IOException
  	        {
  	            if (din == null)
  	                return;
  	            din.close();
  	        }
  	 }
  	 public static long gcd(long x, long p)
  	    {
  	        if (x == 0)
  	            return p;
  	         
  	        return gcd(p%x, x);
  	    }
  	 static int sieve =  1000000 ;
  
  
  	 static boolean[] prime =  new boolean[sieve + 1] ;
  
  	 public static void sieveOfEratosthenes() 
  	     { 
  	         // FALSE == prime and 1 // TRUE ==  COMPOSITE
  	         
  	         // time complexity = 0(NlogLogN)== o(N)
  	         
  	         // gives prime nos bw 1 to N // size - 1e7(at max)
  	         
  	         for(int i = 4; i<= sieve ; i++)
  	         {
  	             prime[i] = true  ; i++ ;
  	            
  	         }
  	         
  	         for(int p = 3; p*p <= sieve; p++) 
  	         { 
  	            if(prime[p] == false) 
  	             { 
  	                     for(int i = p*p; i <= sieve; i += p) 
  	                     prime[i] = true; 
  	             } 
  	             
  	             p++ ;
  	         } 
  	           
  	     } 
  	 public static void arrInpInt(int [] arr, int n) throws IOException
  	 {
  		 Reader reader = new Reader();
  		 for(int i=0;i<n;i++)
  	   		{
  	   			arr[i]=reader.nextInt();	
  	   		}
  	 }
  	 public static void arrInpLong(long [] arr, int n) throws IOException
  	 {
  		 Reader reader = new Reader();
  		 for(int i=0;i<n;i++)
  	   		{
  	   			arr[i]=reader.nextLong();	
  	   		}
  	 }
  	 public static void printArr(int[] arr)
  	 {
  		 for(int i=0;i<arr.length;i++)
  		 {
  			 System.out.print(arr[i]+" ");
  		 }
  		 System.out.println();
  	 }
  	 public static int[] decSort(int[] arr)
  	 {
  		  int[] arr1 = Arrays.stream(arr).boxed().sorted(Collections.reverseOrder()).mapToInt(Integer::intValue).toArray();	
  		  return arr1;
  	 }
  	 
  //	public static int binarySearch(int l, int r, int x)
  //	    {
  //	        if (r >= l) {
  //	            int mid = l + (r - l) / 2;
  //	            if (arr[mid] == x)
  //	                return mid;
  //	            if (arr[mid] > x)
  //	                return binarySearch(arr, l, mid - 1, x);
  //	            return binarySearch(arr, mid + 1, r, x);
  //	        }
  //	        return -1;
  //	    }
  	public static long binarySearch2(long l, long r, long sum,int N)
      {
  		if(r<l)return l;
          if (r >= l) {
              long mid = l + (r - l) / 2;
              if (mid*(N-1) == sum)
                  return mid;
              if(mid*(N-1)>sum &&(mid-1)*(N-1)<sum)return mid;
              if (mid*(N-1)> sum)
                  return binarySearch2(l, mid-1, sum,N);
              return binarySearch2( mid + 1,r,sum,N );
          }
          return -1;
      }
  	//if present - return the first occurrence of the no
  	//not present- return the index of next greater value 
  	//if greater than all the values return N(taking high=N-1)
  	//if smaller than all the values return 0(taking low =0)
  	static int lower_bound(int arr[], int low,
  	             int high, int X)
  	{
  
  	 if (low > high) {
  	     return low;
  	 }
  	 int mid = low + (high - low) / 2;
  	 if (arr[mid] >= X) {
  	     return lower_bound(arr, low,
  	                        mid - 1, X);
  	 }
  
  	 return lower_bound(arr, mid + 1,
  	                    high, X);
  	}
  	//if present - return the index of next greater value
  	//not present- return the index of next greater value 
  	//if greater than all the values return N(taking high=N-1)
  	//if smaller than all the values return 0(taking low =0)
  	
  	
  	 public static class Pair  {// comparator with class
  		    int x;
  		    int y;
  		 public Pair(int x, int y)
  		    {
  		        this.x = x;
  		        this.y = y;
  		    }
  		}
  
  	 private static HashMap sortValues(HashMap<Integer,ArrayList<Integer>> map)   
  	 {   
  	 List list = new LinkedList(map.entrySet());    
  	 Collections.sort(list, new Comparator()   
  	 {  
  	 public int compare(Object o1, Object o2)   
  	 {  
  	 return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue());  
  	 }  
  	 });  
  	 //copying the sorted list in HashMap to preserve the iteration order  
  	 HashMap sortedHashMap = new LinkedHashMap();  
  	 for (Iterator it = list.iterator(); it.hasNext();)   
  	 {  
  	  Map.Entry entry = (Map.Entry) it.next();  
  	 sortedHashMap.put(entry.getKey(), entry.getValue());  
  	 }   
  	 return sortedHashMap;  
  	 }  
  	 //public static HashMap<String,Integer> DP=new HashMap<String,Integer>();
  	//public static HashMap<Long,Integer> factor= new HashMap<Long,Integer>();
  	public static int[] arr=new int[1001];
  	public static  void rec()
  	{
  		int i=1;
  		arr[1]=1;
  		i++;
  		int count=2;
  		while(i<1001)
  		{
  			String s=""+count;
  			if(count%3!=0 && s.charAt(s.length()-1)!='3')
  			{
  				arr[i]=count;
  				i++;
  			}
  			count++;
  		}
  	}
  	static int lcs(String str1, String str2, int m, int n)
      {
          int L[][] = new int[m + 1][n + 1];
          int i, j;
          for (i = 0; i <= m; i++) {
              for (j = 0; j <= n; j++) {
                  if (i == 0 || j == 0)
                      L[i][j] = 0;
   
                  else if (str1.charAt(i - 1)
                           == str2.charAt(j - 1))
                      L[i][j] = L[i - 1][j - 1] + 1;
   
                  else
                      L[i][j] = Math.max(L[i - 1][j],
                                         L[i][j - 1]);
              }
          }
   
          // L[m][n] contains length of LCS
          // for X[0..n-1] and Y[0..m-1]
          return L[m][n];
      }
   
      // function to find minimum number
      // of deletions and insertions
      static int func(String str1,
                                       String str2)
      {
          int m = str1.length();
          int n = str2.length();
   
          int len = lcs(str1, str2, m, n);
   
  //        System.out.println("Minimum number of "
  //                           + "deletions = ");
  //        System.out.println(m - len);
  // 
  //        System.out.println("Minimum number of "
  //                           + "insertions = ");
  //        System.out.println(n - len);
          return (m+n-2*len);
      }
  	public static void main(String args[]) throws NumberFormatException, IOException ,java.lang.Exception
  	{
  		
  		Reader reader = new Reader();
  		String[] strings=new String[63];
  		long ind=1;
  		for(int i=0;i<63;i++)
  		{
  			strings[i]=(""+ind);
  			ind=(ind<<1);
  		}
  		//System.out.println(strings[62]);
  		//System.out.println(strings);
  		//rec();
  		//sieveOfEratosthenes();
  		//System.out.println(prime[0]+" "+prime[1]+" "+prime[2]+" "+prime[3]+" "+prime[4]);
  		//Scanner reader=new Scanner(System.in);
  		//BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
  		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  		int cases=Integer.parseInt(br.readLine());
  		//int cases=0;
  		//int cases=reader.nextInt();
  	//	System.out.println(Integer.toBinaryString(1024));
     	while (cases-->0){
     		//maxheap x=new maxheap();
     		//int N=reader.nextInt();
     		
     	 //PriorityQueue<Long> Q = new PriorityQueue<Long>();
     		//int S=reader.nextInt();
     		
     		//int circum=reader.nextInt();
     		//int K=reader.nextInt();
     		//int N=Integer.parseInt(br.readLine());
     		//String[] first=br.readLine().split(" ");
     		//int X=Integer.parseInt(first[0]);
     		//int Y=Integer.parseInt(first[1]);
     		//int X=reader.nextInt();
     		//int Y=reader.nextInt();
     		String str=br.readLine();
     		//int max=Integer.MIN_VALUE;
     		//int min=Integer.MAX_VALUE;
     		//HashMap<String,Integer> map=new HashMap<String,Integer>();
     		//HashSet<Integer> map=new HashSet<Integer>();
     		//int[] arr=new int[N];
     		//int [] arr1=new int[N];
     		//long[]arr=new long[N];
     		//arrInpInt(arr,N);
     		//arrInpLong(arr,N);
     		//int[] arr1=decSort(arr);
     		//printArr(arr1);
     		//System.out.println(arr[N]);
     		//String fin=strip()
     		//long row=(long) Math.sqrt(N);
     		//System.out.println(row);
     		int min=Integer.MAX_VALUE;
     		String fin="";
     		for(int i=0;i<63;i++)
     		{
     			int del=0;
     			int ind1=0;
     			fin=strings[i];
     			for(int j=0;j<str.length();j++)
     			{
     				if(ind1>=fin.length()) {del=del+str.length()-j;break;}
     				if(fin.charAt(ind1)==str.charAt(j))ind1++;
     				else del++;
     			}
     			int tot=fin.length()-ind1 +del;
     			//System.out.println(tot + "  "+fin);
     			min=Math.min(tot, min);
     			
     			//min=Math.min(min, func(str,strings[i]));
     		}
     		
     	 System.out.println(min);
     	 //System.out.println(fin);
  //System.out.println(arr[N]);
  //System.out.println(possible(p,arr,k-1,circum));
     		
     		}
     		
     	
     		}
  
  	}
  
  