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>
const int MAX_N = 200;
const int MOD = 10007;
char str[MAX_N + 10];
int n, len;
struct Matrix {
  int h, w;
  short mat[MAX_N * 2 + 10][MAX_N * 2 + 10];
};
Matrix operator*(const Matrix& a, const Matrix& b) {
  Matrix ans;
  ans.h = a.h;
  ans.w = b.w;
  memset(ans.mat, 0, sizeof(ans.mat));
  for (int k = 0; k < a.w; k++)
    for (int i = k; i < ans.h; i++)
      for (int j = 0; j <= k; j++) {
        (ans.mat[i][j]) += ((int)a.mat[i][k] * b.mat[k][j] % MOD);
        if ((ans.mat[i][j]) >= MOD) (ans.mat[i][j]) -= MOD;
      }
  return ans;
}
Matrix gen(int n) {
  Matrix ans;
  memset(ans.mat, 0, sizeof(ans.mat));
  ans.h = ans.w = n;
  for (int i = 0; i < n; i++) ans.mat[i][i] = 1;
  return ans;
}
Matrix fastPow(Matrix b, int p) {
  Matrix ans = gen(b.h);
  while (p) {
    if (p & 1) ans = ans * b;
    b = b * b;
    p >>= 1;
  }
  return ans;
}
int f[MAX_N + 10][MAX_N + 10][MAX_N + 10];
int g[MAX_N + 10];
Matrix cg, cg1, cg2;
int main() {
  scanf("%s%d", str + 1, &n);
  len = strlen(str + 1);
  n += len;
  f[1][len][0] = 1;
  int bound = len / 2 + 1;
  for (int gap = len; gap >= 1; gap--) {
    for (int l = 1; l + gap - 1 <= len; l++) {
      int r = l + gap - 1;
      for (int i = 0; i <= len; i++) {
        if (f[l][r][i] == 0) continue;
        if (str[l] == str[r]) {
          if (gap <= 2) {
            (g[i]) += (f[l][r][i]);
            if ((g[i]) >= MOD) (g[i]) -= MOD;
          } else {
            (f[l + 1][r - 1][i]) += (f[l][r][i]);
            if ((f[l + 1][r - 1][i]) >= MOD) (f[l + 1][r - 1][i]) -= MOD;
          }
        } else {
          {
            (f[l + 1][r][i + 1]) += (f[l][r][i]);
            if ((f[l + 1][r][i + 1]) >= MOD) (f[l + 1][r][i + 1]) -= MOD;
          }
          {
            (f[l][r - 1][i + 1]) += (f[l][r][i]);
            if ((f[l][r - 1][i + 1]) >= MOD) (f[l][r - 1][i + 1]) -= MOD;
          }
        }
      }
    }
  }
  cg.h = cg.w = len + bound + bound + 1;
  for (int i = 0; i < len; i++) {
    cg.mat[i + 1][i] = 1;
    cg.mat[i][i] = 24;
    if (i == len - 1) {
      cg.mat[len + bound][i] = 1;
      cg.mat[len + bound][len + bound] = 26;
    }
  }
  for (int i = 0; i < bound; i++) {
    if (i < bound - 1) cg.mat[len + i + 1][len + i] = 1;
    cg.mat[len + i][len + i] = 25;
    cg.mat[i + len + bound + 1][i + len] = 1;
    cg.mat[i + len + bound + 1][i + len + bound + 1] = 26;
  }
  cg1 = fastPow(cg, (n >> 1) + (n & 1) - 1);
  cg2 = cg * cg1;
  int ans = 0;
  for (int i = 0; i <= len; i++) {
    int b = ((len - i) >> 1) + ((len - i) & 1);
    {
      (ans) += (cg2.mat[len + bound + b][len - i] * g[i] % MOD);
      if ((ans) >= MOD) (ans) -= MOD;
    }
    if ((n & 1) && !((len - i) & 1)) {
      ans -= cg1.mat[len + b - 1][len - i] * g[i] % MOD;
      if (ans < 0) ans += MOD;
    }
  }
  printf("%d\n", ans);
  return 0;
}