#include <bits/stdc++.h>
using namespace std;
const int NN = 100 + 117;
const int MM = 100 + 117;
int read() {
  int fl = 1, x;
  char c;
  for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
    ;
  if (c == '-') {
    fl = -1;
    c = getchar();
  }
  for (x = 0; c >= '0' && c <= '9'; c = getchar())
    x = (x << 3) + (x << 1) + c - '0';
  return x * fl;
}
void open() { freopen("a.in", "r", stdin); }
void close() {
  fclose(stdin);
  fclose(stdout);
}
int m, n;
char s[NN] = {};
int dp[NN][NN][NN] = {};
int mat[2 * NN][2 * NN] = {};
int ans[2 * NN][2 * NN] = {};
const int mod = 10007;
void upd(int &a, int b) { a = (a + b) % mod; }
int tp[2 * NN][2 * NN] = {};
void unit(int a[2 * NN][2 * NN], int siz) {
  for (int i = 0; i <= siz; ++i) {
    for (int j = 0; j <= siz; ++j) {
      a[i][j] = (i == j);
    }
  }
}
int c[2 * NN][2 * NN] = {};
void mul(int a[2 * NN][2 * NN], int b[2 * NN][2 * NN], int siz) {
  for (int i = 0; i <= siz; ++i) {
    for (int j = 0; j <= siz; ++j) c[i][j] = b[j][i];
  }
  for (int i = 0; i <= siz; ++i) {
    for (int j = i; j <= siz; ++j) {
      long long x = 0;
      for (int k = i; k <= j; ++k) {
        x += a[i][k] * c[j][k];
      }
      tp[i][j] = x % mod;
    }
  }
  for (int i = 0; i <= siz; ++i)
    for (int j = 0; j <= siz; ++j) a[i][j] = tp[i][j];
}
void ksm(int siz, int n) {
  n += 1;
  unit(ans, siz);
  for (; n; n >>= 1, mul(mat, mat, siz)) {
    if (n & 1) mul(ans, mat, siz);
  }
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  m = read();
  dp[0][0][n + 1] = 1;
  for (int i = 0; i < n; ++i) {
    for (int l = 0; l <= n; ++l) {
      for (int r = n + 1; r > l + 1; --r) {
        int xtl = l + 1, xtr = r - 1;
        if (s[xtl] == s[xtr]) {
          upd(dp[i][xtl][xtr], dp[i][l][r]);
        } else {
          upd(dp[i + 1][l][xtr], dp[i][l][r]);
          upd(dp[i + 1][xtl][r], dp[i][l][r]);
        }
      }
    }
  }
  int all = n + (n + 1) / 2 + 1;
  for (int i = 1; i <= n; ++i) mat[i][i] = 24;
  for (int i = 0; i < n; ++i) mat[i][i + 1] = 1;
  for (int i = n + 1; i < all; ++i) mat[i][i] = 25;
  for (int i = n + 1; i < all; ++i) mat[i][i + 1] = 1;
  mat[all][all] = 26;
  for (int i = 0; i <= n; ++i) {
    int ot = (n - i + 1) / 2;
    int cnt = 0;
    for (int l = 0; l <= n; ++l) {
      upd(cnt, dp[i][l][l]);
      upd(cnt, dp[i][l][l + 1]);
    }
    mat[i][all - ot] = cnt;
  }
  ksm(all, (n + m + 1) / 2);
  int op = ans[0][all];
  if ((n + m) & 1) {
    memset(mat, 0, sizeof mat);
    for (int i = 1; i <= n; ++i) mat[i][i] = 24;
    for (int i = 0; i < n; ++i) mat[i][i + 1] = 1;
    for (int i = n + 1; i < all; ++i) mat[i][i] = 25;
    for (int i = n + 1; i < all; ++i) mat[i][i + 1] = 1;
    for (int i = 0; i <= n; ++i) {
      int ot = (n - i + 1) / 2;
      int cnt = 0;
      for (int l = 1; l < n; ++l) {
        if (s[l] == s[l + 1]) upd(cnt, dp[i][l - 1][l + 2]);
      }
      mat[i][all - ot] = cnt;
    }
    ksm(all, (n + m + 1) / 2);
    op = (mod + op - ans[0][all]) % mod;
  }
  printf("%d\n", op);
  close();
  return 0;
}
