#include <bits/stdc++.h>
using namespace std;
const int mod = 1e4 + 7;
struct Matrix {
  int w, h;
  int mat[305][305];
  Matrix(int W = 0, int H = 0) {
    for (int i = 1; i <= W; ++i)
      for (int j = 1; j <= H; ++j) mat[i][j] = 0;
    w = W;
    h = H;
    return;
  }
  Matrix operator*(Matrix y) {
    Matrix res(w, y.h);
    for (int i = 1; i <= w; ++i)
      for (int j = i; j <= y.h; ++j)
        for (int k = i; k <= j; ++k)
          (res.mat[i][j] += mat[i][k] * y.mat[k][j]) %= mod;
    return res;
  }
  Matrix operator^(int y) {
    Matrix x = *this, res(w, h);
    for (int i = 1; i <= w; ++i) res.mat[i][i] = 1;
    for (; y; y >>= 1, x = x * x)
      if (y & 1) res = res * x;
    return res;
  }
};
char s[305];
int n, m, lim;
int h[305][305][305], f[305];
int H(int, int, int);
int main() {
  scanf("%s%d", s + 1, &n);
  m = strlen(s + 1);
  n += m;
  lim = m + (m + 1) / 2 + 1;
  memset(h, -1, sizeof h);
  for (int i = 0; i <= m; ++i) h[i][1][m] = 0;
  h[s[1] != s[m]][1][m] = 1;
  for (int i = 1; i <= m; ++i)
    for (int j = 0; j <= m; ++j) {
      (f[j] += H(j, i, i)) %= mod;
      if (s[i] == s[i + 1]) (f[j] += H(j, i, i + 1)) %= mod;
    }
  Matrix A(lim, lim);
  for (int i = 2; i <= m; ++i) A.mat[i][i] = 24, A.mat[i - 1][i] = 1;
  for (int i = m + 1; i <= m + (m + 1) / 2; ++i) {
    if (i != m + 1) A.mat[i - 1][i] = 1;
    A.mat[i][i] = 25;
    int tmp = ((m + 1) / 2 - (i - m) + 1) * 2;
    int pos1 = m - tmp, pos2 = m - tmp + 1;
    A.mat[pos1 + 1][i] = f[pos1];
    A.mat[pos2 + 1][i] = f[pos2];
  }
  A.mat[lim - 1][lim] = 1;
  A.mat[lim][lim] = 26;
  A = A ^ ((n + 1) / 2 + 1);
  int res = A.mat[1][lim];
  if (n & 1) {
    A = Matrix(lim, lim);
    memset(f, 0, sizeof f);
    for (int i = 1; i <= m; ++i)
      for (int j = 0; j <= m; ++j)
        if (s[i] == s[i + 1]) (f[j] += H(j, i, i + 1)) %= mod;
    for (int i = 2; i <= m; ++i) A.mat[i][i] = 24, A.mat[i - 1][i] = 1;
    for (int i = m + 1; i <= m + (m + 1) / 2; ++i) {
      if (i != m + 1) A.mat[i - 1][i] = 1;
      A.mat[i][i] = 25;
      int tmp = ((m + 1) / 2 - (i - m) + 1) * 2;
      int pos1 = m - tmp, pos2 = m - tmp + 1;
      A.mat[pos1 + 1][i] = f[pos1];
      A.mat[pos2 + 1][i] = f[pos2];
    }
    A.mat[lim - 1][lim] = 1;
    A = A ^ ((n + 1) / 2 + 1);
    res = (res - A.mat[1][lim] + mod) % mod;
  }
  cout << res << endl;
  return 0;
}
int H(int num, int l, int r) {
  if (!l || r > m || num < 0) return 0;
  if (h[num][l][r] != -1) return h[num][l][r];
  h[num][l][r] = 0;
  int pre = num - (s[l] != s[r]);
  if (s[l - 1] != s[r]) h[num][l][r] += H(pre, l - 1, r);
  if (s[l] != s[r + 1]) h[num][l][r] += H(pre, l, r + 1);
  if (s[l - 1] == s[r + 1]) h[num][l][r] += H(pre, l - 1, r + 1);
  h[num][l][r] %= mod;
  return h[num][l][r];
}
