#include <bits/stdc++.h>
using namespace std;
const int maxn = 410, MOD = 10007;
char s[maxn];
int n, m, mat_s;
typedef long long Mat[maxn][maxn];
void print(Mat A) {
  for (int i = 0; i < (mat_s); i++) {
    for (int j = 0; j < (mat_s); j++) {
      cout << A[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}
void mat_mul(Mat A, Mat B, Mat res) {
  static Mat C;
  memset(C, 0, sizeof(C));
  for (int i = 0; i < (mat_s); i++)
    for (int k = (i); k <= (mat_s - 1); k++)
      for (int j = (k); j <= (mat_s - 1); j++) {
        C[i][j] += A[i][k] * B[k][j];
      }
  for (int i = 0; i < (mat_s); i++)
    for (int j = 0; j < (mat_s); j++) {
      C[i][j] %= MOD;
    }
  memcpy(res, C, sizeof(C));
}
void mat_pow(Mat A, long long k, Mat res) {
  static Mat a, r;
  memcpy(a, A, sizeof(a));
  memset(r, 0, sizeof(r));
  for (int i = 0; i < (mat_s); i++) r[i][i] = 1;
  while (k) {
    if (k & 1) {
      mat_mul(r, a, r);
    }
    if (!(k >>= 1)) {
      break;
    }
    mat_mul(a, a, a);
  }
  memcpy(res, r, sizeof(r));
}
int dp[210][210][210];
int rec(int l, int r, int n24) {
  int& res = dp[l][r][n24];
  if (~res) {
    return res;
  }
  if (l == r) {
    return res = !n24;
  }
  if (s[l] == s[r]) {
    if (l + 1 == r) {
      return res = !n24;
    }
    return res = rec(l + 1, r - 1, n24);
  } else {
    if (n24 > 0) {
      return res = (rec(l + 1, r, n24 - 1) + rec(l, r - 1, n24 - 1)) % MOD;
    } else {
      return res = 0;
    }
  }
}
int n24, n25, n26, times;
int mat_at(Mat A, int c24, int c25) {
  int i24 = n24 - c24;
  int i25 = n24 + c25 - 1;
  int i26 = i25 + n25;
  return A[i24][i26];
}
int main() {
  scanf("%s%d", s, &n);
  m = strlen(s);
  n += m;
  times = (n + 1) >> 1;
  n24 = m - 1;
  n26 = n25 = (m + 1) >> 1;
  mat_s = n24 + n25 + n26;
  static Mat A, B;
  for (int i = 0; i < (mat_s); i++) {
    if (i < n24) {
      A[i][i] = 24;
      A[i][i + 1] = 1;
    } else if (i < n24 + n25) {
      A[i][i] = 25;
      if (i + 1 < n24 + n25) {
        A[i][i + 1] = 1;
      }
      A[i][i + n25] = 1;
    } else {
      A[i][i] = 26;
    }
  }
  mat_pow(A, times - 1, B);
  mat_mul(B, A, A);
  int ans = 0;
  memset(dp, -1, sizeof(dp));
  for (int c24 = 0; c24 < (m); c24++) {
    int c25 = (m - c24 + 1) >> 1;
    if (times - c24 - c25 < 0) {
      continue;
    }
    int ways = rec(0, m - 1, c24);
    ans = (ans + ways * mat_at(A, c24, c25)) % MOD;
    if ((n & 1) && (!((m - c24) & 1))) {
      ans = (ans + MOD - ways * B[n24 - c24][n24 + c25 - 1] % MOD) % MOD;
    }
  }
  printf("%d\n", ans);
  return 0;
}
