#include <bits/stdc++.h>
using namespace std;
struct matrixType {
  int r, c;
  int matrix[310][310];
};
int n, m;
int rc;
char str[205];
int dp[205][205][205];
int roads[205];
matrixType e, qhy;
matrixType c, tmp;
matrixType operator*(matrixType a, matrixType b) {
  int i, j, k;
  c.r = a.r;
  c.c = b.c;
  for (i = 0; i < c.r; i++)
    for (j = i; j < c.c; j++) {
      c.matrix[i][j] = 0;
      for (k = i; k <= j; k++) {
        c.matrix[i][j] += a.matrix[i][k] * b.matrix[k][j];
        if (c.matrix[i][j] > 10007) c.matrix[i][j] %= 10007;
      }
    }
  return c;
}
void standing_by() {
  scanf("%s", str + 1);
  scanf("%d", &n);
  m = strlen(str + 1);
}
void qpow(int y) {
  for (; y; y >>= 1, e = e * e)
    if (y & 1) qhy = qhy * e;
}
void complete() {
  int i, j, k;
  int l, r;
  int ans;
  dp[1][m][0] = 1;
  for (i = 0; i < m; i++)
    for (j = m; j >= 1; j--)
      for (l = 1; l + j - 1 <= m; l++) {
        r = l + j - 1;
        if (str[l] == str[r]) {
          if (j <= 2) {
            roads[i] = (roads[i] + dp[l][r][i]) % 10007;
          } else {
            dp[l + 1][r - 1][i] = (dp[l + 1][r - 1][i] + dp[l][r][i]) % 10007;
          }
        } else {
          dp[l + 1][r][i + 1] = (dp[l + 1][r][i + 1] + dp[l][r][i]) % 10007;
          dp[l][r - 1][i + 1] = (dp[l][r - 1][i + 1] + dp[l][r][i]) % 10007;
        }
      }
  rc = e.r = e.c = m + (m + 1) / 2 + 1;
  for (i = 0; i < m; i++) {
    e.matrix[i][i] = 24;
    if (i < m - 1) e.matrix[i][i + 1] = 1;
    e.matrix[i][rc - (m - i + 1) / 2 - 1] = roads[i];
  }
  e.matrix[0][0] = 0;
  for (i = m; i < rc - 1; i++) {
    e.matrix[i][i] = 25;
    e.matrix[i][i + 1] = 1;
  }
  e.matrix[rc - 1][rc - 1] = 26;
  qhy.r = 1;
  qhy.c = rc;
  qhy.matrix[0][0] = 1;
  if ((n + m) & 1) {
    tmp = e;
    qpow(((n + m + 1) >> 1) + 1);
    ans = qhy.matrix[0][rc - 1];
    e = tmp;
    for (i = 0; i <= m; i++) roads[i] = 0;
    for (i = 1; i < m; i++)
      if (str[i] == str[i + 1])
        for (j = 0; j < m; j++) {
          roads[j] = (roads[j] + dp[i][i + 1][j]) % 10007;
        }
    for (i = 0; i < m; i++) e.matrix[i][rc - (m - i + 1) / 2 - 1] = roads[i];
    e.matrix[rc - 2][rc - 1] = 0;
    for (i = 1; i < rc; i++) qhy.matrix[0][i] = 0;
    qhy.matrix[0][0] = 1;
    qpow((n + m + 1) >> 1);
    ans -= qhy.matrix[0][rc - 2];
    if (ans < 0) ans += 10007;
  } else {
    qpow(((n + m) >> 1) + 1);
    ans = qhy.matrix[0][rc - 1];
  }
  printf("%d\n", ans);
}
int main() {
  standing_by();
  complete();
  return 0;
}
