#include <bits/stdc++.h>
using namespace std;
namespace my_header {
const int INF = 0x3f3f3f3f;
inline char gchar() {
  char ret = getchar();
  for (; (ret == '\n' || ret == '\r' || ret == ' ') && ret != EOF;
       ret = getchar())
    ;
  return ret;
}
template <class T>
inline void fr(T &ret, char c = ' ', int flg = 1) {
  for (c = getchar(); (c < '0' || '9' < c) && c != '-'; c = getchar())
    ;
  if (c == '-') {
    flg = -1;
    c = getchar();
  }
  for (ret = 0; '0' <= c && c <= '9'; c = getchar()) ret = ret * 10 + c - '0';
  ret = ret * flg;
}
inline int fr() {
  int t;
  fr(t);
  return t;
}
template <class T>
inline void fr(T &a, T &b) {
  fr(a), fr(b);
}
template <class T>
inline void fr(T &a, T &b, T &c) {
  fr(a), fr(b), fr(c);
}
template <class T>
inline char wr(T a, int b = 10, bool p = 1) {
  return a < 0 ? putchar('-'), wr(-a, b, 0)
               : (a == 0 ? (p ? putchar('0') : p)
                         : (wr(a / b, b, 0), putchar('0' + a % b)));
}
template <class T>
inline void wt(T a) {
  wr(a), puts("");
}
template <class T>
inline void wt(T a, T b) {
  wr(a), putchar(' '), wr(b), puts("");
}
template <class T>
inline void wt(T a, T b, T c) {
  wr(a), putchar(' '), wr(b), putchar(' '), wr(c), puts("");
}
template <class T>
inline void wt(T a, T b, T c, T d) {
  wr(a), putchar(' '), wr(b), putchar(' '), wr(c), putchar(' '), wr(d),
      puts("");
}
template <class T>
inline T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
};  // namespace my_header
using namespace my_header;
const int maxS = 200 + 20;
const int maxM = maxS * 2;
const int mod = 10007;
char str[maxS];
int n, N, s, ans, f[maxS][maxS][maxS];
inline void add(int &a, int b) { (a += b) %= mod; }
inline void sub(int &a, int b) {
  (a -= b) %= mod;
  if (a < 0) a += mod;
}
int dp(int l, int r, int k) {
  int &ret = f[l][r][k];
  if (ret != -1) return ret;
  ret = 0;
  if (l > r) return 0;
  if (l == r) return ret = k == 0;
  if (str[l] == str[r]) {
    if (l == r - 1) return ret = k == 0;
    add(ret, dp(l + 1, r - 1, k));
  } else {
    add(ret, dp(l + 1, r, k - 1));
    add(ret, dp(l, r - 1, k - 1));
  }
  return ret;
}
struct Matrix {
  int d[maxM][maxM];
  int n;
  int *operator[](int a) { return d[a]; }
  void clear() { memset(d, 0, sizeof d); }
  void init() {
    memset(d, 0, sizeof d);
    for (int i = 1; i <= n; ++i) d[i][i] = 1;
  }
};
Matrix operator*(Matrix a, Matrix b) {
  Matrix c;
  c.n = a.n;
  c.clear();
  for (int i = 1; i <= a.n; ++i)
    for (int j = i; j <= a.n; ++j)
      for (int k = i; k <= j; ++k) add(c[i][j], a[i][k] * b[k][j]);
  return c;
}
template <class T>
inline T fpm(T b, int i) {
  T r;
  r.n = b.n;
  r.init();
  for (; i; i >>= 1, b = b * b)
    if (i & 1) r = r * b;
  return r;
}
int main() {
  cin >> (str + 1) >> n;
  s = strlen(str + 1);
  memset(f, -1, sizeof f);
  for (int i = 0; i <= s; ++i) f[1][s][i] = dp(1, s, i);
  N = (s + n + 1) >> 1;
  int n25 = (s + 1) / 2;
  int num = s + n25;
  Matrix x, res;
  x.clear();
  x.n = num + n25;
  x[1][1] = 24;
  for (int i = 2; i <= s; ++i) {
    x[i][i] = 24;
    x[i - 1][i] = 1;
  }
  x[s][s + 1] = 1;
  x[s + 1][s + 1] = 25;
  x[s + 1][num + 1] = 1;
  x[num + 1][num + 1] = 26;
  for (int i = s + 2; i <= s + n25; ++i) {
    x[i][i] = 25;
    x[i - 1][i] = 1;
    x[i][num + i - s] = 1;
    x[num + i - s][num + i - s] = 26;
  }
  res = fpm(x, N);
  for (int k = 0; k <= s - 1; ++k) {
    int a = s - k + 1;
    int b = s + n25 + (s - k + 1) / 2;
    add(ans, dp(1, s, k) * res[a][b]);
  }
  if ((s + n) % 2 == 1) {
    res = fpm(x, N - 1);
    for (int k = 0; k <= s - 1; ++k)
      if ((s - k) % 2 == 0) {
        int a = s - k + 1;
        int b = s + (s - k + 1) / 2;
        sub(ans, dp(1, s, k) * res[a][b]);
      }
  }
  cout << ans << endl;
  return 0;
}
