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: #include <bits/stdc++.h>
  using namespace std;
  bool prime[10000007];
  void SieveOfEratosthenes() {
    memset(prime, true, sizeof(prime));
    for (long long int p = 2; p * p <= 10000007; p++) {
      if (prime[p] == true) {
        for (long long int i = p * p; i <= 10000007; i += p) prime[i] = false;
      }
    }
  }
  const long long int N = 300500;
  long long int fact[N];
  long long int invFact[N];
  long long int fast_pow(long long int a, long long int p, long long int m) {
    long long int res = 1;
    while (p) {
      if (p % 2 == 0) {
        a = (a * a) % m;
        p /= 2;
      } else {
        res = (res * a) % m;
        p--;
      }
    }
    return res;
  }
  void Call_For_nCr() {
    fact[0] = invFact[0] = 1;
    for (long long int i = 1; i < N; i++) {
      fact[i] = (fact[i - 1] * i) % 1000000007;
      invFact[i] = fast_pow(fact[i], 1000000007 - 2, 1000000007);
    }
  }
  long long int nCR(long long int n, long long int k, long long int m) {
    if (k > n) {
      return 0;
    }
    return fact[n] * invFact[k] % m * invFact[n - k] % m;
  }
  long long int sumOfDigit(long long int n, long long int b) {
    long long int unitDigit, sum = 0;
    while (n > 0) {
      unitDigit = n % b;
      sum += unitDigit;
      n = n / b;
    }
    return sum;
  }
  long long int factorial(long long int n) {
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
  }
  bool compare(pair<long long int, long long int> a,
               pair<long long int, long long int> b) {
    if (a.first < b.first) return 1;
    if (b.first < a.first) return 0;
    if (a.second > b.second) return 1;
    return 0;
  }
  void solve() {
    string s;
    cin >> s;
    long long int ans = 0, one = 0, ok = 0, zero = 0;
    for (long long int i = 0; i < s.length(); i++) {
      if (s[i] == '0') {
        zero = 1;
        ok = 1;
        if (one && zero) ans = 1;
      }
      if (s[i] == '1') {
        if (zero) one = 1;
      }
    }
    if (!ok) {
      cout << 0 << "\n";
      return;
    }
    if (ans)
      cout << 2 << "\n";
    else
      cout << 1 << "\n";
  }
  void init_code() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  }
  signed main() {
    init_code();
    long long int t = 1;
    cin >> t;
    long long int i = 1;
    while (t--) {
      solve();
      i++;
    }
    return 0;
  }
  