#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
void solve() {
  int tc;
  cin >> tc;
  while (tc--) {
    string s;
    cin >> s;
    int n = s.size();
    bool one = true;
    bool zero = true;
    map<char, int> mp;
    for (int i = 0; i < n; i++) {
      if (s[i] == '1') one = false;
      if (s[i] == '0') zero = false;
      mp[s[i]]++;
    }
    if (one) {
      cout << 1 << "\n";
    } else if (zero) {
      cout << 0 << "\n";
    } else {
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
          cnt++;
          while (s[i + 1] == '0') i++;
        }
      }
      if (cnt == 1)
        cout << 1 << "\n";
      else
        cout << 2 << "\n";
    }
  }
}
int main() {
  auto starttime = high_resolution_clock::now();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  auto endtime = high_resolution_clock::now();
  double duration = duration_cast<microseconds>(endtime - starttime).count();
  duration /= 1000000;
  cerr << "Time Taken : " << fixed << setprecision(6) << duration << " secs"
       << '\n';
  return 0;
}
