Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly n lowercase English letters into s to make it a palindrome. (A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.) You can choose any n lowercase English letters, and insert each of them to any position of s, possibly to the beginning or the end of s. You have to insert exactly n letters even if it is possible to turn s into a palindrome by inserting less than n letters.

Find the number of the palindromes that can be obtained in this way, modulo 10007.

Input

The first line contains a string s (1 ≤ |s| ≤ 200). Each character in s is a lowercase English letter.

The second line contains an integer n (1 ≤ n ≤ 109).

Output

Print the number of the palindromes that can be obtained, modulo 10007.

Examples

Input

revive
1


Output

1


Input

add
2


Output

28

Note

For the first sample, you can obtain the palindrome "reviver" by inserting 'r' to the end of "revive".

For the second sample, the following 28 palindromes can be obtained: "adada", "adbda", ..., "adzda", "dadad" and "ddadd".
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
  return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
  return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t = buf;
inline int fetch() {
  if (s == t) {
    t = (s = buf) + fread(buf, 1, bufl, stdin);
    if (s == t) return EOF;
  }
  return *s++;
}
inline int ty() {
  int a = 0;
  int b = 1, c = fetch();
  while (!isdigit(c)) b ^= c == '-', c = fetch();
  while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
  return b ? a : -a;
}
inline int ts(char *s) {
  int a = 0, c = fetch();
  while (c <= 32 && c != EOF) c = fetch();
  while (c > 32 && c != EOF) s[a++] = c, c = fetch();
  s[a] = 0;
  return a;
}
}  // namespace ae86
using ae86::ts;
using ae86::ty;
const int _ = 207, __ = _ + _ / 2, mo = 10007;
template <typename T1, typename T2>
inline T1 ad(T1 &a, T2 b) {
  return a = a + b >= mo ? a + b - mo : a + b;
}
template <typename T1, typename T2>
inline T1 dl(T1 &a, T2 b) {
  return a = a >= b ? a - b : a - b + mo;
}
template <typename T1, typename T2>
inline T1 add(T1 a, T2 b) {
  return a + b >= mo ? a + b - mo : a + b;
}
template <typename T1, typename T2>
inline T1 del(T1 a, T2 b) {
  return a >= b ? a - b : a - b + mo;
}
long long powa(long long a, long long t) {
  long long b = 1;
  a = (a + mo) % mo;
  while (t) {
    if (t & 1) b = b * a % mo;
    a = a * a % mo, t >>= 1;
  }
  return b;
}
inline long long inva(long long a) { return powa(a, mo - 2); }
int n, m;
char s[_];
int lim;
long long f[__] = {0}, g[__][__] = {0}, h[__][__][__];
long long dfs(int d, int l, int r) {
  if (d < 0) return 0;
  if (h[d][l][r] >= 0) return h[d][l][r];
  if (l == 1 && r == m) return h[d][l][r] = d == 0;
  long long ans = 0;
  if (l > 1 && s[l - 1] != s[r]) ad(ans, dfs(d - 1, l - 1, r));
  if (r < m && s[l] != s[r + 1]) ad(ans, dfs(d - 1, l, r + 1));
  if (l > 1 && r < m && s[l - 1] == s[r + 1]) ad(ans, dfs(d, l - 1, r + 1));
  return h[d][l][r] = ans;
}
void che1n(long long a[__], long long b[__][__]) {
  static long long c[__];
  for (int i = 1; i <= lim; i++) c[i] = 0;
  for (int i = 1; i <= lim; i++)
    for (int j = 1; j <= lim; j++) ad(c[j], a[i] * b[i][j] % mo);
  for (int i = 1; i <= lim; i++) a[i] = c[i];
}
void chennsf(long long a[__][__]) {
  static long long b[__][__];
  for (int i = 1; i <= lim; i++)
    for (int j = 1; j <= lim; j++) b[i][j] = 0;
  for (int i = 1; i <= lim; i++)
    for (int j = i; j <= lim; j++)
      for (int k = j; k <= lim; k++) ad(b[i][k], a[i][j] * a[j][k] % mo);
  for (int i = 1; i <= lim; i++)
    for (int j = 1; j <= lim; j++) a[i][j] = b[i][j];
}
long long pf[__], pg[__][__];
int main() {
  ios::sync_with_stdio(0), cout.tie(nullptr);
  m = ts(s + 1), n = ty();
  lim = m + (m + 1) / 2;
  memset(h, -1, sizeof(h));
  for (int i = 0; i < m; i++) {
    long long val = 0;
    for (int j = 1; j <= m; j++) {
      ad(val, dfs(i, j, j));
      if (j < m && s[j] == s[j + 1]) ad(val, dfs(i, j, j + 1));
    }
    if (i > 0) {
      g[i][lim - (m - i + 1) / 2] = val, g[i][i] = 24;
      if (i > 1)
        g[i - 1][i] = 1;
      else
        f[i] = 1;
    } else {
      f[m] = val, g[lim][lim] = 26;
      for (int j = m; j < lim; j++) g[j][j + 1] = 1, g[j][j] = 25;
    }
  }
  memcpy(pf, f, sizeof(pf)), memcpy(pg, g, sizeof(pg));
  int temp = (n + m + 1) / 2;
  while (temp) {
    if (temp & 1) che1n(f, g);
    chennsf(g), temp >>= 1;
  }
  long long ans = f[lim];
  if (!((n + m) & 1)) {
    cout << ans << lf;
    return 0;
  }
  memcpy(f, pf, sizeof(pf)), memcpy(g, pg, sizeof(pg));
  for (int i = 0; i < m; i++) {
    long long val = 0;
    for (int j = 1; j < m; j++)
      if (s[j] == s[j + 1]) ad(val, dfs(i, j, j + 1));
    if (i)
      g[i][lim - (m - i + 1) / 2] = val;
    else
      f[m] = val, g[lim][lim] = 0;
  }
  temp = (n + m + 1) / 2;
  while (temp) {
    if (temp & 1) che1n(f, g);
    chennsf(g), temp >>= 1;
  }
  dl(ans, f[lim]);
  cout << ans << lf;
  return 0;
}
