#include <bits/stdc++.h>
const int mod = 1e4 + 7;
char s[205];
int n, m, f[205][205][205], w[205], tl, r[205], g[205], fin;
struct Matrix {
  int r, c, A[305][305];
  void reset(int r1, int c1) {
    r = r1;
    c = c1;
    std::memset(A, 0, sizeof(A));
  }
};
Matrix mul(Matrix A, Matrix B) {
  Matrix C;
  C.reset(A.r, B.c);
  for (int i = 1; i <= A.r; ++i)
    for (int j = i; j <= A.c; ++j)
      for (int k = j; k <= B.c; ++k)
        C.A[i][k] = (C.A[i][k] + A.A[i][j] * B.A[j][k] % mod) % mod;
  return C;
}
Matrix expo(Matrix A, int b) {
  if (b == 1) return A;
  Matrix D = expo(A, b >> 1);
  D = mul(D, D);
  if (b & 1) D = mul(D, A);
  return D;
}
int main() {
  scanf("%s", s + 1);
  m = std::strlen(s + 1);
  scanf("%d", &n);
  n += m;
  f[1][m][0] = 1;
  for (int i = 1; i <= m; ++i)
    for (int j = m; j >= i; j--)
      for (int k = 0; k <= m; ++k) {
        if (s[i] == s[j]) {
          if (i + 1 <= j - 1)
            f[i + 1][j - 1][k] = (f[i + 1][j - 1][k] + f[i][j][k]) % mod;
          else
            w[k] = (w[k] + f[i][j][k]) % mod;
        } else {
          f[i][j - 1][k + 1] = (f[i][j - 1][k + 1] + f[i][j][k]) % mod;
          f[i + 1][j][k + 1] = (f[i + 1][j][k + 1] + f[i][j][k]) % mod;
        }
      }
  for (int i = 1; i <= m; ++i) r[i] = ++tl;
  for (int i = (m + 1) / 2; i >= 1; --i) g[i] = ++tl;
  fin = ++tl;
  Matrix M, G;
  G.reset(tl, tl);
  M.reset(1, tl);
  for (int i = 1; i < m; ++i) G.A[r[i]][r[i + 1]] = 1;
  for (int i = 2; i <= (m + 1) / 2; ++i) G.A[g[i]][g[i - 1]] = 1;
  for (int i = 1; i <= m; ++i) G.A[r[i]][r[i]] = 24;
  for (int i = 1; i <= (m + 1) / 2; ++i) G.A[g[i]][g[i]] = 25;
  for (int i = 1; i <= m; ++i) G.A[r[i]][g[(m - i + 1) / 2]] = w[i];
  G.A[g[1]][fin] = 1;
  G.A[fin][fin] = 26;
  M.A[1][1] = 1;
  M.A[1][g[(m + 1) / 2]] = w[0];
  M = mul(M, expo(G, (n + 1) / 2));
  if (n % 2 == 0) {
    printf("%d ", M.A[1][tl]);
    return 0;
  }
  int ans1 = M.A[1][tl];
  G.reset(tl, tl);
  M.reset(1, tl);
  M.A[1][1] = 1;
  std::memset(w, 0, sizeof(w));
  for (int i = 1; i < m; ++i)
    for (int k = 0; k <= m; ++k)
      if (s[i] == s[i + 1]) w[k] = (w[k] + f[i][i + 1][k]) % mod;
  G.reset(tl, tl);
  M.reset(1, tl);
  for (int i = 1; i < m; ++i) G.A[r[i]][r[i + 1]] = 1;
  for (int i = 2; i <= (m + 1) / 2; ++i) G.A[g[i]][g[i - 1]] = 1;
  for (int i = 1; i <= m; ++i) G.A[r[i]][r[i]] = 24;
  for (int i = 1; i <= (m + 1) / 2; ++i) G.A[g[i]][g[i]] = 25;
  for (int i = 1; i <= m; ++i) G.A[r[i]][g[(m - i + 1) / 2]] = w[i];
  G.A[g[1]][fin] = 1;
  M.A[1][1] = 1;
  M.A[1][g[(m + 1) / 2]] = w[0];
  M = mul(M, expo(G, (n + 1) / 2));
  printf("%d", (ans1 - M.A[1][tl] + mod) % mod);
  return 0;
}
