#include <bits/stdc++.h>
using namespace std;
const int S = 205;
const long long K = 26, mod = 10007ll;
long long qpow(long long a, long long k) {
  long long res = 1ll;
  while (k) {
    if (k & 1) res = res * a % mod;
    a = a * a % mod, k >>= 1;
  }
  return res;
}
long long get_inv(long long x) {
  if (x == 1ll) return 1ll;
  return qpow(x, mod - 2);
}
struct poly {
  int deg;
  vector<long long> coef;
  poly() {
    deg = 0;
    coef.push_back(0ll);
  }
  poly(long long c) {
    deg = 0;
    coef.push_back(c);
  }
  long long get_coef(int k) const { return k <= deg ? coef[k] : 0ll; }
  poly& operator=(poly rhs) {
    deg = rhs.deg, coef = rhs.coef;
    return *this;
  }
  poly operator+(poly rhs) const {
    poly res;
    res.deg = max(deg, rhs.deg), res.coef.resize(res.deg + 1);
    for (int i = 0; i <= res.deg; i++)
      res.coef[i] = (get_coef(i) + rhs.get_coef(i)) % mod;
    while (res.coef.size() > 1 && !res.coef.back())
      res.deg--, res.coef.pop_back();
    return res;
  }
  poly operator-(poly rhs) const {
    poly res;
    res.deg = max(deg, rhs.deg), res.coef.resize(res.deg + 1);
    for (int i = 0; i <= res.deg; i++)
      res.coef[i] = (get_coef(i) + mod - rhs.get_coef(i)) % mod;
    while (res.coef.size() > 1 && !res.coef.back())
      res.deg--, res.coef.pop_back();
    return res;
  }
  poly operator+=(poly rhs) { return *this = *this + rhs; }
  poly operator-=(poly rhs) { return *this = *this - rhs; }
  poly operator*(poly rhs) const {
    poly res;
    res.deg = deg + rhs.deg, res.coef.resize(res.deg + 1);
    for (int i = 0; i <= deg; i++) {
      for (int j = 0; j <= rhs.deg; j++)
        res.coef[i + j] = (res.coef[i + j] + coef[i] * rhs.coef[j]) % mod;
    }
    return res;
  }
  poly operator%(poly rhs) const {
    poly res = *this;
    for (int i = deg; i >= rhs.deg; i--) {
      long long k = res.coef[i] * get_inv(rhs.coef[rhs.deg]) % mod;
      for (int j = 0; j <= rhs.deg; j++) {
        res.coef[i - rhs.deg + j] =
            (res.coef[i - rhs.deg + j] + mod * mod - rhs.coef[j] * k) % mod;
      }
    }
    while (res.coef.size() > 1 && !res.coef.back())
      res.deg--, res.coef.pop_back();
    return res;
  }
} f0, f1, f2, F, G, pw[S << 1], pw1[S << 1], pw2[S << 1], id;
int s, n;
char str[S];
long long f[S][S][S], tmp0[S], tmp1[S], tmp2[S];
long long calc(poly f, poly g, int k) {
  vector<long long> vec(g.deg);
  for (int i = 0; i < g.deg; i++) {
    vec[i] = f.get_coef(i);
    for (int j = 1; j <= i; j++)
      vec[i] = (vec[i] + mod * mod - g.coef[j] * vec[i - j]) % mod;
  }
  poly res(1ll), a = id, g_;
  g_.deg = g.deg, g_.coef.resize(g.deg + 1);
  for (int i = 0; i <= g.deg; i++) g_.coef[i] = g.coef[g.deg - i];
  while (k) {
    if (k & 1) res = res * a % g_;
    a = a * a % g_, k >>= 1;
  }
  long long ans = 0ll;
  for (int i = 0; i < g.deg; i++) ans = (ans + vec[i] * res.get_coef(i)) % mod;
  return ans;
}
int main() {
  scanf("%s", str + 1), s = strlen(str + 1);
  scanf("%d", &n);
  for (int i = 0; i <= s + 1; i++) {
    for (int j = 0; j <= s + 1; j++) {
      for (int k = 0; k <= s; k++) f[i][j][k] = 0ll;
    }
  }
  for (int i = 1; i <= s; i++) {
    for (int j = s; j >= i; j--) {
      for (int k = 0; k <= s; k++) {
        if (i == 1 && j == s && k == 0) f[i][j][k] = 1ll;
        if (str[i] == str[j])
          f[i + 1][j - 1][k + 1] = (f[i + 1][j - 1][k + 1] + f[i][j][k]) % mod;
        else {
          f[i + 1][j][k] = (f[i + 1][j][k] + f[i][j][k]) % mod;
          f[i][j - 1][k] = (f[i][j - 1][k] + f[i][j][k]) % mod;
        }
      }
    }
  }
  for (int i = 0; i <= s; i++) tmp0[i] = 0ll, tmp1[i] = tmp2[i] = 0ll;
  for (int i = 0; i <= s + 1; i++) {
    for (int j = 0; j <= s + 1; j++) {
      for (int k = 0; k <= s; k++) {
        if (i < j || !f[i][j][k]) continue;
        if (i - j == 1) tmp1[k] = (tmp1[k] + f[i][j][k]) % mod;
        if (i - j == 2) tmp2[k] = (tmp2[k] + f[i][j][k]) % mod;
        if (i == j && (n + s & 1)) tmp0[k] = (tmp0[k] + f[i][j][k]) % mod;
      }
    }
  }
  id.deg = 1, id.coef.resize(2);
  id.coef[1] = 1ll;
  f0.deg = f1.deg = f2.deg = 1;
  f0.coef.resize(2), f1.coef.resize(2), f2.coef.resize(2);
  f0.coef[0] = f1.coef[0] = f2.coef[0] = 1ll;
  f0.coef[1] = (mod - K) % mod, f1.coef[1] = (mod - K + 1) % mod,
  f2.coef[1] = (mod - K + 2) % mod;
  pw[0] = pw1[0] = pw2[0] = poly(1ll);
  for (int i = 1; i <= 2 * s; i++) {
    pw[i] = pw[i - 1] * id % mod;
    pw1[i] = pw1[i - 1] * f1 % mod;
    pw2[i] = pw2[i - 1] * f2 % mod;
  }
  G = f0 * pw1[s] * pw2[s + 1];
  for (int i = 0; i <= s; i++) {
    if (i < s)
      F +=
          poly(tmp0[i]) * pw[s - 1 - i] * f0 * pw1[s - 1 - i] * pw2[i + 1 << 1];
    if (n + s & 1)
      F += poly(tmp1[i] * K % mod) * pw[s - i] * pw1[s - i] * pw2[i << 1 | 1];
    else
      F += poly(tmp1[i]) * pw[s - i] * pw1[s - i] * pw2[i << 1 | 1];
    if (n + s & 1)
      F += poly(tmp2[i] * K % mod) * pw[s + 1 - i] * pw1[s - i] * pw2[i << 1];
    else
      F += poly(tmp2[i]) * pw[s + 1 - i] * pw1[s - i] * pw2[i << 1];
  }
  printf("%lld\n", calc(F, G, n + s >> 1));
  return 0;
}
