#include <bits/stdc++.h>
using namespace std;
const int kMod = 10007;
char buf[222];
int m, n, l;
int dp[222][222][222];
int f[222];
int s;
struct Matrix {
  int v[444][444];
  void clear() { memset(v, 0, sizeof(v)); }
} I, A, F;
Matrix operator*(const Matrix &a, const Matrix &b) {
  Matrix c;
  c.clear();
  for (int i = 0; i < s; ++i)
    for (int k = 0; k <= i; ++k)
      if (a.v[i][k])
        for (int j = 0; j <= k; ++j)
          if (b.v[k][j]) c.v[i][j] = (c.v[i][j] + a.v[i][k] * b.v[k][j]) % kMod;
  return c;
}
Matrix powMod(const Matrix &a, int b) {
  Matrix res = I, tmp = a;
  while (b) {
    if (b & 1) res = res * tmp;
    b >>= 1;
    tmp = tmp * tmp;
  }
  return res;
}
int main() {
  scanf("%s", buf + 1);
  m = strlen(buf + 1);
  scanf("%d", &n);
  l = m + n;
  if (buf[1] != buf[m]) {
    dp[0][0][1] = 1;
  } else {
    dp[0][0][0] = 1;
  }
  for (int l = 0; l < m; ++l) {
    for (int r = 0; r < m - l; ++r) {
      for (int k = 0; k < 222; ++k)
        if (dp[l][r][k]) {
          if (buf[l + 1] != buf[m - r]) {
            int i, j;
            i = l + 1, j = r;
            if (buf[i + 1] != buf[m - j]) {
              dp[i][j][k + 1] += dp[l][r][k];
              dp[i][j][k + 1] %= kMod;
            } else {
              dp[i][j][k] += dp[l][r][k];
              dp[i][j][k] %= kMod;
            }
            i = l, j = r + 1;
            if (buf[i + 1] != buf[m - j]) {
              dp[i][j][k + 1] += dp[l][r][k];
              dp[i][j][k + 1] %= kMod;
            } else {
              dp[i][j][k] += dp[l][r][k];
              dp[i][j][k] %= kMod;
            }
          } else {
            int i, j;
            i = l + 1, j = r + 1;
            if (i + j >= m) {
              f[k] += dp[l][r][k];
              f[k] %= kMod;
            } else {
              if (buf[i + 1] != buf[m - j]) {
                dp[i][j][k + 1] += dp[l][r][k];
                dp[i][j][k + 1] %= kMod;
              } else {
                dp[i][j][k] += dp[l][r][k];
                dp[i][j][k] %= kMod;
              }
            }
          }
        }
    }
  }
  s = (m - 1) + ((m - 1) / 2 + 1) * 2;
  for (int i = 0; i < s; ++i) I.v[i][i] = 1;
  for (int i = 0; i < m - 1; ++i) {
    A.v[i + 1][i]++;
    A.v[i][i] += 24;
  }
  for (int i = m - 1; i < (m - 1) + ((m - 1) / 2 + 1); ++i) {
    if (i + 1 < (m - 1) + ((m - 1) / 2) + 1) A.v[i + 1][i]++;
    A.v[i][i] += 25;
    A.v[(m - 1) + ((m - 1) / 2 + 1) + (i - (m - 1))][i]++;
  }
  for (int i = (m - 1) + ((m - 1) / 2 + 1); i < s; ++i) {
    A.v[i][i] += 26;
  }
  for (int i = 0; i < m; ++i) {
    F.v[i][i] = 1;
  }
  F = powMod(A, (l - 1) / 2 + 1) * F;
  int ans = 0;
  for (int k = 0; k < 222; ++k)
    if (f[k]) {
      int n24 = k, n25 = (m - k - 1) / 2 + 1;
      int from = (m - 1) - k;
      int to = (m - 1) + ((m - 1) / 2 + 1) + n25 - 1;
      ans = (ans + F.v[to][from] * f[k]) % kMod;
    }
  if (l & 1) {
    F.clear();
    for (int i = 0; i < m; ++i) {
      F.v[i][i] = 1;
    }
    F = powMod(A, (l - 1) / 2) * F;
    for (int k = 0; k < 222; ++k)
      if (f[k]) {
        int n24 = k, n25 = (m - k - 1) / 2 + 1;
        if ((m - n24) % 2 == 0) {
          int from = (m - 1) - k;
          int to = (m - 1) + n25 - 1;
          ans -= F.v[to][from] * f[k] % kMod;
          if (ans < 0) ans += kMod;
        }
      }
  }
  printf("%d\n", ans);
  return 0;
}
