#include <bits/stdc++.h>
const int MOD = 10007;
const int M = 400 + 7;
int n, m;
char s[M];
void mul(int a[M][M], int b[M][M], int n) {
  static int c[M][M];
  for (int i = 0; i <= n; ++i)
    for (int k = i; k <= n; ++k)
      for (int j = k; j <= n; ++j) (c[i][j] += a[i][k] * b[k][j]) %= MOD;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= n; ++j) a[i][j] = c[i][j], c[i][j] = 0;
}
int work(int type) {
  static int cnt[M][M][M], e[M][M], t[M][M];
  if (type)
    memset(cnt, 0, sizeof cnt), memset(e, 0, sizeof e), memset(t, 0, sizeof t);
  cnt[0][1][m] = 1;
  for (int i = 0; i <= m; ++i) {
    for (int j = 1; j <= m; ++j)
      for (int k = j; k <= m; ++k)
        if (s[j] == s[k]) {
          if (type && j == k) continue;
          (cnt[i][j + 1][k - 1] += cnt[i][j][k]) %= MOD;
        } else {
          (cnt[i + 1][j + 1][k] += cnt[i][j][k]) %= MOD,
              (cnt[i + 1][j][k - 1] += cnt[i][j][k]) %= MOD;
        }
    for (int j = 1; j <= m + 1; ++j)
      for (int k = 0; k < j; ++k) (cnt[i][0][0] += cnt[i][j][k]) %= MOD;
  }
  int p = m - (m + 1) / 2, q = m * 2 + 1 - p;
  for (int i = 1; i <= q; ++i) e[i][i] = 24 + (i > m);
  ++e[q][q];
  if (type) e[q][q] = 0;
  for (int i = 0; i <= q - 1; ++i) e[i][i + 1] = 1;
  e[m][m + 1] = 0;
  for (int i = 0; i <= m; ++i)
    e[i][2 * m - (m - i + 1) / 2 + 1 - p] = cnt[i][0][0];
  for (int i = 0; i <= q; ++i) t[i][i] = 1;
  for (int k = (n + m + 1) / 2 + 1; k; mul(e, e, q), k >>= 1)
    if (k & 1) mul(t, e, q);
  return t[0][q];
}
int main() {
  scanf("%s\n%d", s + 1, &n), m = strlen(s + 1);
  int ans = work(0);
  if (n + m & 1) ans -= work(1);
  printf("%d", (ans + MOD) % MOD);
  return 0;
}
