description: A binary string is a string that consists of characters 0 and 1.
  
  Let \operatorname{MEX} of a binary string be the smallest digit among 0, 1, or 2 that does not occur in the string. For example, \operatorname{MEX} of 001011 is 2, because 0 and 1 occur in the string at least once, \operatorname{MEX} of 1111 is 0, because 0 and 2 do not occur in the string and 0 < 2.
  
  A binary string s is given. You should cut it into any number of substrings such that each character is in exactly one substring. It is possible to cut the string into a single substring — the whole string.
  
  A string a is a substring of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
  
  What is the minimal sum of \operatorname{MEX} of all substrings pieces can be?
  
  Input
  
  The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases. Description of the test cases follows.
  
  Each test case contains a single binary string s (1 ≤ |s| ≤ 10^5).
  
  It's guaranteed that the sum of lengths of s over all test cases does not exceed 10^5.
  
  Output
  
  For each test case print a single integer — the minimal sum of \operatorname{MEX} of all substrings that it is possible to get by cutting s optimally.
  
  Example
  
  Input
  
  
  6
  01
  1111
  01100
  101
  0000
  01010
  
  
  Output
  
  
  1
  0
  2
  1
  1
  2
  
  Note
  
  In the first test case the minimal sum is \operatorname{MEX}(0) + \operatorname{MEX}(1) = 1 + 0 = 1.
  
  In the second test case the minimal sum is \operatorname{MEX}(1111) = 0.
  
  In the third test case the minimal sum is \operatorname{MEX}(01100) = 2.
solution: import java.util.*;
  import java.io.*;
  import java.lang.*;
  
  
  public class cf742 {
  //HashSet<Integer> hs=new HashSet<>();
  //PriorityQueue<Integer> pq=new PriorityQueue<>();
  //HashMap<Integer,Integer> hm=new HashMap<>();
  //ArrayList<Integer> lt=new ArrayList<>();
      static long mod=1000_000_007;
  
      //Must Do dry Run Before submitting soln. and think also about corner testcases will be passed or not.
      public static void solve1() throws Exception{
          InputStreamReader ip=new InputStreamReader(System.in);
          BufferedReader br = new BufferedReader(ip);
          int t = Integer.parseInt(br.readLine());
          StringBuilder asb=new StringBuilder();
  		
         while(t-->0){
          // int n =Integer.parseInt(br.readLine());
          // String[] strs=(br.readLine()).trim().split(" ");
          // int n=Integer.parseInt(strs[0]),k=Integer.parseInt(strs[1]),r=Integer.parseInt(strs[2]),s=Integer.parseInt(strs[3]);
           String str=(br.readLine()).trim();
          // int[] arr=new int[n];
          // for(int i=0;i<n;i++){arr[i]=Integer.parseInt(strs[i]);}
  
              int n=str.length();
              char prev='0';  int ct0=1;
              if(str.charAt(0)=='1'){ prev='1'; ct0=0; }
  
              
  
              for(int i=1;i<n;i++){
                  if(prev!=str.charAt(i)){
                      if(str.charAt(i)=='0'){ ct0++; }
                      prev=str.charAt(i);
                  }
              }
  
              if(ct0>2){ ct0=2; }   //  01010
  
              asb.append(ct0+"\n");
  
           }
  
           System.out.println(asb);
      }
  
     
  //******************************************************************************************************************** */
      public static void main(String[] args) throws Exception{
          solve1();
      
       }
  
       public static void solve2() throws Exception{
          InputStreamReader ip=new InputStreamReader(System.in);
          BufferedReader br = new BufferedReader(ip);
          int t = Integer.parseInt(br.readLine());
          StringBuilder asb=new StringBuilder();
  		
         while(t-->0){
          // int n =Integer.parseInt(br.readLine());
          // String[] strs=(br.readLine()).trim().split(" ");
          // int n=Integer.parseInt(strs[0]),k=Integer.parseInt(strs[1]),r=Integer.parseInt(strs[2]),s=Integer.parseInt(strs[3]);
          //  String str=(br.readLine()).trim();
          // int[] arr=new int[n];
          // for(int i=0;i<n;i++){arr[i]=Integer.parseInt(strs[i]);}
           }
      }
     
  //******************************************************************************************************************** */
  
      public static long modInverse1(long a, long m){
          // int g = gcd(a, m);
          // if(g!=1) {System.out.println("Inverse Doesnot Exist");}  
          return binexp(a, m - 2, m);
         }
     
      public  static long binexp(long a, long b, long m){
          if (b == 0)return 1; 
              
          long res = binexp(a, b / 2, m);
          if (b % 2 == 1) return (( (res*res)%m )*a) % m;
          else return (res*res)%m;
      }
  
      //binexp
      public static long binexp(long a,long b){
          if(b==0)return 1;
  
          long res=binexp(a, b/2);
  
          if(b%2==1){
              return (((res*res))*a);
          }else return (res*res);
      }
  
      //Comparator Interface
      public static class comp implements Comparator<int[]>{
          public int compare(int[] a,int[] b){
              return a[0]-b[0];
          }
      }
  
  	//gcd using Euclid's Division Algorithm  
      public static long gcd(long a,long b){   
          if(b==0)return a;
          else return gcd(b, a%b);
      }
  
  	//check prime in root(n)
      public static int isprime(int n){
          for(int i=2;i<=Math.sqrt(n);i++){
              if(n%i==0)return i;
          }
  
          return -1;   //means n is prime
      }
  
  	//SOE
  	static  int[] sieve;
  	public static void SOE(int n){
          sieve=new int[n+1];
  
          // System.out.println("All prime number from 1 to n:-");
          
          for(int x=2;x<=n;x++){
              if(sieve[x]!=0){  //Not prime number
                  continue;
              }
              // System.out.print(x+"  ");
              for(int u=2*x;u<=n;u+=x){
                  sieve[u]=x;
              }
          }
  
  		//If  sieve[i]=0 means 'i' is primr else 'i' is not prime 
      }
  
      //sort
       public static void sort(long[] arr) {
  		int n = arr.length;
  		for (int i = 0; i < n; i++) {
  			int idx = (int) Math.random() * n;
  			long temp = arr[i];  arr[i] = arr[idx];  arr[idx] = temp;  //swap
  		}
  		Arrays.sort(arr);
  	}
   
  	public static void sort(int[] arr) {
  		int n = arr.length;
  		for (int i = 0; i < n; i++) {
  			int idx = (int) Math.random() * n;
  			int temp = arr[i];  arr[i] = arr[idx]; arr[idx] = temp;  //swap
  		}
  		Arrays.sort(arr);
  	}
      //1d print
      public static void print(int[] dp) {
  		for (int val : dp) {
  			System.out.print(val + " ");
  		}
  		System.out.println();
  	}
   
  	public static void print(long[] dp) {//Method Overloading
  		for (long val : dp) {
  			System.out.print(val + " ");
  		}
  		System.out.println();
  	}  
      //2d print
  	public static void print(long[][] dp) {//Method Overloading
  		for (long[] a : dp) {
  			for (long val : a) {
  				System.out.print(val + " ");
  			}
  			System.out.println();
  		}
  	}
   
  	public static void print(int[][] dp) {
  		for (int[] a : dp) {
  			for (int val : a) {
  				System.out.print(val + " ");
  			}
  			System.out.println();
  		}
  	}
   
  	
  }
  