#include <bits/stdc++.h>
using namespace std;
const int mod = 1e4 + 7;
const unsigned int inf = 4e9;
int n, m, t;
char str[205];
int f[205][205][205], g[205];
int h[305][305], r[305][305];
inline void mul(int a[][305], int b[][305], int c[][305]) {
  static int r[305][305];
  for (int i = 0; i <= t; ++i)
    for (int j = i; j <= t; ++j) {
      unsigned int f = 0;
      for (int k = i; k <= j; ++k) {
        f += a[i][k] * b[k][j];
        if (f > inf) f %= mod;
      }
      r[i][j] = f % mod;
    }
  for (int i = 0; i <= t; ++i)
    for (int j = i; j <= t; ++j) c[i][j] = r[i][j];
}
int main() {
  scanf("%s%d", str + 1, &n);
  m = strlen(str + 1);
  f[1][m][0] = 1;
  for (int i = m; i; --i) {
    for (int l = 1, r = i; r <= m; ++l, ++r) {
      if (l == r)
        for (int j = 0; j < m; ++j) (f[l][l - 1][j] += f[l][r][j]) %= mod;
      else if (str[l] == str[r])
        for (int j = 0; j < m; ++j) (f[l + 1][r - 1][j] += f[l][r][j]) %= mod;
      else
        for (int j = 0; j < m; ++j)
          (f[l + 1][r][j + 1] += f[l][r][j]) %= mod,
              (f[l][r - 1][j + 1] += f[l][r][j]) %= mod;
    }
  }
  for (int i = 1; i <= m; ++i)
    for (int j = 0; j < m; ++j) (g[j] += f[i][i - 1][j]) %= mod;
  int A = m - 1, B = m + 1 >> 1, ans;
  t = A + B + 1;
  h[t][t] = 26;
  h[0][A + 1] = g[0];
  r[0][0] = 1;
  for (int i = 1; i <= A; ++i) h[i - 1][i] = 1;
  for (int i = 1; i <= A; ++i) h[i][i] = 24;
  for (int i = A + 1; i < t; ++i) h[i][i] = 25;
  for (int i = A + 2; i <= t; ++i) h[i - 1][i] = 1;
  for (int i = 1; i <= A; ++i) h[i][t - (m - i + 1) / 2] = g[i];
  for (int k = (n + m + 1 >> 1) + 1; k; k >>= 1, mul(h, h, h))
    if (k & 1) mul(r, h, r);
  ans = r[0][t];
  if (n + m & 1) {
    memset(g, 0, sizeof(g));
    memset(h, 0, sizeof(h));
    memset(r, 0, sizeof(r));
    for (int i = 1; i < m; ++i)
      if (str[i] == str[i + 1])
        for (int j = 0; j < m; ++j) (g[j] += f[i][i + 1][j]) %= mod;
    if (!(m & 1)) h[0][t - (m - 2) / 2] = g[0];
    h[t][t] = 25;
    r[0][0] = 1;
    for (int i = 1; i <= A; ++i) h[i - 1][i] = 1;
    for (int i = 1; i <= A; ++i) h[i][i] = 24;
    for (int i = A + 1; i < t; ++i) h[i][i] = 25;
    for (int i = A + 2; i <= t; ++i) h[i - 1][i] = 1;
    for (int i = 1; i <= A; ++i)
      if (!(m - i & 1)) h[i][t - (m - 2 - i) / 2] = g[i];
    for (int k = (n + m >> 1) + 1; k; k >>= 1, mul(h, h, h))
      if (k & 1) mul(r, h, r);
    ans = (ans - r[0][t] + mod) % mod;
  }
  return printf("%d\n", ans), 0;
}
