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: //package Codeforces.GR16;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.util.Arrays;
  import java.util.StringTokenizer;
  
  public class B {
  
      static final long mod = (long) 1e9 + 7l;
  
      private static void solve(int t) {
          char chr[] = fs.next().toCharArray();
          boolean z = false;
          boolean o = false;
          int numZ = 0;
          if (chr[0] == '0') numZ++;
          for (int i = 0; i < chr.length; i++) {
              if (i > 0 && chr[i] == '0' && chr[i - 1] != '0') {
                  numZ++;
              }
              if (chr[i] == '0') z = true;
              if (chr[i] == '1') o = true;
          }
          if (numZ == 1) {//0000111 // 11110011111
              System.out.println(1);
              return;
          }
          if (!z) {
              //1111
              System.out.println(0);
              return;
          } else if (!o) {
              //0000  ==1
              System.out.println(1);
              return;
          }
          //000111000101010
          System.out.println(2);
  
      }
  
      static class pair implements Comparable<pair> {
          public int a;
          public int[] players;
  
          public pair(int a, int[] b) {
              this.a = a;
              this.players = b;
          }
  
          @Override
          public int compareTo(pair o) {
              int[] p1 = this.players;
              int[] p2 = o.players;
              int p1Sum = 0;
              int p2Sum = 0;
              for (int i = 0; i < 5; i++) {
                  if (p1[i] > p2[i]) p1Sum++;
                  else p2Sum++;
              }
              if (p1Sum == p2Sum) return 0;
              if (p1Sum > p2Sum) return 1;
              else return -1;
  //            if (p1[0] == p2[0]) {
  //                if (p1[1] == p2[1]) {
  //                    if (p1[2] == p2[2]) {
  //                        if (p1[3] == p2[3]) {
  //                            if (p1[4] == p2[0]) {
  //                                return 0;
  //                            } else if (p1[0] < p2[0]) return 1;
  //                            return -1;
  //                        } else if (p1[3] < p2[3]) return 1;
  //                        return -1;
  //                    } else if (p1[2] < p2[2]) return 1;
  //                    return -1;
  //                } else if (p1[1] < p2[1]) return 1;
  //                return -1;
  //            } else if (p1[0] < p2[0]) return 1;
  //            return -1;
          }
      }
  
      public static void main(String[] args) {
          fs = new FastScanner();
          out = new PrintWriter(System.out);
          long s = System.currentTimeMillis();
          int t = fs.nextInt();
          for (int i = 1; i <= t; i++) solve(t);
          out.close();
  //        System.err.println( System.currentTimeMillis() - s + "ms" );
      }
  
      static boolean DEBUG = true;
      static PrintWriter out;
      static FastScanner fs;
  
      static void trace(Object... o) {
          if (!DEBUG) return;
          System.err.println(Arrays.deepToString(o));
      }
  
      static void pl(Object o) {
          out.println(o);
      }
  
      static void p(Object o) {
          out.print(o);
      }
  
      static long gcd(long a, long b) {
          return (b == 0) ? a : gcd(b, a % b);
      }
  
      static int gcd(int a, int b) {
          return (b == 0) ? a : gcd(b, a % b);
      }
  
      static void sieveOfEratosthenes(int n, int factors[]) {
          factors[1] = 1;
          for (int p = 2; p * p <= n; p++) {
              if (factors[p] == 0) {
                  factors[p] = p;
                  for (int i = p * p; i <= n; i += p)
                      factors[i] = p;
              }
          }
      }
  
      static long mul(long a, long b) {
          return a * b % mod;
      }
  
      static long fact(int x) {
          long ans = 1;
          for (int i = 2; i <= x; i++) ans = mul(ans, i);
          return ans;
      }
  
      static long fastPow(long base, long exp) {
          if (exp == 0) return 1;
          long half = fastPow(base, exp / 2);
          if (exp % 2 == 0) return mul(half, half);
          return mul(half, mul(half, base));
      }
  
      static long modInv(long x) {
          return fastPow(x, mod - 2);
      }
  
      static long nCk(int n, int k) {
          return mul(fact(n), mul(modInv(fact(k)), modInv(fact(n - k))));
      }
  
      static class FastScanner {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          StringTokenizer st = new StringTokenizer("");
  
          public String next() {
              while (!st.hasMoreElements())
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          int[] readArray(int n) {
              int[] a = new int[n];
              for (int i = 0; i < n; i++)
                  a[i] = nextInt();
              return a;
          }
  
          long nextLong() {
              return Long.parseLong(next());
          }
      }
  }
  