#include <bits/stdc++.h>
using std::cerr;
using std::endl;
const int N = 305, P = 1e4 + 7;
char str[N];
int n, m, ans;
int id[N][2], num;
struct Matrix {
  int mat[N][N];
  Matrix() { memset(mat, 0, sizeof(mat)); }
  inline int *operator[](int x) { return mat[x]; }
};
inline Matrix operator*(Matrix &a, Matrix &b) {
  Matrix ret;
  for (int i = 1; i <= num; ++i)
    for (int k = i; k <= num; ++k)
      for (int j = k; j <= num; ++j)
        ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]) % P;
  return ret;
}
inline Matrix fpow(Matrix x, int y) {
  Matrix ret = x;
  for (--y; y; y >>= 1, x = x * x)
    if (y & 1) ret = ret * x;
  return ret;
}
int mem[N][N][N], tag[N][N][N], now, ban;
int dfs(int l, int r, int i) {
  if (i < 0) return 0;
  if (r + 2 == l) return !i && !ban;
  if (r + 1 == l) return !i;
  if (tag[l][r][i] == now) return mem[l][r][i];
  int ret = 0;
  if (str[l] == str[r])
    ret = dfs(l + 1, r - 1, i);
  else
    ret = (dfs(l + 1, r, i - 1) + dfs(l, r - 1, i - 1)) % P;
  tag[l][r][i] = now;
  return mem[l][r][i] = ret;
}
Matrix F, G, bF, bG;
int main() {
  scanf("%s %d", str + 1, &n);
  m = strlen(str + 1), n += m;
  now = 1;
  for (int i = 0; i <= m; ++i) dfs(1, m, i);
  for (int i = 1; i <= m; ++i) id[i][0] = ++num;
  for (int i = (m + 1) / 2; ~i; --i) id[i][1] = ++num;
  for (int i = 1; i <= m; ++i) G[id[i][0]][id[i][0]] = 24;
  for (int i = 1; i <= (m + 1) / 2; ++i) G[id[i][1]][id[i][1]] = 25;
  G[id[0][1]][id[0][1]] = 26;
  for (int i = 1; i < m; ++i) G[id[i][0]][id[i + 1][0]] = 1;
  for (int i = (m + 1) / 2; i; --i) G[id[i][1]][id[i - 1][1]] = 1;
  for (int i = 1; i <= m; ++i) {
    int way = mem[1][m][i];
    int j = (m - i + 1) >> 1;
    G[id[i][0]][id[j][1]] = way;
  }
  F[1][id[1][0]] = 1;
  F[1][id[(m + 1) / 2][1]] = mem[1][m][0];
  bF = F, bG = G;
  G = fpow(G, (n + 1) >> 1);
  F = F * G;
  ans = F[1][id[0][1]];
  if (!(n & 1)) {
    std::cout << ans << '\n';
    return 0;
  }
  ban = 1, now = 2;
  for (int i = 0; i <= m; ++i) dfs(1, m, i);
  F = bF, G = bG;
  for (int i = 1; i <= m; ++i) {
    int way = mem[1][m][i];
    int j = (m - i + 1) >> 1;
    G[id[i][0]][id[j][1]] = way;
  }
  G[id[0][1]][id[0][1]] = 0;
  F[1][id[(m + 1) / 2][1]] = mem[1][m][0];
  G = fpow(G, (n + 1) >> 1);
  F = F * G;
  ans = (ans + P - F[1][id[0][1]]) % P;
  std::cout << ans << '\n';
  return 0;
}
