#include <bits/stdc++.h>
using namespace std;
const int P = 10007;
int n, m, N;
int f[210][210][210], g[210];
struct M {
  int v[310][310];
  int *operator[](const int &a) { return v[a]; }
  M() { memset(v, 0, sizeof(v)); }
  inline M operator*(const M &a) const {
    M b;
    int i, j, k;
    for (i = 0; i <= N; i++)
      for (j = i; j <= N; j++)
        for (k = i; k <= j; k++)
          b.v[i][j] = (b.v[i][j] + v[i][k] * a.v[k][j]) % P;
    return b;
  }
} S, T;
char str[210];
inline void pm(int y) {
  while (y) {
    if (y & 1) S = S * T;
    T = T * T, y >>= 1;
  }
}
int main() {
  scanf("%s%d", str, &m), n = strlen(str);
  int i, j, k;
  f[0][n - 1][0] = 1;
  for (i = 0; i < n; i++) {
    for (j = n - 1; j >= i; j--) {
      if (str[i] == str[j]) {
        for (k = 0; k < i + n - j; k++) {
          if (i + 1 < j)
            f[i + 1][j - 1][k] = (f[i + 1][j - 1][k] + f[i][j][k]) % P;
          else
            g[k] = (g[k] + f[i][j][k]) % P;
        }
      } else {
        for (k = 0; k < i + n - j; k++) {
          f[i + 1][j][k + 1] = (f[i + 1][j][k + 1] + f[i][j][k]) % P;
          f[i][j - 1][k + 1] = (f[i][j - 1][k + 1] + f[i][j][k]) % P;
        }
      }
    }
  }
  N = n + (n + 1) / 2 + 1;
  S[0][1] = 1, S[0][N - (n + 1) / 2] = g[0], T[N][N] = 26;
  for (i = 1; i <= n; i++) {
    T[i][i] = 24, T[i][N - (n - i + 1) / 2] = g[i];
    if (i != n) T[i][i + 1] = 1;
  }
  for (i = n + 1; i < N; i++) T[i][i + 1] = 1, T[i][i] = 25;
  if ((n + m) & 1) {
    pm((n + m + 1) >> 1);
    int ans = S[0][N];
    memset(S.v, 0, sizeof(S.v));
    memset(T.v, 0, sizeof(T.v));
    memset(g, 0, sizeof(g));
    for (i = 0; i < n - 1; i++)
      if (str[i] == str[i + 1])
        for (k = 0; k <= n; k++) {
          g[k] = (g[k] + f[i][i + 1][k]) % P;
        }
    S[0][1] = 1, S[0][N - (n + 1) / 2] = g[0];
    for (i = 1; i <= n; i++) {
      T[i][i] = 24, T[i][N - (n - i + 1) / 2] = g[i];
      if (i != n) T[i][i + 1] = 1;
    }
    for (i = n + 1; i < N; i++) T[i][i + 1] = 1, T[i][i] = 25;
    pm((n + m + 1) >> 1);
    printf("%d", (ans - S[0][N] + P) % P);
  } else {
    pm((n + m) >> 1);
    printf("%d", S[0][N]);
  }
  return 0;
}
