#include <bits/stdc++.h>
const int N = 405, P = 10007;
int r, f[N][N][N], x[N][N];
char str[N];
void inc(int& a, int b) { a += b - P, a += a >> 31 & P; }
void dec(int& a, int b) { a -= b, a += a >> 31 & P; }
int add(int a, int b) { return inc(a, b), a; }
int mul(int a, int b) { return 1ll * a * b % P; }
struct matrix {
  int a[N][N];
  matrix() { memset(a, 0, sizeof a); }
  int* operator[](int x) { return a[x]; }
} E, I;
matrix mul(matrix a, matrix b) {
  matrix c;
  for (int i = 1; i <= r; ++i)
    for (int j = i; j <= r; ++j)
      for (int k = j; k <= r; ++k) inc(c[i][k], mul(a[i][j], b[j][k]));
  return c;
}
matrix pow(matrix a, int k) {
  matrix b;
  for (int i = 1; i <= r; ++i) b[i][i] = 1;
  for (; k; k >>= 1, a = mul(a, a))
    if (k & 1) b = mul(b, a);
  return b;
}
int main() {
  int n, m, ans = 0, cnt;
  scanf("%s%d", str + 1, &m), m += n = strlen(str + 1), cnt = (n + 1) / 2,
                                   r = n + cnt * 2 - 1;
  for (int i = 1; i <= n; ++i)
    f[i][i][0] = 1, f[i][i + 1][0] = i < n && str[i] == str[i + 1];
  for (int i = n - 1; i; --i)
    for (int j = str[i] == str[i + 1] ? i + 2 : i + 1; j <= n; ++j)
      if (str[i] == str[j])
        for (int k = 0; k <= n; ++k) f[i][j][k] = f[i + 1][j - 1][k];
      else
        for (int k = 1; k <= n; ++k)
          f[i][j][k] = add(f[i][j - 1][k - 1], f[i + 1][j][k - 1]);
  for (int i = 1; i < n; ++i) E[i][i] = 24, E[i][i + 1] = 1;
  for (int i = n; i < n + cnt; ++i)
    E[i][i] = 25, E[i][i + cnt] = 1, E[i - 1][i] = 1;
  for (int i = n + cnt; i <= r; ++i) E[i][i] = 26;
  I = pow(E, (m - 1) / 2), E = mul(E, I);
  for (int i = 0, p, k; i < n; ++i) {
    p = (n - i - 1) / 2, k = E[n - i][n + cnt + p];
    if (m & 1 && ~(n - i) & 1) dec(k, I[n - i][n + p]);
    inc(ans, mul(k, f[1][n][i]));
  }
  printf("%d", ans);
}
