#include <bits/stdc++.h>
using namespace std;
const int N = 205, P = 10007, M = N * N;
char s[N];
int n, m, tmp[N << 1][N << 1], lim, tp[M];
inline void add(int &a, int b) { a = (a + b) % P; }
inline void mul(int &a, int b) { a = a * b % P; }
struct Graph {
  int head[M], v[M * 2], nxt[M * 2], ptr, dp[N][M];
  bool vis[N][M];
  inline void add_edge(int uu, int vv) {
    v[ptr] = vv;
    nxt[ptr] = head[uu];
    head[uu] = ptr++;
  }
  int dfs(int cnt, int pos) {
    if (cnt < 0) return 0;
    if (vis[cnt][pos]) return dp[cnt][pos];
    for (int i = head[pos]; i != -1; i = nxt[i])
      add(dp[cnt][pos], dfs(cnt - tp[pos], v[i]));
    vis[cnt][pos] = 1;
    return dp[cnt][pos];
  }
  Graph() {
    memset(head, -1, sizeof(head));
    memset(nxt, -1, sizeof(nxt));
  }
} g;
struct Matrix {
  int a[N << 1][N << 1];
  inline int *operator[](const size_t &x) { return a[x]; }
  inline const int *operator[](const size_t &x) const { return a[x]; }
  Matrix operator*=(const Matrix &b) {
    for (int i = 1; i <= lim; i++)
      for (int j = 1; j <= lim; j++) tmp[i][j] = 0;
    for (int i = 1; i <= lim; i++)
      for (int j = i; j <= lim; j++)
        for (int k = j; k <= lim; k++) add(tmp[i][k], a[i][j] * b[j][k]);
    for (int i = 1; i <= lim; i++)
      for (int j = 1; j <= lim; j++) a[i][j] = tmp[i][j];
    return *this;
  }
} ts, ret;
int id[N][N], idx, f[N], gg[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> (s + 1) >> m;
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) id[i][j] = ++idx;
  ++idx;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      if (s[i] == s[j]) {
        if (j - i <= 1)
          g.add_edge(idx, id[i][j]);
        else
          g.add_edge(id[i + 1][j - 1], id[i][j]);
      } else {
        tp[id[i][j]] = 1;
        g.add_edge(id[i + 1][j], id[i][j]);
        g.add_edge(id[i][j - 1], id[i][j]);
      }
  for (int i = 0; i < n; i++) g.vis[i][id[1][n]] = 1;
  g.dp[tp[id[1][n]]][id[1][n]] = 1;
  for (int i = 0; i < n; i++) g.dfs(i, idx);
  for (int i = 1; i < n; i++) ts[i][i] = 24;
  int t = (n + 1) / 2;
  for (int i = 0; i < t; i++) ts[n + i][n + i] = 25;
  for (int i = 0; i < t; i++) ts[n + t + i][n + t + i] = 26;
  for (int i = 1; i < n + t - 1; i++) ++ts[i][i + 1];
  for (int i = 0; i < t; i++) ++ts[n + i][n + t + i];
  lim = n + t * 2 - 1;
  for (int i = 1; i <= lim; i++) ret[i][i] = 1;
  for (int p = (n + m) / 2; p > 0; p >>= 1, ts *= ts)
    if (p & 1) ret *= ts;
  for (int i = 0, v; i < n; i++)
    v = (n - i + 1) / 2, f[i] = ret[n - i][n + t + v - 1],
    gg[i] = ret[n - i][n + v - 1];
  int ans = 0;
  if ((n + m) & 1) {
    for (int i = 0; i < n; i++) add(ans, f[i] * g.dp[i][idx]);
    mul(ans, 26);
    for (int i = 1; i <= 26; i++)
      for (int j = 1; j <= n; j++)
        if (s[j] == 'a' + i - 1)
          for (int k = 0; k < n; k++) add(ans, gg[k] * g.dp[k][id[j][j]]);
  } else
    for (int i = 0; i < n; i++) add(ans, f[i] * g.dp[i][idx]);
  cout << ans << endl;
  return 0;
}
