#include <bits/stdc++.h>
using namespace std;
const int inf = ~0u >> 1, mo = 10007;
inline int rd() {
  int x, c, f = 1;
  while (!isdigit(c = getchar())) f = c != '-';
  x = c - '0';
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  return f ? x : -x;
}
const int N = 205;
int n, m, cnt, tot, dp[N][N][N], g[N << 1][N << 1];
char s[N];
struct matrix {
  int p[N << 1][N << 1];
} a, b;
void operator*=(matrix &x, const matrix y) {
  memset(g, 0, sizeof(g));
  for (int i = (1), i_end = (tot); i <= i_end; ++i)
    for (int j = (i), j_end = (tot); j <= j_end; ++j)
      for (int k = (j), k_end = (tot); k <= k_end; ++k)
        g[i][k] = (g[i][k] + x.p[i][j] * y.p[j][k]) % mo;
  swap(x.p, g);
}
void ksm(matrix x, int y) {
  for (int i = (1), i_end = (tot); i <= i_end; ++i)
    for (int j = (1), j_end = (tot); j <= j_end; ++j) b.p[i][j] = (i == j);
  for (; y; y >>= 1, x *= x)
    if (y & 1) b *= x;
}
int main() {
  scanf("%s%d", s + 1, &m);
  n = strlen(s + 1), m += n;
  for (int i = (1), i_end = (n); i <= i_end; ++i) {
    dp[i][i][0] = 1;
    if (i < n && s[i] == s[i + 1]) dp[i][i + 1][0] = 1;
  }
  for (int i = (n - 1), i_st = (1); i >= i_st; --i)
    for (int j = ((s[i] == s[i + 1]) ? i + 2 : i + 1), j_end = (n); j <= j_end;
         ++j)
      if (s[i] == s[j])
        for (int k = (0), k_end = (n); k <= k_end; ++k)
          dp[i][j][k] = dp[i + 1][j - 1][k];
      else
        for (int k = (1), k_end = (n); k <= k_end; ++k)
          dp[i][j][k] = (dp[i][j - 1][k - 1] + dp[i + 1][j][k - 1]) % mo;
  int ans = 0;
  cnt = n + 1 >> 1;
  for (int i = (1), i_end = (n); i < i_end; ++i)
    a.p[i][i] = 24, a.p[i][i + 1] = 1;
  for (int i = (n), i_end = (n + cnt); i < i_end; ++i)
    a.p[i][i] = 25, a.p[i][i + cnt] = a.p[i - 1][i] = 1;
  tot = n + (cnt << 1) - 1;
  for (int i = (n + cnt), i_end = (tot); i <= i_end; ++i) a.p[i][i] = 26;
  ksm(a, m - 1 >> 1), a *= b;
  for (int i = (0), i_end = (n); i < i_end; ++i) {
    int j = n - i - 1 >> 1, k = a.p[n - i][n + cnt + j];
    if ((m & 1) && !(n - i & 1)) k = (k - b.p[n - i][n + j] + mo) % mo;
    ans = (ans + dp[1][n][i] * k) % mo;
  }
  cout << ans << endl;
}
