#include <bits/stdc++.h>
using namespace std;
const int N = 3e2 + 10;
const int Mo = 10007;
char s[N];
int a[N], n, m, len, Ans;
int f[N][N][N], w[N], c[N][N], C[N][N], g[N], g_[N];
void Doit(int fu) {
  int step = (n + m + 1 >> 1) + 1;
  memset(g, 0, sizeof g), g[0] = 1;
  for (int x = step; x; x >>= 1) {
    if (x & 1) {
      memset(g_, 0, sizeof g_);
      for (int x = 0; x <= len; x++)
        for (int y = x; y <= len; y++)
          ((g_[y]) = (g_[y] + g[x] * c[x][y]) % Mo);
      memcpy(g, g_, sizeof g);
    }
    memset(C, 0, sizeof C);
    for (int x = 0; x <= len; x++)
      for (int y = x; y <= len; y++)
        for (int z = y; z <= len; z++)
          ((C[x][z]) = (C[x][z] + 1ll * c[x][y] * c[y][z]) % Mo);
    memcpy(c, C, sizeof c);
  }
  ((Ans) = (Ans + fu * g[len]) % Mo);
}
int main() {
  scanf("%s", s + 1), m = strlen(s + 1);
  for (int i = 1; i <= m; i++) a[i] = s[i] - 'a' + 1;
  scanf("%d", &n);
  f[0][m + 1][0] = 1;
  for (int l = m + 2; l >= 3; l--)
    for (int i = 0; i <= m - l + 2; i++) {
      int j = i + l - 1;
      for (int k = 0; k <= m; k++)
        if (f[i][j][k]) {
          if (a[i + 1] == a[j - 1])
            ((f[i + 1][j - 1][k]) = (f[i + 1][j - 1][k] + f[i][j][k]) % Mo);
          else {
            ((f[i + 1][j][k + 1]) = (f[i + 1][j][k + 1] + f[i][j][k]) % Mo);
            ((f[i][j - 1][k + 1]) = (f[i][j - 1][k + 1] + f[i][j][k]) % Mo);
          }
        }
    }
  for (int k = 0; k <= m; k++)
    for (int i = 0; i <= m; i++)
      ((w[k]) = (w[k] + f[i][i][k] + f[i][i + 1][k]) % Mo);
  int L = m + 1 >> 1;
  len = m + L;
  c[0][1] = 1, c[0][m] = w[0];
  for (int i = 1; i <= m - 1; i++) {
    c[i][i + 1] = i < (m - 1), c[i][i] = 24;
    c[i][len - (m - i + 1 >> 1)] = w[i];
  }
  for (int i = m; i <= len - 1; i++) {
    c[i][i] = 25;
    c[i][i + 1] = 1;
  }
  c[len][len] = 26;
  Doit(1);
  if (n + m & 1) {
    memset(w, 0, sizeof w);
    for (int k = 0; k <= m; k++)
      for (int i = 0; i <= m; i++)
        if (a[i] == a[i + 1]) ((w[k]) = (w[k] + f[i][i + 1][k]) % Mo);
    memset(c, 0, sizeof c), c[0][1] = 1;
    c[0][m] = w[0];
    for (int i = 1; i <= m - 1; i++) {
      c[i][i + 1] = i < (m - 1), c[i][i] = 24;
      c[i][len - (m - i + 1 >> 1)] = w[i];
    }
    for (int i = m; i <= len - 1; i++) {
      c[i][i] = 25;
      c[i][i + 1] = 1;
    }
    c[len][len] = 0;
    Doit(-1);
  }
  printf("%d\n", (Ans + Mo) % Mo);
}
