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, N = 310;
int m, cnt, f[N], g[N], dp[N][N][N], n, p[N], q[N];
char s[N];
void upd(int& x, int y) { ((x += y) >= P) && (x -= P); }
struct Mat {
  int a[N][N];
  inline int* operator[](int x) { return a[x]; }
  Mat() { memset(a, 0, sizeof(a)); }
} A, B;
inline Mat operator*(Mat a, Mat b) {
  Mat c;
  for (int i = (1); i <= (cnt); ++i)
    for (int j = (i); j <= (cnt); ++j)
      for (int k = (i); k <= (j); ++k) (c[i][j] += a[i][k] * b[k][j]) %= P;
  return c;
}
inline void ksm(Mat a, int b, int x) {
  for (int i = (1); i <= (cnt); ++i) p[i] = 0;
  p[1] = 1;
  p[n + 1] = x;
  for (; b; b >>= 1, a = a * a)
    if (b & 1) {
      for (int i = (1); i <= (cnt); ++i)
        for (int j = (1); j <= (cnt); ++j) upd(q[j], p[i] * a[i][j] % P);
      for (int i = (1); i <= (cnt); ++i) p[i] = q[i], q[i] = 0;
    }
}
int main() {
  scanf("%s%d", s + 1, &m);
  n = strlen(s + 1);
  cnt = n + (n + 1) / 2 + 1;
  dp[1][n][0] = 1;
  for (int i = (1); i <= (n); ++i)
    for (int j = (n); j >= (i); --j)
      if (s[i] == s[j]) {
        if (i + 1 < j)
          for (int k = (0); k <= (i + n - j - 1); ++k)
            upd(dp[i + 1][j - 1][k], dp[i][j][k]);
        else
          for (int k = (0); k <= (i + n - j - 1); ++k) upd(f[k], dp[i][j][k]);
      } else
        for (int k = (0); k <= (i + n - j - 1); ++k)
          upd(dp[i][j - 1][k + 1], dp[i][j][k]),
              upd(dp[i + 1][j][k + 1], dp[i][j][k]);
  A[cnt][cnt] = 26;
  for (int i = (n + 1); i <= (cnt - 1); ++i) A[i][i + 1] = 1, A[i][i] = 25;
  for (int i = (1); i <= (n); ++i)
    A[i][i] = 24, A[i][cnt - (n - i + 1) / 2] = f[i], A[i][i + 1] = i != n;
  if ((n + m) & 1) {
    ksm(A, (n + m + 1) / 2, f[0]);
    int ans = p[cnt];
    for (int i = (1); i <= (n - 1); ++i)
      if (s[i] == s[i + 1])
        for (int k = (0); k <= (n - 1); ++k) upd(g[k], dp[i][i + 1][k]);
    for (int i = (n + 1); i <= (cnt - 1); ++i) B[i][i + 1] = 1, B[i][i] = 25;
    for (int i = (1); i <= (n); ++i)
      B[i][i] = 24, B[i][cnt - (n - i + 1) / 2] = g[i], B[i][i + 1] = i != n;
    ksm(B, (n + m + 1) / 2, g[0]);
    printf("%d\n", (ans - p[cnt] + P) % P);
  } else {
    ksm(A, (n + m) / 2, f[0]);
    printf("%d\n", p[cnt]);
  }
  return 0;
}