PS:自然溢出hash会被卡,cin,endl也会被卡!!!!!!!!!!!!!!!!!!!!!!!
#include <iostream>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
const int N=1e6+5,mod=1e9+7,P=131;
int n;
int h1[N],h2[N],p[N];
char str[N],s[N];
int init(){
int len=strlen(str+1);
for(int i=1,j=len;i<=len&&i<j;i++,j--){
if(str[i]==str[j]){
str[i]=str[j]='#';
}
else break;
}
int k=0;
for(int i=1;i<=len;i++){
if(str[i]=='#')continue;
s[++k]=str[i];
}
return k;
}
void make_hash(){
p[0]=1,h1[0]=0;
for(int i=1;i<=n;i++){
h1[i]=(h1[i-1]*P%mod+s[i])%mod;
p[i]=p[i-1]*P%mod;
}
h2[n+1]=0;
for(int i=n;i>=1;i--){
h2[i]=(h2[i+1]*P%mod+s[i])%mod;
}
}
int get1(int l,int r){
return (h1[r]%mod-h1[l-1]%mod*p[r-l+1]%mod+mod)%mod;
}
int get2(int l,int r){
return (h2[l]%mod-h2[r+1]%mod*p[r-l+1]%mod+mod)%mod;
}
bool judge(int l,int r){
int hash_l=(get1(1,n)-get1(l,r)*p[n-r]%mod+get2(l,r)*p[n-r]%mod+mod)%mod;
int hash_r=(get2(1,n)-get2(l,r)*p[l-1]%mod+get1(l,r)*p[l-1]%mod+mod)%mod;
//cout<<hash_l<<"~~~~~~"<<hash_r<<endl;
if(hash_l==hash_r)return true;
return false;
}
bool check(){
//cout<<"%%%%%"<<n<<endl;
for(int i=1;i<=n;i++){
if(judge(1,i))return true;
}
for(int i=n;i>=1;i--){
if(judge(i,n))return true;
}
return false;
}
main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%s",str+1);
//n=strlen(str+1);
n=init();
make_hash();
//debug();
if(check()||n==0)puts("Yes");
else puts("No");
}
}
#include <iostream>
#include <cstring>
#include <algorithm>
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N=1e6+5,mod=1e9+7,P=131;
int n;
int h1[N],h2[N],p[N];
char s[N];
void make_hash(){
p[0]=1,h1[0]=0;
for(int i=1;i<=n;i++){
h1[i]=(h1[i-1]*P%mod+s[i])%mod;
p[i]=p[i-1]*P%mod;
}
h2[n+1]=0;
for(int i=n;i>=1;i--){
h2[i]=(h2[i+1]*P%mod+s[i])%mod;
}
}
int get1(int l,int r){
return (h1[r]%mod-h1[l-1]%mod*p[r-l+1]%mod+mod)%mod;
}
int get2(int l,int r){
return (h2[l]%mod-h2[r+1]%mod*p[r-l+1]%mod+mod)%mod;
}
bool judge(int l,int r){
int hash_l=(get1(1,n)-get1(l,r)*p[n-r]%mod+get2(l,r)*p[n-r]%mod+mod)%mod;
int hash_r=(get2(1,n)-get2(l,r)*p[l-1]%mod+get1(l,r)*p[l-1]%mod+mod)%mod;
if(hash_l==hash_r)return true;
return false;
}
bool check(){
int pos=-1;
for(int i=1,j=n;i<=n;i++,j--){
if(s[i]==s[j])continue;
pos=i;
break;
}
for(int i=pos+1;i<=n-pos+1;i++)
if(judge(pos,i)||judge(i,n-pos+1))return true;
return false;
}
main(){
IOS;
int T;
cin>>T;
while(T--){
cin>>s+1;
n=strlen(s+1);
make_hash();
if(check())puts("Yes");
else puts("No");
}
}