#include<iostream> #include<cstring> #include<vector> using namespace std; using LL = long long;
int main(){
cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
const int N = 2e5; vector<int> f(N + 1); for(int i = 1; i <= N; i++) f[i] = f[i / 2] + 1;
int T; cin >> T; while(T--){ vector<vector<int> > pos(26, {-1}); string s; cin >> s; for(int i = 0; i < s.size(); i++){ int c = s[i] - 'a'; pos[c].push_back(i); } int ans = s.size(); for(auto &v : pos){ v.push_back(s.size()); int res = 0; for(int i = 1; i < v.size(); i++){ int len = v[i] - v[i - 1] - 1; res = max(res, f[len]); } ans = min(ans, res); } cout << ans << '\n'; } }