#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
const int mod = 10007;
char s[225];
int dp[225][225][225], N;
struct Matrix {
  int n, m;
  int a[225 * 2][225 * 2];
  Matrix() {}
  Matrix(int n, int m) : n(n), m(m) {}
  void init(int num) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) a[i][j] = num;
  }
  Matrix operator*(Matrix b) {
    Matrix o = Matrix(n, b.m);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < b.m; j++) {
        o.a[i][j] = 0;
        for (int k = i; k <= j; k++) {
          o.a[i][j] = (o.a[i][j] + (a[i][k] * b.a[k][j]) % mod) % mod;
        }
      }
    }
    return o;
  }
  Matrix pow(long long p) {
    Matrix o = Matrix(n, m);
    Matrix b = *this;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) o.a[i][j] = (i == j);
    while (p > 0) {
      if (p & 1) o = o * b;
      b = b * b;
      p >>= 1;
    }
    return o;
  }
};
int dfs(int l, int r, int n24) {
  if (dp[l][r][n24] != -1) return dp[l][r][n24];
  int ans = 0;
  if (l == r) {
    ans = n24 == 0;
  } else {
    if (s[l] == s[r]) {
      if (l + 1 == r) {
        ans = n24 == 0;
      } else
        ans = dfs(l + 1, r - 1, n24);
    } else {
      if (n24 > 0) ans = dfs(l + 1, r, n24 - 1) + dfs(l, r - 1, n24 - 1);
    }
  }
  return dp[l][r][n24] = ans % mod;
}
int main() {
  scanf("%s%d", s, &n);
  int l = strlen(s);
  n += l;
  N = (n + 1) / 2;
  int X = l - 1, Y = (l + 1) / 2, Z = Y;
  int S = X + Y + Z;
  Matrix a = Matrix(S, S);
  a.init(0);
  for (int(i) = 0; (i) < (int)(S); (i)++) {
    if (i < X) {
      a.a[i][i] = 24;
      a.a[i][i + 1] = 1;
    } else if (i < X + Y) {
      a.a[i][i] = 25;
      if (i < X + Y - 1) a.a[i][i + 1] = 1;
      a.a[i][X + Y + i - X] = 1;
    } else
      a.a[i][i] = 26;
  }
  Matrix b = a.pow(N - 1);
  Matrix c = b * a;
  memset(dp, -1, sizeof dp);
  int ans = 0;
  for (int(n24) = 0; (n24) < (int)(l); (n24)++) {
    int n25 = (l + 1 - n24) / 2;
    if (N - n24 - n25 < 0) continue;
    int ways = dfs(0, l - 1, n24);
    ans += ways * c.a[X - n24][X + Y + n25 - 1] % mod;
    ans %= mod;
    if (n & 1 && (l - n24) % 2 == 0) {
      int tmp = b.a[X - n24][X + n25 - 1] * ways % mod;
      ans += mod - tmp;
      ans %= mod;
    }
  }
  printf("%d\n", ans);
  return 0;
}
