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 N = 410, mod = 10007;
char s[N];
int a[N][N], n, m, b[N][N];
void mult(int a[][N], int b[][N]) {
  static int c[N][N];
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= m; j++) c[i][j] = 0;
  for (int i = 0; i <= m; i++) {
    for (int k = 0; k <= m; k++) {
      for (int j = 0; j <= m; j++) c[i][j] += a[i][k] * b[k][j];
      if (k % 20 == 0)
        for (int j = 0; j <= m; j++) c[i][j] %= mod;
    }
  }
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= m; j++) a[i][j] = c[i][j] % mod;
}
int w[N][N];
void pw(int a[][N], int b) {
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= m; j++) w[i][j] = (i == j);
  for (; b; b >>= 1, mult(a, a))
    if (b & 1) mult(w, a);
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  static char t[N];
  memcpy(t + 1, s + 1, n * sizeof(s[0]));
  reverse(t + 1, t + n + 1);
  s[n + 1] = t[n + 1] = '#';
  int L, len;
  scanf("%d", &L);
  len = L + n;
  L = (len + 1) / 2 + 1;
  int S = 0, T = n + 1;
  m = T;
  static short f[N][N][N];
  f[0][0][0] = 1;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= i; j++)
      for (int k = 0; k <= i; k++)
        if (f[i][j][k] && j + k < n) {
          if (s[j + 1] == t[k + 1]) {
            (f[i + 1][j + 1][k + 1] += f[i][j][k]) %= mod;
            if (j + k + 2 == n) {
              int n25 = n - (i + 1), n24 = n - 2 * n25;
              if (len & 1) (b[n24][T + n25] += f[i][j][k]) %= mod;
            }
          } else
            (f[i + 1][j + 1][k] += f[i][j][k]) %= mod,
                (f[i + 1][j][k + 1] += f[i][j][k]) %= mod;
        }
  a[S][1] = b[S][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++)
      if (f[i][j][n - j]) {
        int k = n - j, n25 = (j + k) - i, n24 = (j + k) - 2 * n25;
        (a[n24][T + n25] += f[i][j][k]) %= mod;
        m = max(m, T + n25);
      }
    for (int j = 0; j <= i; j++)
      if (f[i][j][n + 1 - j]) {
        int k = n + 1 - j, n25 = (j + k) - i, n24 = (j + k) - 2 * n25;
        (a[n24][T + n25] += f[i][j][k]) %= mod;
        m = max(m, T + n25);
      }
  }
  for (int i = 1; i <= n; i++)
    a[i - 1][i] = b[i - 1][i] = 1, a[i][i] = b[i][i] = 24;
  for (int i = T; i <= m - 1; i++)
    a[i + 1][i] = b[i + 1][i] = 1, a[i + 1][i + 1] = b[i + 1][i + 1] = 25;
  a[T][T] = 26;
  pw(a, L);
  int ans = w[S][T];
  if (len & 1) {
    pw(b, L);
    ans = (ans - w[S][T]) % mod;
  }
  if (ans < 0) ans += mod;
  printf("%d\n", ans);
  return 0;
}