#include <bits/stdc++.h>
using namespace std;
int gi() {
  int res = 0, w = 1;
  char ch = getchar();
  while (ch != '-' && !isdigit(ch)) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar();
  return res * w;
}
const int Mod = 1e4 + 7;
const int LIM = Mod * Mod;
int cnt;
struct Matrix {
  int m[305][305];
  Matrix() { memset(m, 0, sizeof(m)); }
  int *operator[](const int &id) { return m[id]; }
  Matrix operator*(const Matrix &r) const {
    Matrix res;
    for (int i = 0; i <= cnt; i++)
      for (int j = i; j <= cnt; j++)
        for (int k = i; k <= j; k++) {
          res[i][j] += m[i][k] * r.m[k][j];
          if (res[i][j] >= LIM) res[i][j] %= Mod;
        }
    for (int i = 0; i <= cnt; i++)
      for (int j = i; j <= cnt; j++) res[i][j] %= Mod;
    return res;
  }
} F, G;
void mul(int y) {
  while (y) {
    if (y & 1) F = F * G;
    G = G * G;
    y >>= 1;
  }
}
int N, M, col[205][205], h[205][205][205];
int g[205];
char s[205];
int main() {
  scanf("%s %d", s + 1, &M);
  N = strlen(s + 1);
  h[1][N][0] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = N; j >= i; j--)
      if (s[i] == s[j]) {
        for (int k = 0; k < i + N - j; k++) {
          if (i + 1 < j)
            h[i + 1][j - 1][k] = (h[i + 1][j - 1][k] + h[i][j][k]) % Mod;
          else
            g[k] = (g[k] + h[i][j][k]) % Mod;
        }
      } else {
        for (int k = 0; k < i + N - j; k++) {
          h[i][j - 1][k + 1] = (h[i][j - 1][k + 1] + h[i][j][k]) % Mod;
          h[i + 1][j][k + 1] = (h[i + 1][j][k + 1] + h[i][j][k]) % Mod;
        }
      }
  }
  cnt = N + (N + 1) / 2 + 1;
  F[0][1] = 1, F[0][N + 1] = g[0], G[cnt][cnt] = 26;
  for (int i = 1; i <= N; i++) {
    int j = cnt - (N - i + 1) / 2;
    G[i][i] = 24, G[i][j] = g[i];
    if (i != N) G[i][i + 1] = 1;
  }
  for (int i = N + 1; i < cnt; i++) G[i][i + 1] = 1, G[i][i] = 25;
  if ((N + M) & 1) {
    mul((N + M + 1) >> 1);
    int ans = F[0][cnt];
    memset(F.m, 0, sizeof(F.m));
    memset(G.m, 0, sizeof(G.m));
    memset(g, 0, sizeof(g));
    for (int i = 1; i < N; i++)
      if (s[i] == s[i + 1]) {
        for (int k = 0; k <= N; k++) g[k] = (g[k] + h[i][i + 1][k]) % Mod;
      }
    F[0][1] = 1, F[0][N + 1] = g[0];
    for (int i = 1; i <= N; i++) {
      int j = cnt - (N - i + 1) / 2;
      G[i][i] = 24, G[i][j] = g[i];
      if (i != N) G[i][i + 1] = 1;
    }
    for (int i = N + 1; i < cnt; i++) G[i][i + 1] = 1, G[i][i] = 25;
    mul((N + M + 1) >> 1);
    printf("%d\n", (ans - F[0][cnt] + Mod) % Mod);
  } else
    mul((N + M) >> 1), printf("%d\n", F[0][cnt]);
  return 0;
}
