#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
char ch[205];
int n, m, f[205][205][205], g[205], MAXN;
struct Martix {
  int a[205 << 1][205 << 1];
} A, B;
Martix operator*(Martix a, Martix b) {
  Martix c;
  memset(c.a, 0, sizeof(c));
  for (int i = 0; i <= MAXN; i++) {
    for (int j = i; j <= MAXN; j++) {
      for (int k = i; k <= j; k++) {
        c.a[i][j] += a.a[i][k] * b.a[k][j];
        c.a[i][j] %= 10007;
      }
    }
  }
  return c;
}
void ksm(int b) {
  while (b) {
    if (b & 1) A = A * B;
    B = B * B;
    b >>= 1;
  }
}
int main() {
  scanf("%s", ch);
  m = read();
  n = strlen(ch);
  f[0][n - 1][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j >= i; j--) {
      if (ch[i] == ch[j]) {
        for (int k = 0; k < i + n - j; k++) {
          if (i + 1 < j)
            f[i + 1][j - 1][k] += f[i][j][k], f[i + 1][j - 1][k] %= 10007;
          else
            g[k] += f[i][j][k], g[k] %= 10007;
        }
      } else {
        for (int k = 0; k < i + n - j; k++) {
          f[i + 1][j][k + 1] += f[i][j][k], f[i + 1][j][k + 1] %= 10007;
          f[i][j - 1][k + 1] += f[i][j][k], f[i][j - 1][k + 1] %= 10007;
        }
      }
    }
  }
  MAXN = n + (n + 1) / 2 + 1;
  A.a[0][1] = 1;
  A.a[0][n + 1] = g[0];
  B.a[MAXN][MAXN] = 26;
  for (int i = 1; i <= n; i++)
    B.a[i][i] = 24, B.a[i][i + 1] = 1, B.a[i][MAXN - (n - i + 1) / 2] = g[i];
  B.a[n][n + 1] = 0;
  for (int i = n + 1; i < MAXN; i++) B.a[i][i + 1] = 1, B.a[i][i] = 25;
  if ((n + m) % 2 == 1) {
    ksm((n + m + 1) / 2);
    int ans = A.a[0][MAXN];
    memset(A.a, 0, sizeof(A.a));
    memset(B.a, 0, sizeof(B.a));
    memset(g, 0, sizeof(g));
    for (int i = 0; i < n - 1; i++) {
      if (ch[i] == ch[i + 1]) {
        for (int j = 0; j <= n; j++) {
          g[j] += f[i][i + 1][j];
          g[j] %= 10007;
        }
      }
    }
    A.a[0][1] = 1;
    A.a[0][n + 1] = g[0];
    for (int i = 1; i <= n; i++)
      B.a[i][i] = 24, B.a[i][i + 1] = 1, B.a[i][MAXN - (n - i + 1) / 2] = g[i];
    B.a[n][n + 1] = 0;
    for (int i = n + 1; i < MAXN; i++) B.a[i][i + 1] = 1, B.a[i][i] = 25;
    ksm((n + m + 1) / 2);
    printf("%d\n", (ans - A.a[0][MAXN] + 10007) % 10007);
  } else {
    ksm((n + m) / 2);
    printf("%d\n", A.a[0][MAXN]);
  }
  return 0;
}
