#include <bits/stdc++.h>
using namespace std;
struct Matrix {
  int a[402][402];
};
Matrix ans, d, g, anso, anst;
int mo = 10007;
char s[221];
int i, L, n, N, Ans, tot;
int dp[211][2];
int f[211][211][211];
Matrix operator*(Matrix a, Matrix b) {
  int i, j, k;
  Matrix c;
  for (i = 1; i <= tot; i++)
    for (j = 1; j <= tot; j++) c.a[i][j] = 0;
  for (i = 1; i <= tot; i++)
    for (k = i; k <= tot; k++)
      if (a.a[i][k]) {
        for (j = k; j <= tot; j++)
          c.a[i][j] = (c.a[i][j] + a.a[i][k] * b.a[k][j]) % mo;
      }
  return c;
}
void update(int i, int nl, int nr, int l, int r) {
  if (nl + 1 >= nr) {
    if (N % 2 == 0)
      dp[i][0] = (dp[i][0] + f[i][l][r]) % mo;
    else {
      if (nl + 1 == nr)
        dp[i][0] = (dp[i][0] + f[i][l][r]) % mo;
      else
        dp[i][1] = (dp[i][1] + f[i][l][r]) % mo;
    }
  } else {
    if (s[nl + 1] == s[nr - 1])
      f[i][nl][nr] = (f[i][nl][nr] + f[i][l][r]) % mo;
    else
      f[i + 1][nl][nr] = (f[i + 1][nl][nr] + f[i][l][r]) % mo;
  }
}
void prepare() {
  int i, j, l, r, nl, nr;
  if (s[1] == s[L])
    f[0][0][L + 1] = 1;
  else
    f[1][0][L + 1] = 1;
  for (i = 0; i <= L; i++)
    for (l = 0; l <= L; l++)
      for (r = L + 1; r >= l; r--)
        if (f[i][l][r]) {
          if (l + 1 <= r - 1) {
            if (s[l + 1] == s[r - 1])
              update(i, l + 1, r - 1, l, r);
            else {
              update(i, l + 1, r, l, r);
              update(i, l, r - 1, l, r);
            }
          }
        }
}
void build() {
  int i;
  for (i = 1; i <= L; i++) d.a[i][i] = 24, d.a[i][i + 1] = 1;
  for (i = 1; i <= (L + 1) / 2; i++) {
    tot = L + i;
    if (i != (L + 1) / 2) d.a[tot][tot + 1] = 1;
    d.a[tot][tot] = 25;
    d.a[tot][tot + (L + 1) / 2] = 1;
    d.a[tot + (L + 1) / 2][tot + (L + 1) / 2] = 26;
  }
  tot += (L + 1) / 2;
}
void mi(int x) {
  while (x) {
    if (x % 2 == 1) ans = ans * d;
    x /= 2;
    d = d * d;
  }
}
void work() {
  int i, j;
  for (i = 1; i <= tot; i++) ans.a[i][i] = 1;
  for (i = 1; i <= tot; i++)
    for (j = 1; j <= tot; j++) g.a[i][j] = d.a[i][j];
  if (N % 2 == 1) {
    mi(N / 2);
    for (i = 1; i <= tot; i++)
      for (j = 1; j <= tot; j++) {
        d.a[i][j] = g.a[i][j];
        anso.a[i][j] = ans.a[i][j];
      }
    mi(1);
    for (i = 1; i <= tot; i++)
      for (j = 1; j <= tot; j++) {
        anst.a[i][j] = ans.a[i][j];
        ans.a[i][j] = anso.a[i][j];
        d.a[i][j] = g.a[i][j];
      }
    for (i = 1; i <= (L + 1) / 2; i++) d.a[L + i][L + i + (L + 1) / 2] = 0;
    mi(1);
  } else
    mi(N / 2);
}
void calc() {
  int i, ts, tg;
  for (i = 0; i <= L; i++) {
    dp[i][0] = dp[i][0] % mo;
    dp[i][1] = dp[i][1] % mo;
    ts = i;
    if ((L - ts) % 2 == 1)
      tg = (L + 1 - ts) / 2;
    else
      tg = (L - ts) / 2;
    Ans = (Ans + dp[i][0] * ans.a[L - ts + 1][L + tg + (L + 1) / 2]) % mo;
    Ans = (Ans + dp[i][1] * anst.a[L - ts + 1][L + tg + (L + 1) / 2]) % mo;
  }
}
int main() {
  scanf("%s", s + 1);
  scanf("%d", &n);
  L = strlen(s + 1);
  N = n + L;
  prepare();
  build();
  work();
  calc();
  printf("%d\n", Ans);
}
