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: //package codechef;
  import java.io.*;
  import java.util.*;
  
  
  
  public class cp_class {
  
  	static int mod=(int)1e9+7;
  	
  //	static  Reader sc=new Reader();
  	   static FastReader sc=new FastReader(System.in);
  	   
  //	static long[] arr=new long[1<<20];
  //	static long[] seg=new long[4*(1<<20)];
  //	
  //	static void buildSeg(int ind,int low,int high,int ok)
  //	{
  //		if(low==high)
  //		{
  //			seg[ind]=arr[low];
  //			return;
  //		}
  //		
  //		int mid=(low+high)/2;
  //		buildSeg(2*ind+1, low, mid, ok-1);
  //		buildSeg(2*ind+2, mid+1, high, ok-1);
  //		
  //		if(ok%2==1)
  //		{
  //			seg[ind]=seg[2*ind+1] | seg[2*ind+2];
  //		}
  //		else {
  //			seg[ind]=seg[2*ind+1] ^ seg[2*ind+2];
  //		}
  //	}
  //	
  //	static void update(int ind,int low,int high,int node,long val,int ok)
  //	{
  //		if(low==high)
  //		{
  //			seg[ind]=val;
  //			return;
  //		}
  //		
  //		int mid=(low+high)/2;
  //		if(node<=mid && node>=low)
  //			update(2*ind+1, low, mid, node, val, ok-1);
  //		else {
  //			update(2*ind+2, mid+1, high, node, val, ok-1);
  //		}
  //		
  //		if(ok%2==1)
  //		{
  //			seg[ind]=seg[2*ind+1] | seg[2*ind+2];
  //		}
  //		else {
  //			seg[ind]=seg[2*ind+1] ^ seg[2*ind+2];
  //		}
  //	}
  	
  	public static void main(String[] args) throws IOException {
  		// TODO Auto-generated method stub
  		//FastReader sc=new FastReader();
  			
  			int t=sc.nextInt();
  			while(t-->0)
  			{
  				long n=sc.nextLong();
  				int moves=10;
  				for(int i=0;i<63;i++)
  				{
  					moves=Math.min(moves, helper(new StringBuilder(Long.toString(n)), new StringBuilder(Long.toString(1L<<i))));
  				}
  				
  				out.println(moves);
  			}
  			
  			out.flush();
  			out.close();
  			System.gc();
  	
  	}
  	
  	
  	 /*
  	   ...SOLUTION ENDS HERE...........SOLUTION ENDS HERE...
  	 */
  	 
  	static void flag(boolean flag)
  	   {
  	       out.println(flag ? "YES" : "NO");
  	       out.flush();
  	   }
  	   
  	 /*                     
  	    Map<Long,Long> map=new HashMap<>();
  	             for(int i=0;i<n;i++)
  	               {
  	                  if(!map.containsKey(a[i]))
  	                   map.put(a[i],1);
  	                 else
  	                   map.replace(a[i],map.get(a[i])+1);
  	               }
  	     
  	    Set<Map.Entry<Long,Long>> hmap=map.entrySet();
  	             for(Map.Entry<Long,Long> data : hmap)
  	               {
  	          
  	               }
  	       
  	   Iterator<Integer> it = set.iterator();
  	          while(it.hasNext()) 
  	           { 
  	            int x=it.next();
  	           }
  	   */
  
  	static int helper(StringBuilder a,StringBuilder b)
  	{
  		if(a.length()==0)
  			return b.length();
  		if(b.length()==0)
  			return a.length();
  		
  		if(a.charAt(0)==b.charAt(0))
  		{
  			a.deleteCharAt(0);
  			b.deleteCharAt(0);
  			return helper(a, b);
  		}
  		else {
  			a.deleteCharAt(0);
  			return 1+helper(a, b);
  		}
  		
  		
  	}
  	
  	static void print(int a[])
  	  {
  	     int n=a.length;
  	     for(int i=0;i<n;i++)
  	       {
  	          out.print(a[i]+" ");
  	       }
  	     out.println();
  	     out.flush();
  	  }
  	static void print(long a[])
  	  {
  	     int n=a.length;
  	     for(int i=0;i<n;i++)
  	       {
  	          out.print(a[i]+" ");
  	       }
  	     out.println();
  	     out.flush();
  	  } 
  	static void print_int(ArrayList<Integer> al)
  	  {
  	     int si=al.size();
  	     for(int i=0;i<si;i++)
  	       {
  	          out.print(al.get(i)+" ");
  	       }
  	     out.println();
  	     out.flush();
  	  }
  	static void print_long(ArrayList<Long> al)
  	  {
  	     int si=al.size();
  	     for(int i=0;i<si;i++)
  	       {
  	          out.print(al.get(i)+" ");
  	       }
  	     out.println();
  	     out.flush();
  	  }
  	  
  	static int LowerBound(int a[], int x) 
  	 { // x is the target value or key
  	  int l=-1,r=a.length;
  	  while(l+1<r) {
  	    int m=(l+r)>>>1;
  	    if(a[m]>=x) r=m;
  	    else l=m;
  	  }
  	  return r;
  	}
  	
  	
  	static int lowerIndex(int arr[], int n, int x)
      {
          int l = 0, h = n - 1;
          while (l <= h)
          {
              int mid = (l + h) / 2;
              if (arr[mid] >= x)
                  h = mid - 1;
              else
                  l = mid + 1;
          }
          return l;
      }
       
  	
  	 static int UpperBound(int a[], int x)
  	  {// x is the key or target value
  	    int l=-1,r=a.length;
  	    while(l+1<r) {
  	       int m=(l+r)>>>1;
  	       if(a[m]<=x) l=m;
  	       else r=m;
  	    }
  	    return l+1;
  	 }
  	 static class DisjointUnionSets
  	 {
  	    int[] rank, parent;
  	    int n;
  	    // Constructor
  	    public DisjointUnionSets(int n)
  	    {
  	        rank = new int[n];
  	        parent = new int[n];
  	        this.n = n;
  	        makeSet();
  	    }
  	    // Creates n sets with single item in each
  	    void makeSet()
  	    {
  	        for (int i = 0; i < n; i++)
  	            parent[i] = i;
  	    }
  	    int find(int x)
  	    {
  	        if (parent[x] != x) {
  	            parent[x] = find(parent[x]);
  	        }
  	        return parent[x];
  	    }
  	    // Unites the set that includes x and the set
  	    // that includes x
  	    void union(int x, int y)
  	    {
  	        int xRoot = find(x), yRoot = find(y);
  	        if (xRoot == yRoot)
  	            return;
  	        if (rank[xRoot] < rank[yRoot])
  	            parent[xRoot] = yRoot;
  	        else if (rank[yRoot] < rank[xRoot])
  	         parent[yRoot] = xRoot;
  	        else // if ranks are the same
  	        {
  	         parent[yRoot] = xRoot;
  	            rank[xRoot] = rank[xRoot] + 1;
  	        }
  	    }
  	 }
  
  	 
  //	static class countClass{
  //		int cnt;
  //		public countClass() {
  //			this.cnt=0;
  //			// TODO Auto-generated constructor stub
  //		}
  //	}
  
  	 
  	 
  	static class Graph
  	  {
  	        int v;
  	        ArrayList<Integer> list[];
  	        Graph(int v)
  	        {
  	            this.v=v;
  	            list=new ArrayList[v+1];
  	            for(int i=1;i<=v;i++)
  	                list[i]=new ArrayList<Integer>();
  	        }
  	        void addEdge(int a, int b)
  	        {
  	            this.list[a].add(b);
  	        }
  	    }
  	
  	static class GraphMap{
  		Map<String,ArrayList<String>> graph;
  		GraphMap() {
  			// TODO Auto-generated constructor stub
  			graph=new HashMap<String,ArrayList<String>>();
  			
  		}
  		void addEdge(String a,String b)
  		{
  			if(graph.containsKey(a))
  			this.graph.get(a).add(b);
  			else {
  				this.graph.put(a, new ArrayList<>());
  				this.graph.get(a).add(b);
  			}
  		}
  	}
  	static void dfsMap(GraphMap g,HashSet<String> vis,String src,int ok)
  	{
  		vis.add(src);
  		
  		if(g.graph.get(src)!=null)
  		{
  			for(String each:g.graph.get(src))
  			{
  				if(!vis.contains(each))
  				{
  					dfsMap(g, vis, each, ok+1);
  				}
  			}
  		}
  		
  		cnt=Math.max(cnt, ok);
  	}
  	static int cnt;
  	static void DFS(Graph g, boolean[] visited, int u,int ok)
  		{
  	        visited[u]=true;
  	       
  	        for(int i=0;i<g.list[u].size();i++)
  	        {
  	            int v=g.list[u].get(i);
  	            if(!visited[v])
  	            {
  	            	DFS(g, visited, v,ok+1);
  	            }
  	               
  	        }
  	        
  	        cnt=Math.max(cnt, ok);
  	        
  	  } 
  	
  	
  	  
  	 static class Pair
  	    {
  	       int x,y;
  	       Pair(int x,int y)
  	        {
  	           this.x=x;
  	           this.y=y;
  	        }
  	    }
  	   
  	static long sum_array(int a[])
  	 {
  	    int n=a.length;
  	    long sum=0;
  	    for(int i=0;i<n;i++)
  	     sum+=a[i];
  	    return sum;
  	 }
  	static long sum_array(long a[])
  	 {
  	    int n=a.length;
  	    long sum=0;
  	    for(int i=0;i<n;i++)
  	     sum+=a[i];
  	    return sum;
  	 }
  
  	 static void sort(int[] a) 
  	   {
  			ArrayList<Integer> l=new ArrayList<>();
  			for (int i:a) l.add(i);
  			Collections.sort(l);
  			for (int i=0; i<a.length; i++) a[i]=l.get(i);
  		}
  	static void sort(long[] a) 
  	   {
  			ArrayList<Long> l=new ArrayList<>();
  			for (long i:a) l.add(i);
  			Collections.sort(l);
  			for (int i=0; i<a.length; i++) a[i]=l.get(i);
  		}
  
  	static void reverse_array(int a[])
  	 {
  	    int n=a.length;
  	    int i,t; 
  	    for (i = 0; i < n / 2; i++) { 
  	            t = a[i]; 
  	            a[i] = a[n - i - 1]; 
  	            a[n - i - 1] = t; 
  	        } 
  	 }
  	static void reverse_array(long a[])
  	 {
  	    int n=a.length;
  	    int i; long t; 
  	    for (i = 0; i < n / 2; i++) { 
  	            t = a[i]; 
  	            a[i] = a[n - i - 1]; 
  	            a[n - i - 1] = t; 
  	        } 
  	 }
  	 static long modInverse(long a, long m)
  		    {
  		        long g = gcd(a, m);
  		       
  		          return   power(a, m - 2, m);
  		        
  		    }
  	static long power(long x, long y, long m)
  		    {
  		        if (y == 0)
  		            return 1;
  		        long p = power(x, y / 2, m) % m;
  		        p = (int)((p * (long)p) % m);
  		        if (y % 2 == 0)
  		            return p;
  		        else
  		            return (int)((x * (long)p) % m);
  		    }
  	static long gcd(long a, long b) 
  	    { 
  	        if (a == 0) 
  	            return b; 
  	          
  	        return gcd(b%a, a); 
  	    } 
  	static int gcd(int a, int b) 
  	    { 
  	        if (a == 0) 
  	            return b; 
  	          
  	        return gcd(b%a, a); 
  	    } 
  
  	   static class FastReader{
  	 
  	        byte[] buf = new byte[2048];
  	        int index, total;
  	        InputStream in;
  	 
  	        FastReader(InputStream is) {
  	            in = is;
  	        }
  	 
  	        int scan() throws IOException {
  	            if (index >= total) {
  	                index = 0;
  	                total = in.read(buf);
  	                if (total <= 0) {
  	                    return -1;
  	                }
  	            }
  	            return buf[index++];
  	        }
  	 
  	        String next() throws IOException {
  	            int c;
  	            for (c = scan(); c <= 32; c = scan());
  	            StringBuilder sb = new StringBuilder();
  	            for (; c > 32; c = scan()) {
  	                sb.append((char) c);
  	            }
  	            return sb.toString();
  	        }
  	 
  	        int nextInt() throws IOException {
  	            int c, val = 0;
  	            for (c = scan(); c <= 32; c = scan());
  	            boolean neg = c == '-';
  	            if (c == '-' || c == '+') {
  	                c = scan();
  	            }
  	            for (; c >= '0' && c <= '9'; c = scan()) {
  	                val = (val << 3) + (val << 1) + (c & 15);
  	            }
  	            return neg ? -val : val;
  	        }
  	 
  	        long nextLong() throws IOException {
  	            int c;
  	            long val = 0;
  	            for (c = scan(); c <= 32; c = scan());
  	            boolean neg = c == '-';
  	            if (c == '-' || c == '+') {
  	                c = scan();
  	            }
  	            for (; c >= '0' && c <= '9'; c = scan()) {
  	                val = (val << 3) + (val << 1) + (c & 15);
  	            }
  	            return neg ? -val : val;
  	        }
  	    }
  	   
  	    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') 
  	                    break; 
  	                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(); 
  	        } 
  	    }
  	  static  PrintWriter out=new PrintWriter(System.out);
  	  static int int_max=Integer.MAX_VALUE;
  	  static int int_min=Integer.MIN_VALUE;
  	  static long long_max=Long.MAX_VALUE;
  	  static long long_min=Long.MIN_VALUE;
  
  }
  
  
  