Problem: Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly n lowercase English letters into s to make it a palindrome. (A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.) You can choose any n lowercase English letters, and insert each of them to any position of s, possibly to the beginning or the end of s. You have to insert exactly n letters even if it is possible to turn s into a palindrome by inserting less than n letters.

Find the number of the palindromes that can be obtained in this way, modulo 10007.

Input

The first line contains a string s (1 ≤ |s| ≤ 200). Each character in s is a lowercase English letter.

The second line contains an integer n (1 ≤ n ≤ 109).

Output

Print the number of the palindromes that can be obtained, modulo 10007.

Examples

Input

revive
1


Output

1


Input

add
2


Output

28

Note

For the first sample, you can obtain the palindrome "reviver" by inserting 'r' to the end of "revive".

For the second sample, the following 28 palindromes can be obtained: "adada", "adbda", ..., "adzda", "dadad" and "ddadd".

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int P = 10007;
const int N = 301;
struct Mat {
  int data[305][305];
  Mat() { memset(data, 0, sizeof(data)); }
  int* operator[](int x) { return data[x]; }
};
Mat operator+(Mat& x, Mat& y) {
  Mat z;
  for (int i = 0; i <= N; i++)
    for (int j = 0; j <= N; j++) z[i][j] = (x[i][j] + y[i][j]) % P;
  return z;
}
Mat operator*(Mat& x, Mat& y) {
  Mat z;
  for (int i = 0; i <= N; i++)
    for (int j = 0; j <= N; j++)
      for (int k = 0; k <= N; k++) {
        z[i][k] = (z[i][k] + x[i][j] * y[j][k]) % P;
      }
  return z;
}
Mat exp(Mat mul, int val) {
  Mat ans;
  ans[0][0] = 1;
  for (; val; val >>= 1) {
    if (val & 1) ans = ans * mul;
    mul = mul * mul;
  }
  return ans;
}
int n, val;
char s[205];
int dp[205][205][205];
void solve_1() {
  for (int i = 1; i <= n; i++) dp[i][i - 1][0] = 1;
  for (int i = 1; i <= n; i++) dp[i][i][0] = 1;
  for (int _ = 1; _ <= n; _++)
    for (int i = 1; i <= n - _; i++) {
      int j = i + _;
      if (s[i] == s[j])
        for (int k = 0; k <= n; k++) dp[i][j][k] = dp[i + 1][j - 1][k];
      else
        for (int k = 1; k <= n; k++)
          dp[i][j][k] = (dp[i + 1][j][k - 1] + dp[i][j - 1][k - 1]) % P;
    }
  Mat mul;
  mul[N][N] = 26;
  for (int i = 1; i <= 200; i++) mul[i][i] = 24;
  for (int i = 0; i <= 199; i++) mul[i][i + 1] = 1;
  for (int i = 201; i <= 300; i++) mul[i][i] = 25;
  for (int i = 201; i <= 300; i++) mul[i][i + 1] = 1;
  for (int i = 0; i <= n; i++) {
    int j = (n - i + 1) >> 1;
    mul[i][N - j] = dp[1][n][i];
  }
  Mat ans = exp(mul, (val >> 1) + 1);
  int x = ans[0][N];
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) dp[i][i][0] = 1;
  for (int _ = 1; _ <= n; _++)
    for (int i = 1; i <= n - _; i++) {
      int j = i + _;
      if (s[i] == s[j])
        for (int k = 0; k <= n; k++) dp[i][j][k] = dp[i + 1][j - 1][k];
      else
        for (int k = 1; k <= n; k++)
          dp[i][j][k] = (dp[i + 1][j][k - 1] + dp[i][j - 1][k - 1]) % P;
    }
  mul = Mat();
  for (int i = 1; i <= 200; i++) mul[i][i] = 24;
  for (int i = 0; i <= 199; i++) mul[i][i + 1] = 1;
  for (int i = 201; i <= 300; i++) mul[i][i] = 25;
  for (int i = 201; i <= 300; i++) mul[i][i + 1] = 1;
  for (int i = 0; i <= n; i++) {
    int j = (n - i + 1) >> 1;
    mul[i][N - j] = dp[1][n][i];
  }
  Mat res = exp(mul, (val >> 1) + 2);
  int y = res[0][N];
  printf("%d\n", (26 * x + y) % P);
}
void solve_2() {
  for (int i = 1; i <= n; i++) dp[i][i - 1][0] = 1;
  for (int i = 1; i <= n; i++) dp[i][i][0] = 1;
  for (int _ = 1; _ <= n; _++)
    for (int i = 1; i <= n - _; i++) {
      int j = i + _;
      if (s[i] == s[j])
        for (int k = 0; k <= n; k++) dp[i][j][k] = dp[i + 1][j - 1][k];
      else
        for (int k = 1; k <= n; k++)
          dp[i][j][k] = (dp[i + 1][j][k - 1] + dp[i][j - 1][k - 1]) % P;
    }
  Mat mul;
  mul[N][N] = 26;
  for (int i = 1; i <= 200; i++) mul[i][i] = 24;
  for (int i = 0; i <= 199; i++) mul[i][i + 1] = 1;
  for (int i = 201; i <= 300; i++) mul[i][i] = 25;
  for (int i = 201; i <= 300; i++) mul[i][i + 1] = 1;
  for (int i = 0; i <= n; i++) {
    int j = (n - i + 1) >> 1;
    mul[i][N - j] = dp[1][n][i];
  }
  Mat ans = exp(mul, (val >> 1) + 1);
  printf("%d\n", ans[0][N]);
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  cin >> val;
  val += n;
  if (val & 1)
    solve_1();
  else
    solve_2();
  return 0;
}