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;
struct matrixType {
  int r, c;
  int matrix[310][310];
};
int n, m;
int rc;
char str[205];
int dp[205][205][205];
int roads[205];
matrixType e, qhy;
matrixType c, tmp;
matrixType operator*(matrixType a, matrixType b) {
  int i, j, k;
  c.r = a.r;
  c.c = b.c;
  for (i = 0; i < c.r; i++)
    for (j = i; j < c.c; j++) {
      c.matrix[i][j] = 0;
      for (k = i; k <= j; k++) {
        c.matrix[i][j] += a.matrix[i][k] * b.matrix[k][j];
        if (c.matrix[i][j] > 10007) c.matrix[i][j] %= 10007;
      }
    }
  return c;
}
void standing_by() {
  scanf("%s", str + 1);
  scanf("%d", &n);
  m = strlen(str + 1);
}
void qpow(int y) {
  for (; y; y >>= 1, e = e * e)
    if (y & 1) qhy = qhy * e;
}
void complete() {
  int i, j, k;
  int l, r;
  int ans;
  dp[1][m][0] = 1;
  for (i = 0; i < m; i++)
    for (j = m; j >= 1; j--)
      for (l = 1; l + j - 1 <= m; l++) {
        r = l + j - 1;
        if (str[l] == str[r]) {
          if (j <= 2) {
            roads[i] = (roads[i] + dp[l][r][i]) % 10007;
          } else {
            dp[l + 1][r - 1][i] = (dp[l + 1][r - 1][i] + dp[l][r][i]) % 10007;
          }
        } else {
          dp[l + 1][r][i + 1] = (dp[l + 1][r][i + 1] + dp[l][r][i]) % 10007;
          dp[l][r - 1][i + 1] = (dp[l][r - 1][i + 1] + dp[l][r][i]) % 10007;
        }
      }
  rc = e.r = e.c = m + (m + 1) / 2 + 1;
  for (i = 0; i < m; i++) {
    e.matrix[i][i] = 24;
    if (i < m - 1) e.matrix[i][i + 1] = 1;
    e.matrix[i][rc - (m - i + 1) / 2 - 1] = roads[i];
  }
  e.matrix[0][0] = 0;
  for (i = m; i < rc - 1; i++) {
    e.matrix[i][i] = 25;
    e.matrix[i][i + 1] = 1;
  }
  e.matrix[rc - 1][rc - 1] = 26;
  qhy.r = 1;
  qhy.c = rc;
  qhy.matrix[0][0] = 1;
  if ((n + m) & 1) {
    tmp = e;
    qpow(((n + m + 1) >> 1) + 1);
    ans = qhy.matrix[0][rc - 1];
    e = tmp;
    for (i = 0; i <= m; i++) roads[i] = 0;
    for (i = 1; i < m; i++)
      if (str[i] == str[i + 1])
        for (j = 0; j < m; j++) {
          roads[j] = (roads[j] + dp[i][i + 1][j]) % 10007;
        }
    for (i = 0; i < m; i++) e.matrix[i][rc - (m - i + 1) / 2 - 1] = roads[i];
    e.matrix[rc - 2][rc - 1] = 0;
    for (i = 1; i < rc; i++) qhy.matrix[0][i] = 0;
    qhy.matrix[0][0] = 1;
    qpow((n + m + 1) >> 1);
    ans -= qhy.matrix[0][rc - 2];
    if (ans < 0) ans += 10007;
  } else {
    qpow(((n + m) >> 1) + 1);
    ans = qhy.matrix[0][rc - 1];
  }
  printf("%d\n", ans);
}
int main() {
  standing_by();
  complete();
  return 0;
}