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;
char str[333];
int n, dp[222][222][222], m, n24, n25, n26, ways, wy, ans, c[222][222],
    coef[4][422][222], now[422], rp[422];
const int mod = 10007;
int pos[mod], cnt, rev[mod], stirling[222][222], hs[mod], ct, fac[10007];
int power(int a, int n) {
  int res;
  if (n == 0) return 1;
  a %= mod;
  res = power(a, n / 2);
  res = res * res % mod;
  if (n % 2) res = res * a % mod;
  return res;
}
void init() {
  int i, j, s, p, q;
  for (i = 0; i <= m; i++)
    for (j = 0; j <= i; j++) {
      if (j == 0 || j == i)
        c[i][j] = 1;
      else
        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
    }
  for (i = 0; i < mod; i++) rev[i] = power(i, mod - 2);
  memset(stirling, 0, sizeof(stirling));
  stirling[0][0] = 1;
  for (i = 0; i < m; i++)
    for (j = 0; j <= i; j++) {
      if (stirling[i][j] == 0) continue;
      stirling[i + 1][j] += stirling[i][j] * (i + 1);
      stirling[i + 1][j] %= mod;
      stirling[i + 1][j + 1] = (stirling[i + 1][j + 1] + stirling[i][j]) % mod;
    }
  fac[0] = 1;
  for (i = 1; i < mod; i++) fac[i] = fac[i - 1] * i % mod;
}
int cal_coef(int n, int t) {
  int i, j, s, p, q;
  if (pos[n] >= 0) return pos[n];
  memset(coef[cnt], 0, sizeof(coef[cnt]));
  coef[cnt][0][m] = 1;
  for (i = 1; i <= t; i++) {
    for (j = i - 1; j >= 0; j--) {
      coef[cnt][i][j] = stirling[i - 1][j] * rev[fac[i - 1]] % mod;
      for (s = i - 1; s >= i - 1; s--) {
        coef[cnt][i][j] -= coef[cnt][s][j];
        if (j == 0) coef[cnt][i][m + j] -= coef[cnt][s][m + j];
      }
      coef[cnt][i][j] %= mod;
      if (j == 0) {
        coef[cnt][i][m + j] %= mod;
        coef[cnt][i][m + j] = coef[cnt][i][m + j] * rev[n - 1] % mod;
        if (coef[cnt][i][m + j] < 0) coef[cnt][i][m + j] += mod;
      }
      coef[cnt][i][j] = coef[cnt][i][j] * rev[n - 1] % mod;
      if (coef[cnt][i][j] < 0) coef[cnt][i][j] += mod;
    }
  }
  pos[n] = cnt++;
  return pos[n];
}
void clx(int n, int x, int t) {
  int i, j, s, p, q;
  x = x % ((mod - 1) * mod);
  memset(rp, 0, sizeof(rp));
  if (x == 0) {
    rp[0] = power(n, (x + 1) % (mod - 1) * (mod - 2));
    return;
  }
  for (i = 0; i <= t; i++) {
    rp[i] = power(x, i);
    if (i % 2 == 0) {
      rp[i] -= power(n, (x + 1) % (mod - 1) * (mod - 2));
      rp[i] = (rp[i] + mod) % mod;
    } else {
      rp[i] += power(n, (x + 1) % (mod - 1) * (mod - 2));
      rp[i] %= mod;
    }
    for (j = 0; j < i; j++) {
      if (rp[j] == 0) continue;
      if ((i - j) % 2 == 0)
        rp[i] += c[i][j] * rp[j] % mod;
      else
        rp[i] -= c[i][j] * rp[j] % mod;
      rp[i] = rp[i] % mod;
      if (rp[i] < 0) rp[i] += mod;
    }
    rp[i] = rp[i] * rev[n - 1] % mod;
  }
}
int cal(int x, int n24, int n25) {
  int i, j, s, k, p, q, res, tmp, id;
  q = 25 * power(26, mod - 2) % mod;
  id = cal_coef(q, m);
  memset(now, 0, sizeof(now));
  for (i = n25 - 1; i >= 0; i--) {
    for (j = n25 - 1 - i; j >= 0; j--) {
      now[j] = x % mod * now[j] % mod;
      if (j) now[j] = (now[j] - now[j - 1] + mod) % mod;
    }
    now[0] = (now[0] + coef[id][n25][i]) % mod;
  }
  now[m] = coef[id][n25][m];
  for (i = n25 + n24; i >= 0; i--) {
    for (j = 0; j <= min(i, n24 - 1); j++) {
      if (j == 0) {
        now[i] = now[i - j] * stirling[n24 - 1][j] % mod;
        now[m + i] = now[m + i - j] * stirling[n24 - 1][j] % mod;
      } else {
        now[i] += now[i - j] * stirling[n24 - 1][j] % mod;
        now[m + i] += now[m + i - j] * stirling[n24 - 1][j] % mod;
      }
    }
    now[i] %= mod;
    now[m + i] %= mod;
    if (n24) {
      now[i] = now[i] * rev[fac[n24 - 1]] % mod;
      now[m + i] = now[m + i] * rev[fac[n24 - 1]] % mod;
    }
  }
  if (n24 == 0) {
    res = now[0] * power(q, x + 1) % mod;
    res = (res + now[m]) % mod;
    res = res * power(26, x) % mod;
    return res;
  }
  res = power(12, x + 1) * power(13, (x + 1) % (mod - 1) * (mod - 2)) % mod;
  q = 24 * power(25, (mod - 2)) % mod;
  clx(q, x, m);
  tmp = 0;
  int mx = n24 + n25 - 1;
  for (i = 0; i <= mx; i++) tmp += now[i] * rp[i] % mod;
  tmp %= mod;
  res = res * tmp % mod;
  q = 12 * power(13, mod - 2) % mod;
  clx(q, x, n24 + n25);
  tmp = 0;
  for (i = 0; i <= mx; i++) tmp += now[m + i] * rp[i] % mod;
  tmp %= mod;
  tmp = tmp * power(12, x + 1) % mod;
  tmp = tmp * power(13, (x + 1) % (mod - 1) * (mod - 2)) % mod;
  res = (res + tmp) % mod;
  res = res * power(26, x) % mod;
  return res;
}
int main() {
  int i, j, s, p, q, x, tmp, tx, ws;
  scanf("%s%d", str, &n);
  m = strlen(str);
  memset(dp, 0, sizeof(dp));
  dp[0][m + 1][0] = 1;
  for (n24 = 0; n24 <= m; n24++)
    for (i = 0; i < m; i++)
      for (j = m + 1; j >= i; j--) {
        if (dp[i][j][n24] == 0) continue;
        if (j - 1 >= i + 1 && str[i] == str[j - 2])
          dp[i + 1][j - 1][n24] = (dp[i + 1][j - 1][n24] + dp[i][j][n24]) % mod;
        else if (i + 1 < j) {
          dp[i][j - 1][n24 + 1] = (dp[i][j - 1][n24 + 1] + dp[i][j][n24]) % mod;
          dp[i + 1][j][n24 + 1] = (dp[i + 1][j][n24 + 1] + dp[i][j][n24]) % mod;
        }
      }
  init();
  ans = 0;
  cnt = ct = 0;
  memset(pos, -1, sizeof(pos));
  memset(hs, 0, sizeof(hs));
  for (n24 = 0; n24 <= m; n24++) {
    ways = wy = ws = 0;
    for (i = 0; i <= m; i++) {
      ways = (ways + dp[i][i + 1][n24]) % mod;
      if (i) ws = (ws + dp[i - 1][i + 1][n24]) % mod;
    }
    n25 = (m - n24) / 2;
    x = (n + m + 1) / 2 - n24 - n25;
    if (x < 0) continue;
    x--;
    if (x >= 0 && (n + m) % 2 && m % 2 != n24 % 2 && ws)
      ans = ans + ws * cal(x, n24, n25);
    x++;
    if (m % 2 == n24 % 2) {
      if ((n - m) % 2 == 0)
        ans = ans + ways * cal(x, n24, n25);
      else if (x) {
        tmp = ways * cal(x - 1, n24, n25) % mod;
        tmp = tmp * 26 % mod;
        ans = (ans + tmp) % mod;
      }
    }
    x--;
    if (x >= 0 && m % 2 != n24 % 2 && ws && (n + m) % 2 == 0)
      ans = ans + ws * cal(x, n24, n25 + 1);
    else if (x >= 0 && m % 2 != n24 % 2 && ws) {
      x--;
      if (x >= 0) {
        tmp = ws * cal(x, n24, n25 + 1) % mod;
        ans = ans + tmp * 25;
      }
      x++;
    }
    x++;
    ans %= mod;
  }
  printf("%d\n", ans);
  return 0;
}