#include <bits/stdc++.h>
using namespace std;
const int sj = 205;
const int zzh = 10007;
int dp[sj][sj][sj], tp, d, m, hf, n, bz, ans;
char s[sj];
struct matrix {
  int a[405][405];
  inline void clear() { memset(a, 0, sizeof(a)); }
  friend matrix operator*(matrix x, matrix y) {
    matrix ret;
    ret.clear();
    for (register int i = 1; i <= d; i++)
      for (register int j = i; j <= d; j++)
        for (register int k = i; k <= j; k++)
          ret.a[i][j] = (ret.a[i][j] + x.a[i][k] * y.a[k][j]) % zzh;
    return ret;
  }
} nt, res, qwq;
void build() {
  hf = (m + 1) / 2, d = hf * 2 + m - 1;
  for (int i = 1; i < m - 1 + hf; i++) nt.a[i][i + 1] = 1;
  for (int i = m; i <= m - 1 + hf; i++) nt.a[i][i + hf] = 1;
  for (int i = 1; i < m; i++) nt.a[i][i] = 24;
  for (int i = m; i <= m - 1 + hf; i++) nt.a[i][i] = 25;
  for (int i = m + hf; i <= d; i++) nt.a[i][i] = 26;
}
int dfs(int l, int r, int k) {
  if (k < 0) return 0;
  if (l == r || l == r + 1) {
    if (k == 0)
      return dp[l][r][k] = 1;
    else
      return dp[l][r][k] = 0;
  }
  if (dp[l][r][k] != -1) return dp[l][r][k];
  if (s[l] == s[r])
    dp[l][r][k] = dfs(l + 1, r - 1, k);
  else
    dp[l][r][k] = dfs(l + 1, r, k - 1) + dfs(l, r - 1, k - 1);
  if (dp[l][r][k] >= zzh) dp[l][r][k] -= zzh;
  return dp[l][r][k];
}
int main() {
  scanf("%s%d", s + 1, &n);
  m = strlen(s + 1), n += m;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < m; i++) dfs(1, m, i);
  for (int i = 1; i <= m; i++) build();
  bz = n / 2;
  for (int i = 1; i <= d; i++) qwq.a[i][i] = 1;
  while (bz) {
    if (bz & 1) qwq = qwq * nt;
    nt = nt * nt, bz >>= 1;
  }
  for (int i = 0; i < m; i++) {
    bz = (m - i + 1) / 2;
    ans = (ans + dp[1][m][i] * qwq.a[m - i][m + hf + bz - 1]) % zzh;
  }
  if (n & 1) {
    ans = ans * 26 % zzh;
    for (int i = 0; i < m; i++) {
      if (!((m - i) & 1)) continue;
      bz = (m - i + 1) / 2;
      ans = (ans + dp[1][m][i] * qwq.a[m - i][m + bz - 1]) % zzh;
    }
  }
  printf("%d", ans);
  return 0;
}
