#include <bits/stdc++.h>
using namespace std;
const int MaxN = 410;
const int MOD = 10007;
char s[MaxN];
int n, m, N, cnt, a[MaxN][MaxN], b[MaxN][MaxN], c[MaxN][MaxN];
int f[MaxN][MaxN][MaxN];
inline void mul(int a[][MaxN], int b[][MaxN], int c[][MaxN]) {
  static int d[MaxN][MaxN];
  memset(d, 0, sizeof(d));
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      for (int k = i; k <= j; k++)
        d[i][j] = (d[i][j] + a[i][k] * b[k][j]) % MOD;
  memcpy(c, d, sizeof(d));
}
inline void pow(int x) {
  memset(c, 0, sizeof(c));
  for (int i = 0; i < N; i++) c[i][i] = 1;
  for (; x; x >>= 1, mul(a, a, a))
    if (x & 1) mul(c, a, c);
}
int F(int l, int r, int C) {
  if (f[l][r][C] != -1) return f[l][r][C];
  int &t = f[l][r][C];
  if (l == r)
    return t = !C;
  else if (s[l] == s[r])
    return t = (l + 1 == r ? !C : F(l + 1, r - 1, C));
  else
    return t = C ? F(l, r - 1, C - 1) + F(l + 1, r, C - 1) % MOD : 0;
}
int main() {
  scanf("%s%d", s, &n);
  m = strlen(s);
  n += m;
  cnt = n + 1 >> 1;
  int n1 = m - 1, n2 = m + 1 >> 1, n3 = n2;
  N = n1 + n2 + n3;
  for (int i = 0; i < n1; i++) a[i][i] = 24, a[i][i + 1] = 1;
  for (int i = n1; i < n1 + n2; i++)
    a[i][i] = 25, a[i][i + n2] = 1, i < n1 + n2 - 1 ? a[i][i + 1] = 1 : 0;
  for (int i = n1 + n2; i < N; i++) a[i][i] = 26;
  memcpy(b, a, sizeof(a));
  pow(cnt - 1);
  mul(c, b, a);
  memset(f, 0xff, sizeof(f));
  long long res = 0;
  for (int c1 = 0; c1 < m; c1++) {
    int c2 = m - c1 + 1 >> 1, flag = ~(m - c1) & 1;
    int c3 = cnt - c1 - c2;
    if (c3 < 0) continue;
    int tot = F(0, m - 1, c1);
    res += 1LL * tot * a[n1 - c1][n1 + n2 + c2 - 1];
    if ((n & 1) && flag)
      res += 1LL * MOD * MOD - 1LL * tot * c[n1 - c1][n1 + c2 - 1];
  }
  printf("%d\n", int(res % MOD));
  return 0;
}
