#include <bits/stdc++.h>
const int N(305), Mod(10007), LIM(Mod *Mod);
int n, m, cnt, col[N][N], h[N][N][N], g[N];
char s[N];
struct Matrix {
  int a[N][N];
  inline int *operator[](const int &x) { return a[x]; }
  inline const int *operator[](const int &x) const { return a[x]; }
} F, G;
inline void Add(int &x, int y) {
  x += y;
  if (x >= LIM) x %= Mod;
}
Matrix operator*(const Matrix &a, const Matrix &b) {
  Matrix c;
  std::memset(c.a, 0, sizeof c.a);
  for (int i = 0; i <= cnt; i++)
    for (int k = i; k <= cnt; k++)
      for (int j = k; j <= cnt; j++) Add(c[i][j], a[i][k] * b[k][j]);
  for (int i = 0; i <= cnt; i++)
    for (int j = i; j <= cnt; j++) c[i][j] %= Mod;
  return c;
}
void Pow(int y) {
  for (; y; y >>= 1, G = G * G)
    if (y & 1) F = F * G;
}
int main() {
  scanf("%s%d", s + 1, &m), n = strlen(s + 1), h[1][n][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = n; j >= i; j--)
      if (s[i] == s[j]) {
        for (int k = 0; k < i + n - j; k++)
          if (i + 1 < j)
            h[i + 1][j - 1][k] = (h[i + 1][j - 1][k] + h[i][j][k]) % Mod;
          else
            g[k] = (g[k] + h[i][j][k]) % Mod;
      } else {
        for (int k = 0; k < i + n - j; k++)
          h[i][j - 1][k + 1] = (h[i][j - 1][k + 1] + h[i][j][k]) % Mod,
                          h[i + 1][j][k + 1] =
                              (h[i + 1][j][k + 1] + h[i][j][k]) % Mod;
      }
  cnt = n + 1 + (n + 1) / 2, F[0][1] = 1, F[0][n + 1] = g[0], G[cnt][cnt] = 26;
  for (int i = 1, j; i <= n; i++)
    j = cnt - (n - i + 1) / 2, G[i][i] = 24, G[i][j] = g[i];
  for (int i = 1; i < n; i++) G[i][i + 1] = 1;
  for (int i = n + 1; i < cnt; i++) G[i][i] = 25, G[i][i + 1] = 1;
  Pow((n + m + 1) >> 1);
  if ((n + m) & 1) {
    int ans = F[0][cnt];
    std::memset(g, 0, sizeof g);
    std::memset(F.a, 0, sizeof F.a), std::memset(G.a, 0, sizeof G.a);
    for (int i = 1; i < n; i++)
      if (s[i] == s[i + 1])
        for (int k = 0; k <= n; k++) g[k] = (g[k] + h[i][i + 1][k]) % Mod;
    F[0][1] = 1, F[0][n + 1] = g[0];
    for (int i = 1, j; i <= n; i++)
      j = cnt - (n - i + 1) / 2, G[i][i] = 24, G[i][j] = g[i];
    for (int i = 1; i < n; i++) G[i][i + 1] = 1;
    for (int i = n + 1; i < cnt; i++) G[i][i] = 25, G[i][i + 1] = 1;
    Pow((n + m + 1) >> 1);
    printf("%d\n", (ans - F[0][cnt] + Mod) % Mod);
  } else
    printf("%d\n", F[0][cnt]);
  return 0;
}
