36 lines
647 B
C++
36 lines
647 B
C++
#include<iostream>
|
|
#include<cstring>
|
|
#include<algorithm>
|
|
#include<cassert>
|
|
#include<string>
|
|
using namespace std;
|
|
typedef long long LL;
|
|
const int inf=0x3f3f3f3f;
|
|
const int maxn=200005;
|
|
char s[maxn];
|
|
int main()
|
|
{
|
|
#ifdef local
|
|
freopen("pro.in","r",stdin);
|
|
// freopen("pro.out","w",stdout);
|
|
#endif
|
|
int T,n; scanf("%d",&T);
|
|
while(T-->0)
|
|
{
|
|
scanf("%s",s); n=strlen(s);
|
|
int pos[4];
|
|
pos[1]=pos[2]=pos[3]=-1;
|
|
int res=inf;
|
|
for(int i=0;i<n;i++)
|
|
{
|
|
int loc=inf;
|
|
for(int j=1;j<=3;j++)
|
|
if(j!=s[i]-'0')
|
|
loc=min(loc,pos[j]);
|
|
pos[s[i]-'0']=i;
|
|
if(loc>=0) res=min(res,i-loc+1);
|
|
}
|
|
printf("%d\n",res==inf?0:res);
|
|
}
|
|
return 0;
|
|
} |