#include <bits/stdc++.h>
using namespace std;
const int P = 10007, N = 310;
int m, cnt, f[N], g[N], dp[N][N][N], n, p[N], q[N];
char s[N];
void upd(int& x, int y) { ((x += y) >= P) && (x -= P); }
struct Mat {
  int a[N][N];
  inline int* operator[](int x) { return a[x]; }
  Mat() { memset(a, 0, sizeof(a)); }
} A, B;
inline Mat operator*(Mat a, Mat b) {
  Mat c;
  for (int i = (1); i <= (cnt); ++i)
    for (int j = (i); j <= (cnt); ++j)
      for (int k = (i); k <= (j); ++k) (c[i][j] += a[i][k] * b[k][j]) %= P;
  return c;
}
inline void ksm(Mat a, int b, int x) {
  for (int i = (1); i <= (cnt); ++i) p[i] = 0;
  p[1] = 1;
  p[n + 1] = x;
  for (; b; b >>= 1, a = a * a)
    if (b & 1) {
      for (int i = (1); i <= (cnt); ++i)
        for (int j = (1); j <= (cnt); ++j) upd(q[j], p[i] * a[i][j] % P);
      for (int i = (1); i <= (cnt); ++i) p[i] = q[i], q[i] = 0;
    }
}
int main() {
  scanf("%s%d", s + 1, &m);
  n = strlen(s + 1);
  cnt = n + (n + 1) / 2 + 1;
  dp[1][n][0] = 1;
  for (int i = (1); i <= (n); ++i)
    for (int j = (n); j >= (i); --j)
      if (s[i] == s[j]) {
        if (i + 1 < j)
          for (int k = (0); k <= (i + n - j - 1); ++k)
            upd(dp[i + 1][j - 1][k], dp[i][j][k]);
        else
          for (int k = (0); k <= (i + n - j - 1); ++k) upd(f[k], dp[i][j][k]);
      } else
        for (int k = (0); k <= (i + n - j - 1); ++k)
          upd(dp[i][j - 1][k + 1], dp[i][j][k]),
              upd(dp[i + 1][j][k + 1], dp[i][j][k]);
  A[cnt][cnt] = 26;
  for (int i = (n + 1); i <= (cnt - 1); ++i) A[i][i + 1] = 1, A[i][i] = 25;
  for (int i = (1); i <= (n); ++i)
    A[i][i] = 24, A[i][cnt - (n - i + 1) / 2] = f[i], A[i][i + 1] = i != n;
  if ((n + m) & 1) {
    ksm(A, (n + m + 1) / 2, f[0]);
    int ans = p[cnt];
    for (int i = (1); i <= (n - 1); ++i)
      if (s[i] == s[i + 1])
        for (int k = (0); k <= (n - 1); ++k) upd(g[k], dp[i][i + 1][k]);
    for (int i = (n + 1); i <= (cnt - 1); ++i) B[i][i + 1] = 1, B[i][i] = 25;
    for (int i = (1); i <= (n); ++i)
      B[i][i] = 24, B[i][cnt - (n - i + 1) / 2] = g[i], B[i][i + 1] = i != n;
    ksm(B, (n + m + 1) / 2, g[0]);
    printf("%d\n", (ans - p[cnt] + P) % P);
  } else {
    ksm(A, (n + m) / 2, f[0]);
    printf("%d\n", p[cnt]);
  }
  return 0;
}
