简单题。
#include <iostream>
#include <string>
using namespace std; int main() {
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
int l = 0;
int r = s.size() - 1;
while (l < r && s[l] == s[r]) {
l++;
r--;
}
if (l >= r) {
cout << -1 << endl;
continue;
}
int ll = l + 1;
int rr = r;
while (ll < rr && s[ll] == s[rr]) {
ll++;
rr--;
}
if (ll >= rr) {
cout << l << endl;
} else {
cout << r << endl;
}
}
return 0;
}