#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;
}
