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 NN = 100 + 117;
const int MM = 100 + 117;
int read() {
  int fl = 1, x;
  char c;
  for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
    ;
  if (c == '-') {
    fl = -1;
    c = getchar();
  }
  for (x = 0; c >= '0' && c <= '9'; c = getchar())
    x = (x << 3) + (x << 1) + c - '0';
  return x * fl;
}
void open() { freopen("a.in", "r", stdin); }
void close() {
  fclose(stdin);
  fclose(stdout);
}
int m, n;
char s[NN] = {};
int dp[NN][NN][NN] = {};
int mat[2 * NN][2 * NN] = {};
int ans[2 * NN][2 * NN] = {};
const int mod = 10007;
void upd(int &a, int b) { a = (a + b) % mod; }
int tp[2 * NN][2 * NN] = {};
void unit(int a[2 * NN][2 * NN], int siz) {
  for (int i = 0; i <= siz; ++i) {
    for (int j = 0; j <= siz; ++j) {
      a[i][j] = (i == j);
    }
  }
}
int c[2 * NN][2 * NN] = {};
void mul(int a[2 * NN][2 * NN], int b[2 * NN][2 * NN], int siz) {
  for (int i = 0; i <= siz; ++i) {
    for (int j = 0; j <= siz; ++j) c[i][j] = b[j][i];
  }
  for (int i = 0; i <= siz; ++i) {
    for (int j = i; j <= siz; ++j) {
      long long x = 0;
      for (int k = i; k <= j; ++k) {
        x += a[i][k] * c[j][k];
      }
      tp[i][j] = x % mod;
    }
  }
  for (int i = 0; i <= siz; ++i)
    for (int j = 0; j <= siz; ++j) a[i][j] = tp[i][j];
}
void ksm(int siz, int n) {
  n += 1;
  unit(ans, siz);
  for (; n; n >>= 1, mul(mat, mat, siz)) {
    if (n & 1) mul(ans, mat, siz);
  }
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  m = read();
  dp[0][0][n + 1] = 1;
  for (int i = 0; i < n; ++i) {
    for (int l = 0; l <= n; ++l) {
      for (int r = n + 1; r > l + 1; --r) {
        int xtl = l + 1, xtr = r - 1;
        if (s[xtl] == s[xtr]) {
          upd(dp[i][xtl][xtr], dp[i][l][r]);
        } else {
          upd(dp[i + 1][l][xtr], dp[i][l][r]);
          upd(dp[i + 1][xtl][r], dp[i][l][r]);
        }
      }
    }
  }
  int all = n + (n + 1) / 2 + 1;
  for (int i = 1; i <= n; ++i) mat[i][i] = 24;
  for (int i = 0; i < n; ++i) mat[i][i + 1] = 1;
  for (int i = n + 1; i < all; ++i) mat[i][i] = 25;
  for (int i = n + 1; i < all; ++i) mat[i][i + 1] = 1;
  mat[all][all] = 26;
  for (int i = 0; i <= n; ++i) {
    int ot = (n - i + 1) / 2;
    int cnt = 0;
    for (int l = 0; l <= n; ++l) {
      upd(cnt, dp[i][l][l]);
      upd(cnt, dp[i][l][l + 1]);
    }
    mat[i][all - ot] = cnt;
  }
  ksm(all, (n + m + 1) / 2);
  int op = ans[0][all];
  if ((n + m) & 1) {
    memset(mat, 0, sizeof mat);
    for (int i = 1; i <= n; ++i) mat[i][i] = 24;
    for (int i = 0; i < n; ++i) mat[i][i + 1] = 1;
    for (int i = n + 1; i < all; ++i) mat[i][i] = 25;
    for (int i = n + 1; i < all; ++i) mat[i][i + 1] = 1;
    for (int i = 0; i <= n; ++i) {
      int ot = (n - i + 1) / 2;
      int cnt = 0;
      for (int l = 1; l < n; ++l) {
        if (s[l] == s[l + 1]) upd(cnt, dp[i][l - 1][l + 2]);
      }
      mat[i][all - ot] = cnt;
    }
    ksm(all, (n + m + 1) / 2);
    op = (mod + op - ans[0][all]) % mod;
  }
  printf("%d\n", op);
  close();
  return 0;
}