https://codeforces.com/contest/1948/submission/251648373
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
string s,s2;
int ans;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t,tou,n,len;
cin>>t;
while(t--)
{
cin>>s;
s=' '+s;
ans=0;
n=s.size()-1;
if(n%2==0)
len=n;
else
len=n-1;
for(;len>1;len-=2)
{
for(int l=1,r=l+len-1;r<=n;l++,r++)
{
for(int j=l;j<l+len/2;j++)
if(s[j]!=s[j+len/2]&&s[j]!='?'&&s[j+len/2]!='?')
goto l;
ans=len;
goto ll;
l:;
}
}
ll:;
cout<<ans<<"\n";
}
}