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;
inline int read() {
  int x = 0, fl = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') fl = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return fl == 1 ? x : -x;
}
const int N = 304, mod = 10007;
inline int fix(int x) { return x + ((x >> 31) & mod); }
inline int add(int x, int y) { return fix(x + y - mod); }
inline int dec(int x, int y) { return fix(x - y); }
inline int mul(int x, int y) { return (long long)x * y % mod; }
inline void ADD(int &x, int y) { x = fix(x + y - mod); }
inline void DEC(int &x, int y) { x = fix(x - y); }
inline void MUL(int &x, int y) { x = (long long)x * y % mod; }
int n, m, k, ans[N], Ans[N], h[N][N][N];
char s[N];
struct matrix {
  int a[N][N];
  inline matrix operator*(const matrix &x) const {
    static matrix ret;
    for (int i = 1; i <= k; i++)
      for (int j = i; j <= k; j++) {
        ret.a[i][j] = 0;
        for (int o = i; o <= j; o++) ADD(ret.a[i][j], mul(a[i][o], x.a[o][j]));
      }
    return ret;
  }
} A, AA;
inline void mul() {
  static int tmp[N];
  for (int i = 1; i <= k; i++) {
    tmp[i] = 0;
    for (int j = 1; j <= k; j++) ADD(tmp[i], mul(ans[j], A.a[j][i]));
  }
  memcpy(ans, tmp, sizeof(tmp));
}
inline void ksm(int r) {
  for (int i = 0; (1ll << i) <= r; i++) {
    if ((r >> i) & 1) mul();
    A = A * A;
  }
}
inline int H(int i, int l, int r) {
  if (i < 0) return 0;
  if (h[i][l][r] != -1) return h[i][l][r];
  if (l == 1 && r == m) return h[i][l][r] = !i;
  int ret = 0;
  if (l != 1 && s[l - 1] != s[r]) ADD(ret, H(i - 1, l - 1, r));
  if (r != m && s[l] != s[r + 1]) ADD(ret, H(i - 1, l, r + 1));
  if (l != 1 && r != m && s[l - 1] == s[r + 1]) ADD(ret, H(i, l - 1, r + 1));
  return h[i][l][r] = ret;
}
int main() {
  scanf("%s", s + 1);
  m = strlen(s + 1);
  n = read();
  k = m + ((m + 1) >> 1);
  memset(h, -1, sizeof(h));
  for (int i = 0, c; i < m; i++) {
    c = 0;
    for (int j = 1; j <= m; j++) {
      ADD(c, H(i, j, j));
      if (j != m && s[j] == s[j + 1]) c += H(i, j, j + 1);
    }
    if (i) {
      A.a[i][k - ((m - i + 1) >> 1)] = c;
      A.a[i][i] = 24;
      if (i != 1)
        A.a[i - 1][i] = 1;
      else
        ans[i] = 1;
    } else {
      ans[m] = c;
      A.a[k][k] = 26;
      for (int j = m; j < k; j++) {
        A.a[j][j + 1] = 1;
        A.a[j][j] = 25;
      }
    }
  }
  if ((n + m) & 1) {
    memcpy(Ans, ans, sizeof(ans));
    AA = A;
  }
  ksm((n + m + 1) >> 1);
  if (!(n + m) & 1) {
    cout << ans[k];
    return 0;
  }
  int res = ans[k];
  memcpy(ans, Ans, sizeof(Ans));
  A = AA;
  for (int i = 0, c; i < m; i++) {
    c = 0;
    for (int j = 1; j <= m; j++)
      if (j != m && s[j] == s[j + 1]) ADD(c, H(i, j, j + 1));
    if (i)
      A.a[i][k - ((m - i + 1) >> 1)] = c;
    else {
      ans[m] = c;
      A.a[k][k] = 0;
    }
  }
  ksm((n + m + 1) >> 1);
  cout << dec(res, ans[k]);
  return (0 - 0);
}