#include <bits/stdc++.h>
using namespace std;
const int mod = 10007;
int sz, f[205][205][205];
char s[205];
struct matrix {
  long long a[305][305];
  long long* operator[](int x) { return a[x]; }
  matrix() { memset(a, 0, sizeof(a)); }
  matrix operator*(const matrix& b) {
    matrix c;
    for (int i = 0; i <= sz; i++)
      for (int j = i; j <= sz; j++)
        for (int k = i; k <= j; k++)
          c.a[i][j] = c.a[i][j] + a[i][k] * b.a[k][j];
    for (int i = 0; i <= sz; i++)
      for (int j = 0; j <= sz; j++) c.a[i][j] %= mod;
    return c;
  }
};
matrix ksm(matrix x, int k) {
  matrix ret, tmp = x;
  for (int i = 0; i <= sz; i++) ret[i][i] = 1;
  while (k) {
    if (k & 1) ret = ret * tmp;
    tmp = tmp * tmp;
    k >>= 1;
  }
  return ret;
}
int calc(matrix st, matrix mul, int k) {
  mul = ksm(mul, k);
  st = st * mul;
  return st[0][sz];
}
int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1), m;
  scanf("%d", &m);
  f[1][n][0] = 1;
  for (int len = n; len >= 1; len--)
    for (int l = 1, r = len; r <= n; l++, r++)
      if (s[l] == s[r])
        for (int k = 0; k < n; k++)
          f[l + 1][r - 1][k] = (f[l + 1][r - 1][k] + f[l][r][k]) % mod;
      else
        for (int k = 0; k < n; k++) {
          f[l + 1][r][k + 1] = (f[l + 1][r][k + 1] + f[l][r][k]) % mod;
          f[l][r - 1][k + 1] = (f[l][r - 1][k + 1] + f[l][r][k]) % mod;
        }
  static matrix start, mul;
  sz = n + (n + 1) / 2 + 1;
  start[0][1] = 1;
  for (int i = 1; i <= n; i++)
    start[0][n + 1] =
        (start[0][n + 1] + f[i][i - 1][0] + f[i + 1][i - 1][0]) % mod;
  for (int i = 1; i <= n; i++) {
    mul[i][i] = 24;
    for (int j = 1; j <= n; j++)
      (mul[i][n + 1 + (i + (n & 1)) / 2] +=
       f[j][j - 1][i] + f[j + 1][j - 1][i]) %= mod;
    if (i != n) mul[i][i + 1] = 1;
  }
  for (int i = n + 1; i < sz; i++) mul[i][i] = 25, mul[i][i + 1] = 1;
  mul[sz][sz] = 26;
  int ans = calc(start, mul, (n + m + 1) / 2);
  if ((n + m) & 1) {
    for (int i = 1; i <= n; i++)
      start[0][n + 1] = (start[0][n + 1] - f[i + 1][i - 1][0]) % mod;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        (mul[i][n + 1 + (i + (n & 1)) / 2] -= f[j + 1][j - 1][i]) %= mod;
    mul[sz][sz] = 0;
    ans = (ans - calc(start, mul, (n + m + 1) / 2)) % mod;
  }
  cout << (ans + mod) % mod << "\n";
  return 0;
}
