#include <bits/stdc++.h>
using namespace std;
int f[210][210][210], cnt;
char s[210];
inline void upd(int &a, int b) { a = (a + b) % 10007; }
int d[410][410], ret[410][410], tmp[410][410];
int main() {
  register int i, j, k, l;
  int n, m, ans = 0, dis;
  scanf("%s%d", s + 1, &n), m = strlen(s + 1), n += m;
  for (i = 1; i <= m; ++i) f[i][i][0] = 1;
  for (i = 1; i < m; ++i)
    if (s[i] != s[i + 1])
      f[i][i + 1][1] = 2;
    else
      f[i][i + 1][0] = 1;
  for (i = 3; i <= m; ++i)
    for (j = 1, k = i; k <= m; ++j, ++k)
      for (l = 0; l <= m; ++l)
        if (s[j] == s[k])
          upd(f[j][k][l], f[j + 1][k - 1][l]);
        else
          upd(f[j][k][l + 1], f[j + 1][k][l]),
              upd(f[j][k][l + 1], f[j][k - 1][l]);
  dis = (m + 1) / 2, cnt = m - 1 + dis + dis;
  for (i = 1; i < m; ++i) d[i][i] = 24, d[i][i + 1] = 1;
  for (i = m; i < m + dis; ++i)
    d[i + dis][i + dis] = 26, d[i][i] = 25, d[i][i + dis] = 1;
  for (i = m; i < m + dis - 1; ++i) d[i][i + 1] = 1;
  for (i = 1; i <= cnt; ++i) ret[i][i] = 1;
  for (l = n / 2; l; l >>= 1) {
    if (l & 1) {
      memset(tmp, 0, sizeof(tmp));
      for (i = 1; i <= cnt; ++i)
        for (k = i; k <= cnt; ++k)
          if (ret[i][k])
            for (j = k; j <= cnt; ++j)
              if (d[k][j]) upd(tmp[i][j], ret[i][k] * d[k][j] % 10007);
      for (i = 1; i <= cnt; ++i)
        for (k = i; k <= cnt; ++k) ret[i][k] = tmp[i][k];
    }
    memset(tmp, 0, sizeof(tmp));
    for (i = 1; i <= cnt; ++i)
      for (k = i; k <= cnt; ++k)
        if (d[i][k])
          for (j = k; j <= cnt; ++j)
            if (d[k][j]) upd(tmp[i][j], d[i][k] * d[k][j] % 10007);
    for (i = 1; i <= cnt; ++i)
      for (k = i; k <= cnt; ++k) d[i][k] = tmp[i][k];
  }
  for (i = 0; i < m; ++i)
    j = (m - i + 1) / 2,
    upd(ans, f[1][m][i] * ret[m - i][m + j - 1 + dis] % 10007);
  if (n & 1)
    for (ans = ans * 26 % 10007, i = 0; i < m; ++i)
      if ((m - i) & 1)
        j = (m - i + 1) / 2,
        upd(ans, f[1][m][i] * ret[m - i][m + j - 1] % 10007);
  printf("%d\n", ans);
}
