#include <bits/stdc++.h>
const int max_N = 207;
const int mod = 10007;
int n, m, dp[max_N][max_N][max_N];
char s[max_N];
int read() {
  char c = getchar();
  int ans = 0;
  bool flag = true;
  while (!isdigit(c)) flag &= (c != '-'), c = getchar();
  while (isdigit(c)) ans = 10 * ans + c - '0', c = getchar();
  return flag ? ans : -ans;
}
void Write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x < 10)
    putchar(x + '0');
  else
    Write(x / 10), putchar(x % 10 + '0');
}
int min(int x, int y) { return x < y ? x : y; }
int max(int x, int y) { return x > y ? x : y; }
void _min(int &x, int y) {
  if (x > y) x = y;
}
void _max(int &x, int y) {
  if (x < y) x = y;
}
int plus(int x, int y) { return (x += y) >= mod ? x - mod : x; }
int minus(int x, int y) { return (x -= y) < 0 ? x + mod : x; }
int fma(int x, int y, int z) { return (x + y * z) % mod; }
void _plus(int &x, int y) {
  if ((x += y) >= mod) x -= mod;
}
void _minus(int &x, int y) {
  if ((x -= y) < 0) x += mod;
}
void _fma(int &x, int y, int z) { x = (x + y * z) % mod; }
int _inv(int x) { return x == 1 ? 1 : (mod - mod / x) * _inv(mod % x) % mod; }
namespace matrix_base {
int size;
std::vector<std::vector<int> > O, I;
}  // namespace matrix_base
void init_matrix(int n) {
  using namespace matrix_base;
  size = n;
  O.clear(), I.clear();
  O.resize(n), I.resize(n);
  for (int i = 0; i < n; i++) O[i].resize(n), I[i].resize(n), I[i][i] = 1;
}
std::vector<std::vector<int> > operator*(std::vector<std::vector<int> > A,
                                         std::vector<std::vector<int> > B) {
  std::vector<std::vector<int> > C = matrix_base::O;
  for (int i = 0; i < matrix_base::size; i++)
    for (int k = 0; k < matrix_base::size; k++)
      for (int j = 0; j < matrix_base::size; j++)
        _fma(C[i][j], A[i][k], B[k][j]);
  return C;
}
std::vector<std::vector<int> > power(
    std::vector<std::vector<int> > x, int y,
    std::vector<std::vector<int> > ans = matrix_base::I) {
  for (; y; y >>= 1, x = x * x)
    if (y & 1) ans = ans * x;
  return ans;
}
int main() {
  scanf("%s", s + 1), n = strlen(s + 1), m = read() + n;
  dp[1][n][0] = 1;
  for (int _ = n; _; _--)
    for (int i = 1, j = _; j <= n; i++, j++)
      for (int k = 0; k <= n - _; k++)
        if (s[i] == s[j]) {
          if (_ <= 2)
            _plus(dp[0][0][k], dp[i][j][k]);
          else
            _plus(dp[i + 1][j - 1][k], dp[i][j][k]);
        } else
          _plus(dp[i][j - 1][k + 1], dp[i][j][k]),
              _plus(dp[i + 1][j][k + 1], dp[i][j][k]);
  init_matrix((3 * n + 1) / 2);
  std::vector<std::vector<int> > G = matrix_base::O;
  G[0][0] = 25;
  for (int i = 1; i < n; i++) G[i][i] = 24;
  for (int i = n; i < (3 * n - 1) / 2; i++) G[i][i] = 25;
  G[(3 * n - 1) / 2][(3 * n - 1) / 2] = 26;
  for (int i = 1; i < n; i++) G[i - 1][i] = 1;
  for (int i = n + 1; i < (3 * n + 1) / 2; i++) G[i - 1][i] = 1;
  for (int i = 0; i < n; i++)
    G[i][(3 * n + 1) / 2 - (n - i + 1) / 2] = dp[0][0][i];
  if (m & 1) {
    int ans = power(G, (m + 1) / 2)[0][(3 * n - 1) / 2];
    std::fill(dp[0][0], dp[0][0] + n, 0);
    for (int i = 2; i <= n; i++)
      if (s[i - 1] == s[i])
        for (int j = 0; j < n; j++) _plus(dp[0][0][j], dp[i - 1][i][j]);
    for (int i = 0; i < n; i++)
      G[i][(3 * n + 1) / 2 - (n - i + 1) / 2] = dp[0][0][i];
    G[(3 * n - 1) / 2][(3 * n - 1) / 2] = 0;
    Write(minus(ans, power(G, (m + 1) / 2)[0][(3 * n - 1) / 2]));
  } else
    Write(power(G, m / 2)[0][(3 * n - 1) / 2]);
  return 0;
}
