#include <bits/stdc++.h>
using namespace std;
const int mod = 1e4 + 7;
int add(int x, int y) { return x + y < mod ? x + y : x + y - mod; }
void ade(int& x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int n, m;
char s[220];
int id[220][220], tot;
struct data {
  int to, nxt;
} mp[200200];
int head[50500], cnt;
void link(int x, int y) {
  mp[++cnt].to = y;
  mp[cnt].nxt = head[x];
  head[x] = cnt;
}
int b24[50500];
int dp[50500][220];
bool book[50500][220];
int dfs(int x, int c) {
  if (c < 0) return 0;
  if (book[x][c]) return dp[x][c];
  book[x][c] = 1;
  for (int i = head[x]; i; i = mp[i].nxt)
    dp[x][c] = add(dp[x][c], dfs(mp[i].to, c - b24[x]));
  return dp[x][c];
}
int ng;
int tp;
struct Mat {
  int d[440][440];
  void clear() {
    for (int i = 1; i <= tp; ++i) memset(d[i], 0, sizeof(d[i]));
  }
  Mat operator*(const Mat& o) const {
    Mat res;
    res.clear();
    for (int i = 1; i <= tp; ++i)
      for (int k = 1; k <= tp; ++k) {
        if (!d[i][k]) continue;
        for (int j = 1; j <= tp; ++j)
          ade(res.d[i][j], d[i][k] * o.d[k][j] % mod);
      }
    return res;
  }
} mat;
Mat qpow(int k) {
  Mat res;
  res.clear();
  for (int i = 1; i <= tp; ++i) res.d[i][i] = 1;
  while (k) {
    if (k & 1) res = res * mat;
    k >>= 1;
    mat = mat * mat;
  }
  return res;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  scanf("%d", &m);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) id[i][j] = ++tot;
  tot++;
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; ++j) {
      if (s[i] == s[j] && j - i <= 1)
        link(tot, id[i][j]);
      else if (s[i] == s[j] && j - i > 1)
        link(id[i + 1][j - 1], id[i][j]);
      else {
        link(id[i + 1][j], id[i][j]);
        link(id[i][j - 1], id[i][j]);
        b24[id[i][j]] = 1;
      }
    }
  for (int i = 0; i < n; ++i) book[id[1][n]][i] = 1;
  dp[id[1][n]][b24[id[1][n]]] = 1;
  for (int i = 0; i < n; ++i) dfs(tot, i);
  ng = (n + 1) / 2;
  tp = n - 1 + ng + ng;
  for (int i = 1; i < n; ++i) mat.d[i][i] += 24;
  for (int i = n - 1 + 1; i <= n - 1 + ng; ++i)
    mat.d[i][i] += 25, mat.d[i][i + ng]++, mat.d[i + ng][i + ng] += 26;
  for (int i = 1; i < n - 1 + ng; ++i) mat.d[i][i + 1]++;
  int S = (n + m) / 2;
  mat = qpow(S);
  int ans = 0;
  for (int i = 0, j; i < n; ++i) {
    j = (n - i + 1) / 2;
    ans = add(ans, mat.d[n - i][n + j - 1 + ng] * dp[tot][i] % mod);
  }
  if ((n + m) & 1) {
    (ans *= 26) %= mod;
    for (int p = 1; p <= n; ++p)
      for (int i = 0, j; i < n; ++i) {
        j = (n - i + 1) / 2;
        ans = add(ans, mat.d[n - i][n + j - 1] * dp[id[p][p]][i] % mod);
      }
  }
  printf("%d\n", ans);
  return 0;
}
