#include <bits/stdc++.h>
using namespace std;
const int e = 205, o = e << 1, mod = 1e4 + 7;
int ans, m, n, a[o][o], b[o], f[e][e][e], cnt, c[o][o], d[o];
bool vis[e][e][e];
char s[e];
inline void add(int &x, int y) { (x += y) >= mod && (x -= mod); }
inline int plu(int x, int y) {
  add(x, y);
  return x;
}
inline void del(int &x, int y) { (x -= y) < 0 && (x += mod); }
inline int dfs(int x, int l, int r) {
  if (x < 0) return 0;
  if (vis[x][l][r]) return f[x][l][r];
  vis[x][l][r] = 1;
  int &res = f[x][l][r];
  if (l > r) {
    if (!x)
      res = 1;
    else
      res = 0;
  } else {
    if (s[l] == s[r])
      res = dfs(x, l + 1, r - 1);
    else
      res = plu(dfs(x - 1, l + 1, r), dfs(x - 1, l, r - 1));
  }
  return res;
}
inline void merge() {
  int i, j, k;
  for (i = 1; i <= cnt; i++)
    for (j = 1; j <= cnt; j++) c[i][j] = a[i][j], a[i][j] = 0;
  for (i = 1; i <= cnt; i++)
    for (k = i; k <= cnt; k++)
      for (j = k; j <= cnt; j++) a[i][j] = (a[i][j] + c[i][k] * c[k][j]) % mod;
}
inline void join() {
  int i, j, k;
  for (i = 1; i <= cnt; i++) d[i] = b[i], b[i] = 0;
  for (k = 1; k <= cnt; k++)
    for (j = k; j <= cnt; j++) b[j] = (b[j] + d[k] * a[k][j]) % mod;
}
inline void ksm(int y) {
  y++;
  while (y) {
    if (y & 1) join();
    y >>= 1;
    merge();
  }
}
inline int div2(int x) { return (x >> 1) + (x & 1); }
inline int id1(int x) { return x + 1; }
inline int id2(int x) { return x + m + 1; }
inline void build() {
  int i, j;
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  for (i = 0; i <= m; i++) {
    int x = id1(i);
    a[x][x] = 24;
    if (i != m) a[x][x + 1] = 1;
    int j = div2(m - i), y = id2(div2(m) - j + 1);
    if (m + 2 <= y && y <= id2(div2(m))) {
      a[x][y] = dfs(i, 1, m);
    }
  }
  for (i = 1; i <= div2(m); i++) {
    int x = id2(i);
    a[x][x] = 25;
    a[x][x + 1] = 1;
  }
  a[cnt][cnt] = 26;
  a[1][1] = 0;
  b[1] = 1;
}
int main() {
  scanf("%s", s + 1);
  m = strlen(s + 1);
  cin >> n;
  n += m;
  int i;
  cnt = div2(m) + 2 + m;
  build();
  ksm(div2(n));
  ans = b[cnt];
  if (n & 1) {
    build();
    a[cnt][cnt] = 0;
    for (i = 0; i <= m; i++) {
      int x = id1(i);
      int j = div2(m - i), y = id2(div2(m) - j + 1);
      if (y >= m + 2 && (2 * j + i != m)) a[x][y] = 0;
    }
    ksm(div2(n));
    del(ans, b[cnt]);
  }
  cout << ans << endl;
  return 0;
}
