#include <bits/stdc++.h>
using namespace std;
const int N = 205, mod = 1e4 + 7;
char s[N];
int n, m, f[N][N][N][2], g[32][N << 1][N << 1], val[N << 1], pre[N << 1], cnt;
int calc_(int T) {
  memset(val, 0, sizeof(val)), T++;
  for (int p = 1; p < 31; p++) {
    memset(g[p], 0, sizeof(g[p]));
    for (int i = 0; i <= cnt; i++)
      for (int k = i; k <= cnt; k++)
        for (int j = k; j <= cnt; j++)
          g[p][i][j] =
              (g[p][i][j] + 1ll * g[p - 1][i][k] * g[p - 1][k][j]) % mod;
  }
  val[0] = 1;
  for (int k = 30; k >= 0; k--)
    if (T & (1 << k)) {
      for (int i = 0; i <= cnt; i++) pre[i] = val[i], val[i] = 0;
      for (int i = 0; i <= cnt; i++)
        for (int j = i; j <= cnt; j++)
          val[j] = (val[j] + 1ll * pre[i] * g[k][i][j]) % mod;
    }
  return val[cnt];
}
int main() {
  scanf("%s%d", s + 1, &m), n = strlen(s + 1);
  for (int i = 1; i <= n; i++)
    for (int l = 1, r; (r = l + i - 1) <= n; l++) {
      if (l == r) {
        f[l][r][0][0] = 1;
        continue;
      }
      if (r - l == 1 && s[l] == s[r]) {
        f[l][r][0][1] = 1;
        continue;
      }
      for (int j = 0; j <= r - l + 1; j++)
        for (int k = 0; k < 2; k++)
          if (s[l] == s[r])
            f[l][r][j][k] = f[l + 1][r - 1][j][k];
          else if (j)
            f[l][r][j][k] =
                (f[l][r - 1][j - 1][k] + f[l + 1][r][j - 1][k]) % mod;
    }
  cnt = n << 1 | 1;
  for (int i = 0; i < cnt; i++)
    if (i != n) g[0][i][i + 1] = 1;
  for (int i = 0; i <= n; i++)
    g[0][i][cnt - (n + 1 - i) / 2] =
        (1ll * g[0][i][cnt - (n + 1 - i) / 2] + f[1][n][i][0] + f[1][n][i][1]) %
        mod;
  for (int i = 1; i < cnt; i++) g[0][i][i] = 24 + (i > n);
  g[0][cnt][cnt] = 26;
  int ans = calc_((n + m + 1) >> 1);
  if ((n + m) & 1) {
    g[0][cnt][cnt] = 0;
    for (int i = 0; i <= n; i++) g[0][i][cnt - (n + 1 - i) / 2] = 0;
    for (int i = 0; i <= n; i++)
      g[0][i][cnt - (n + 1 - i) / 2] =
          (g[0][i][cnt - (n + 1 - i) / 2] + f[1][n][i][1]) % mod;
    ans = (ans - calc_((n + m + 1) >> 1)) % mod;
  }
  printf("%d\n", (ans % mod + mod) % mod);
}
