#include <bits/stdc++.h>
const unsigned int Mod = 10007;
const int ML = 205, MS = 305;
inline void Add(unsigned int &x, unsigned int y) {
  x -= (x += y) >= Mod ? Mod : 0;
}
int D;
struct Mat {
  unsigned int A[MS][MS];
  Mat() { memset(A, 0, sizeof A); }
  Mat(int x) {
    memset(A, 0, sizeof A);
    for (int i = 1; i <= D; ++i) A[i][i] = x;
  }
  void operator*=(Mat B) {
    static int C[MS][MS];
    for (int i = 1; i <= D; ++i)
      for (int j = 1; j <= i; ++j) C[i][j] = A[i][j], A[i][j] = 0;
    for (int i = 1; i <= D; ++i) {
      for (int k = 1; k <= i; ++k)
        for (int j = 1; j <= k; ++j) {
          A[i][j] += C[i][k] * B.A[k][j];
          if (A[i][j] >= 4194847260) A[i][j] %= Mod;
        }
      for (int j = 1; j <= i; ++j) A[i][j] %= Mod;
    }
  }
  friend Mat operator^(Mat B, int e) {
    Mat A(1);
    for (; e; e >>= 1, B *= B)
      if (e & 1) A *= B;
    return A;
  }
} A;
int N, L, G;
char S[ML];
unsigned int f[ML][ML][ML], g[ML], Ans;
int main() {
  scanf("%s%d", S + 1, &N), N += L = strlen(S + 1);
  f[1][L][0] = 1;
  for (int q = L; q >= 1; --q) {
    for (int i = 1; i <= L - q + 1; ++i) {
      int j = i + q - 1, t = S[i] != S[j];
      if (t) {
        for (int x = 0; x < L; ++x)
          Add(f[i + 1][j][x + 1], f[i][j][x]),
              Add(f[i][j - 1][x + 1], f[i][j][x]);
      } else {
        unsigned int *v = i + 2 <= j ? f[i + 1][j - 1] : g;
        for (int x = 0; x < L; ++x) Add(v[x], f[i][j][x]);
      }
    }
  }
  G = (L - 1) / 2 + 1, D = L + G + 1;
  for (int i = 1; i <= D; ++i) {
    if (i <= L) {
      if (i > 1) A.A[i][i] = 24;
      A.A[L + G - (L - i) / 2][i] = g[i - 1];
      if (i < L) A.A[i + 1][i] = 1;
    } else if (i < D) {
      A.A[i][i] = 25;
      A.A[i + 1][i] = 1;
    } else
      A.A[i][i] = 26;
  }
  Ans = (N & 1 ? 26 : 1) * (A ^ (N / 2 + 1)).A[D][1];
  if (N & 1) {
    for (int i = 1; i <= L; ++i) {
      A.A[L + G - (L - i) / 2][i] = 0;
      for (int j = 1; j <= L; ++j)
        Add(A.A[L + G - (L - i) / 2][i], f[j][j][i - 1]);
    }
    Add(Ans, (A ^ (N / 2 + 1)).A[D - 1][1]);
  }
  printf("%d\n", Ans % Mod);
  return 0;
}
