#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 10, mod = 10007, M = mod + 2;
int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
void ad(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }
int fpow(int a, int b) {
  int an = 1;
  while (b) {
    if (b & 1) an = 1ll * an * a % mod;
    a = 1ll * a * a % mod, b >>= 1;
  }
  return an;
}
int ginv(int a) { return fpow(a, mod - 2); }
int pt;
struct mtx {
  int a[N << 1][N << 1];
  mtx() { memset(a, 0, sizeof(a)); }
  mtx operator*(const mtx &bb) const {
    long long nw;
    mtx an;
    for (int i = 1; i <= pt; ++i)
      for (int j = 1; j <= pt; ++j) {
        nw = 0;
        for (int k = 1; k <= pt; ++k) nw += a[i][k] * bb.a[k][j];
        an.a[i][j] = nw % mod;
      }
    return an;
  }
} aa, bb, zb;
char cc[N];
int n, m, lm, f[N][N][N], ans;
int p1[N], p2[N], p3[N];
void wk1() {
  f[1][n][0] = 1;
  for (int h = n - 1; ~h; --h)
    for (int i = 1, j = h + 1; j <= n; ++i, ++j)
      for (int k = 0; k <= n - h; ++k) {
        if (!f[i][j][k]) continue;
        if (cc[i] != cc[j])
          ad(f[i + 1][j][k], f[i][j][k]), ad(f[i][j - 1][k], f[i][j][k]);
        else if (i != j)
          ad(f[i + 1][j - 1][k + 1], f[i][j][k]);
      }
  for (int k = 0; k <= n / 2 + 1; ++k) {
    int l = n - 2 * k, sm;
    if (l >= 0) {
      sm = 0;
      for (int i = 0; i <= n; ++i) ad(sm, f[i + 1][i][k]);
      ad(ans, 1ll * sm * aa.a[p1[l]][p3[k]] % mod);
    }
    --l;
    if (l >= 0) {
      sm = 0;
      for (int i = 1; i <= n; ++i) ad(sm, f[i][i][k]);
      ad(ans, 1ll * sm * aa.a[p1[l]][p3[k + 1]] % mod);
    }
  }
  ans = 26ll * ans % mod;
  for (int k = 0; k <= (n - 1) / 2; ++k) {
    int l = (n - 1) - 2 * k, sm = 0;
    for (int i = 1; i <= n; ++i) ad(sm, f[i][i][k]);
    ad(ans, 1ll * sm * aa.a[p1[l]][p2[k + 1]] % mod);
  }
}
void wk2() {
  f[1][n][0] = 1;
  for (int h = n - 1; ~h; --h)
    for (int i = 1, j = h + 1; j <= n; ++i, ++j)
      for (int k = 0; k <= n - h; ++k) {
        if (!f[i][j][k]) continue;
        if (cc[i] != cc[j])
          ad(f[i + 1][j][k], f[i][j][k]), ad(f[i][j - 1][k], f[i][j][k]);
        else if (i != j)
          ad(f[i + 1][j - 1][k + 1], f[i][j][k]);
      }
  for (int k = 0; k <= n / 2 + 1; ++k) {
    int l = n - 2 * k, sm;
    if (l >= 0) {
      sm = 0;
      for (int i = 0; i <= n; ++i) ad(sm, f[i + 1][i][k]);
      ad(ans, 1ll * sm * aa.a[p1[l]][p3[k]] % mod);
    }
    --l;
    if (l >= 0) {
      sm = 0;
      for (int i = 1; i <= n; ++i) ad(sm, f[i][i][k]);
      ad(ans, 1ll * sm * aa.a[p1[l]][p3[k + 1]] % mod);
    }
  }
}
int main() {
  scanf("%s", cc + 1);
  n = strlen(cc + 1), m = rd();
  for (int i = n; i; --i) {
    p1[i] = ++pt;
    bb.a[p1[i]][p1[i]] = 24;
    if (i < n) bb.a[p1[i + 1]][p1[i]] = 1;
  }
  for (int i = 0; i <= (n + 3) / 2; ++i) {
    p2[i] = ++pt;
    if (i) {
      bb.a[p2[i]][p2[i]] = 25;
      if (i == 1)
        bb.a[p1[1]][p2[i]] = 1;
      else
        bb.a[p2[i - 1]][p2[i]] = 1;
    } else
      bb.a[p1[1]][p2[i]] = 1;
  }
  for (int i = 0; i <= (n + 3) / 2; ++i) {
    p3[i] = ++pt;
    bb.a[p3[i]][p3[i]] = 26;
    if (i)
      bb.a[p2[i]][p3[i]] = 1;
    else
      bb.a[p1[1]][p3[i]] = 1;
  }
  p1[0] = p2[1];
  for (int i = n; ~i; --i) aa.a[p1[i]][p1[i]] = 1;
  zb = bb;
  int rs = (n + m) / 2;
  while (rs) {
    if (rs & 1) aa = aa * bb;
    bb = bb * bb, rs >>= 1;
  }
  if ((n + m) & 1)
    wk1();
  else
    wk2();
  printf("%d\n", ans);
  return 0;
}
