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 = 205;
const int M = 405;
const int MD = 10007;
int n, m;
int a[N];
int dp[N][N][N];
int cnt[N][2];
void fido() {
  dp[1][n][0] = 1;
  for (int siz = n - 1; siz >= 0; siz--)
    for (int i = 1, j; i <= n - siz + 1; i++)
      for (int k = 0; k <= n - siz; k++)
        if (dp[i][j = i + siz][k]) {
          if (a[i] == a[j])
            (dp[i + 1][j - 1][k + 1] += dp[i][j][k]) %= MD;
          else
            (dp[i + 1][j][k + 1] += dp[i][j][k]) %= MD,
                (dp[i][j - 1][k + 1] += dp[i][j][k]) %= MD;
        }
  for (int i = 0; i <= n; i++)
    for (int k = 0; k <= n; k++)
      (cnt[k][0] += dp[i + 1][i][k]) %= MD,
          (cnt[k][1] += dp[i + 2][i][k]) %= MD;
}
int og[M][M], sz, rp, bp;
int f[M][M], g[M][M];
long long tt[M][M];
void sqr() {
  for (int i = 1; i <= sz; i++)
    for (int j = i; j <= sz; j++) {
      tt[i][j] = 0;
      for (int k = i; k <= j; k++) tt[i][j] += f[i][k] * f[k][j];
    }
  for (int i = 1; i <= sz; i++)
    for (int j = 1; j <= sz; j++) f[i][j] = tt[i][j] % MD;
}
void sig() {
  for (int i = 1; i <= sz; i++)
    for (int j = i; j <= sz; j++) {
      tt[i][j] = 0;
      for (int k = i; k <= j; k++) tt[i][j] += f[i][k] * og[k][j];
    }
  for (int i = 1; i <= sz; i++)
    for (int j = 1; j <= sz; j++) f[i][j] = tt[i][j] % MD;
}
void mat(int m) {
  if (m == 1) {
    memcpy(f, og, sizeof f);
    return;
  }
  mat(m >> 1), sqr();
  if (m & 1) sig();
}
void sedo() {
  rp = n - 1, bp = (n + 1) / 2, sz = rp + bp + bp;
  for (int i = 1; i <= rp; i++) og[i][i] = 24;
  for (int i = rp + 1; i <= rp + bp; i++) og[i][i] = 25;
  for (int i = rp + bp + 1; i <= sz; i++) og[i][i] = 26;
  for (int i = 1; i < rp + bp; i++) og[i][i + 1] = 1;
  for (int i = rp + 1; i <= rp + bp; i++) og[i][i + bp] = 1;
}
void read(int *s) {
  int c;
  while (c = getchar(), c <= ' ')
    ;
  s[s[0] = 1] = c;
  while (c = getchar(), c > ' ') s[++s[0]] = c;
}
int main() {
  read(a), scanf("%d", &m), n = a[0], m += n;
  fido();
  sedo(), mat((m + 1) / 2);
  int ans(0);
  for (int i = 0, j; i < n; i++) {
    j = (n - i + 1) / 2;
    if (i + j + j == n)
      (ans += (f[n - i][n + j - 1 + bp] * cnt[n - j][0]) % MD) %= MD;
    else
      (ans += (f[n - i][n + j - 1 + bp] * cnt[n - j + 1][1]) % MD) %= MD;
  }
  if (m & 1) {
    mat((m - 1) / 2);
    for (int i = 0, j; i < n; i++) {
      j = (n - i + 1) / 2;
      if (i + j + j == n)
        (ans -= (f[n - i][n + j - 1] * cnt[n - j][0]) % MD) %= MD;
    }
  }
  printf("%d\n", (ans + MD) % MD);
  return 0;
}