17609
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int canPalindrome(string word, int start, int end)
{
while (start < end)
{
if (word[start] == word[end])
{
start++;
end--;
}
else
{
return 2;
}
}
return 1;
}
int isPalindrome(string word)
{
int start = 0;
int end = word.length() - 1;
while (start < end)
{
if (word[start] == word[end])
{
start++;
end--;
}
else
{
int result1 = canPalindrome(word, start + 1, end);
int result2 = canPalindrome(word, start, end - 1);
if (result1 == 1 || result2 == 1)
{
return 1;
}
else
{
return 2;
}
}
}
return 0;
}
int main()
{
int n;
vector<string> words;
cin >> n;
for (int i = 0; i < n; i++)
{
string word;
cin >> word;
words.push_back(word);
}
for (int i = 0; i < words.size(); i++)
{
cout << isPalindrome(words[i]) << endl;
}
}