#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, nn, an;
int a[210 * 2][210 * 2], b[210 * 2][210 * 2], f[210][210][210];
char p[210];
inline void mul(int a[210 * 2][210 * 2], int b[210 * 2][210 * 2]) {
  int i, j, k, c[210 * 2][210 * 2] = {};
  for (i = 1; i <= nn; i++)
    for (j = i; j <= nn; j++)
      for (k = j; k <= nn; k++) c[i][k] = (a[i][j] * b[j][k] + c[i][k]) % 10007;
  for (i = 1; i <= nn; i++)
    for (j = i; j <= nn; j++) a[i][j] = c[i][j];
}
inline void S(int &x, int y) { x = (x + y) % 10007; }
inline void pre() {
  int i, j, k, u, x;
  f[1][m][0] = 1;
  for (i = m - 1; i >= 0; i--)
    for (j = 1; j <= m - i; j++)
      for (k = 0; k <= m; k++) {
        u = j + i;
        if ((x = f[j][u][k]) > 0) {
          if (p[j] == p[u])
            S(f[j + 1][u - 1][k], x);
          else
            S(f[j + 1][u][k + 1], x), S(f[j][u - 1][k + 1], x);
        }
      }
}
int main() {
  scanf("%s%d", p + 1, &n);
  m = strlen(p + 1);
  pre();
  n += m;
  int flag = n & 1;
  n /= 2;
  int n24 = m, n25 = (m + 1) / 2, n26 = n25 + 1;
  nn = n24 + n25 + n26;
  for (i = 1; i <= n24 + n25 - 1; i++) a[i][i + 1] = 1;
  for (i = 0; i <= n25; i++) a[n24 + i][nn - i] = 1;
  for (i = 1; i <= n24; i++) a[i][i] = 24;
  for (i = 1; i <= n25; i++) a[n24 + i][n24 + i] = 25;
  for (i = 1; i <= n26; i++) a[n24 + n25 + i][n24 + n25 + i] = 26;
  for (i = 1; i <= nn; i++) b[i][i] = 1;
  for (k = n; k; k /= 2) {
    if (k & 1) mul(b, a);
    mul(a, a);
  }
  for (i = 0; i <= m; i++) {
    int v24 = i, v25 = (m - i + 1) / 2, s = 0;
    for (j = 1; j <= m; j++) S(s, f[j + 1][j - 1][i]), S(s, f[j][j - 1][i]);
    an =
        (s * b[n24 - v24 + 1][nn - v25] % 10007 * (flag ? 26 : 1) + an) % 10007;
    if (flag && (m - v24) % 2 == 1) {
      s = 0;
      for (j = 1; j <= m; j++) S(s, f[j][j][i]);
      an = (s * b[n24 - v24 + 1][n24 + v25] + an) % 10007;
    }
  }
  printf("%d\n", an);
  return 0;
}
