#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const bool db = false;
string s;
int n, m, n24, n25, n26, len;
int tot;
int a[444][444], c[444][444], aa[444][444];
int res[444][444], res2[444][444];
int dp[222][222][222];
void mul(int a[444][444], int b[444][444]) {
  for (int i = 0; i < tot; ++i) {
    for (int j = 0; j < tot; ++j) {
      long long cur = 0;
      for (int k = 0; k < tot; ++k) {
        cur += a[i][k] * b[k][j];
      }
      res[i][j] = cur % 10007;
    }
  }
  for (int i = 0; i < 444; ++i)
    for (int j = 0; j < 444; ++j) a[i][j] = res[i][j];
}
void go(int a[444][444], long long n) {
  memset(res, 0, sizeof(res));
  for (int i = 0; i < 444; ++i) res2[i][i] = 1;
  while (n > 0) {
    if (n & 1) mul(res2, a);
    mul(a, a);
    n >>= 1;
  }
  for (int i = 0; i < 444; ++i)
    for (int j = 0; j < 444; ++j) a[i][j] = res2[i][j];
}
int foo(int L, int R, int n24) {
  if (dp[L][R][n24] != -1) return dp[L][R][n24];
  int &ret = dp[L][R][n24];
  ret = 0;
  if (L == R) {
    ret = n24 == 0;
    return ret;
  }
  if (s[L] == s[R]) {
    if (L + 1 == R) {
      ret = n24 == 0;
    } else {
      ret = foo(L + 1, R - 1, n24);
    }
    return ret;
  }
  if (n24 > 0) {
    ret = (foo(L + 1, R, n24 - 1) + foo(L, R - 1, n24 - 1)) % 10007;
  }
  return ret;
}
int main() {
  cin >> s >> n;
  len = s.length();
  n += len;
  m = (n + 1) / 2;
  n24 = len - 1;
  n25 = n26 = (len + 1) / 2;
  tot = n25 + n26 + n24;
  for (int i = 0; i < tot; ++i) {
    if (i < n24) {
      a[i][i] = 24;
      a[i][i + 1] = 1;
    } else if (i < n24 + n25) {
      a[i][i] = 25;
      if (i < n24 + n25 - 1) a[i][i + 1] = 1;
      a[i][i + n25] = 1;
    } else {
      a[i][i] = 26;
    }
  }
  for (int i = 0; i < 444; ++i)
    for (int j = 0; j < 444; ++j) aa[i][j] = a[i][j];
  go(a, m - 1);
  for (int i = 0; i < 444; ++i)
    for (int j = 0; j < 444; ++j) c[i][j] = a[i][j];
  mul(a, aa);
  memset(dp, -1, sizeof(dp));
  long long ret = 0;
  for (int nn24 = 0; nn24 < len; ++nn24) {
    int nn25 = (len - nn24 + 1) / 2;
    bool last = (len - nn24) % 2 == 0;
    int nn26 = m - nn24 - nn25;
    if (nn26 < 0) continue;
    ret += foo(0, len - 1, nn24) * a[n24 - nn24][n24 + n25 + nn25 - 1];
    if (n % 2 == 1 && last == true) {
      ret +=
          10007 * 10007 - foo(0, len - 1, nn24) * c[n24 - nn24][n24 + nn25 - 1];
    }
  }
  cout << ret % 10007 << '\n';
  getchar();
  getchar();
  return 0;
}
