Problem: 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".

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int mod = 10007;
int mul(int a, int b) { return a * b % mod; }
int ad(int a, int b) { return (a += b) >= mod ? a - mod : a; }
void inc(int& a, int b) { (a += b) >= mod ? a -= mod : 0; }
int pow(int a, int b) {
  int s = 1;
  while (b) {
    if (b & 1) s = mul(s, a);
    a = mul(a, a);
    b >>= 1;
  }
  return s;
}
const int N = 1510;
namespace bm {
int a[N];
struct tr {
  int b[N], k, f, d;
  int& operator[](int k) { return b[k]; }
} fr, se, tmp;
int get(int i) {
  int j, s;
  s = 0;
  for (j = 1; j <= fr.k; j++) inc(s, mul(fr[j], a[i - j]));
  return s;
}
void work(int n) {
  int i, j, d, t;
  for (i = 1; i <= n; i++) {
    d = ad(a[i], mod - get(i));
    if (!d) continue;
    if (!fr.k) {
      fr.k = i;
      se.f = i;
      se.d = d;
      continue;
    }
    t = mul(d, pow(se.d, mod - 2));
    tmp = fr;
    tmp.k = max(fr.k, i - se.f + se.k);
    inc(tmp[i - se.f], t);
    for (j = 1; j <= se.k; j++) inc(tmp[i - se.f + j], mod - mul(t, se[j]));
    fr.f = i;
    fr.d = d;
    if (fr.k - fr.f < se.k - se.f) se = fr;
    fr = tmp;
  }
}
}  // namespace bm
namespace p {
int f[610], k;
int t[1210];
void pmul(int* a, int& n, int* b, int m) {
  int i, j;
  memset(t, 0, (n + m + 1) << 2);
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= m; j++) inc(t[i + j], mul(a[i], b[j]));
  }
  n += m;
  for (i = n - k; i >= 0; i--) {
    for (j = 0; j <= k; j++) inc(t[i + j], mod - mul(t[i + k], f[j]));
  }
  n = min(n, k - 1);
  memcpy(a, t, (n + 1) << 2);
}
int a[610], s[610];
void pow(int b) {
  int n, sn;
  n = 1;
  a[1] = 1;
  sn = 0;
  s[0] = 1;
  while (b) {
    if (b & 1) pmul(s, sn, a, n);
    pmul(a, n, a, n);
    b >>= 1;
  }
}
}  // namespace p
char s[210];
int f[210][210], g_[210][210];
int& g(int l, int r) { return r - l < 2 ? g_[0][0] : g_[l][r]; }
int ans[N], tp;
int main() {
  int n, m, i, j, k, res;
  scanf("%s%d", s + 1, &n);
  m = strlen(s + 1);
  f[0][m + 1] = 1;
  for (k = 0; tp <= 1500; k++) {
    if (k * 2 + 1 >= m) {
      res = f[0][0];
      if (k * 2 >= m) ans[++tp] = res;
      res = mul(res, 26);
      for (i = 0; i + 2 <= m + 1; i++) inc(res, f[i][i + 2]);
      if (k * 2 + 1 >= m) ans[++tp] = res;
    }
    memset(g_, 0, sizeof(g_));
    inc(g_[0][0], mul(f[0][0], 26));
    for (i = 0; i <= m; i++) {
      for (j = i + 2; j <= m + 1; j++) {
        if (!f[i][j]) continue;
        if (s[i + 1] != s[j - 1]) {
          inc(g(i, j), mul(f[i][j], 24));
          inc(g(i + 1, j), f[i][j]);
          inc(g(i, j - 1), f[i][j]);
        } else {
          inc(g(i, j), mul(f[i][j], 25));
          inc(g(i + 1, j - 1), f[i][j]);
        }
      }
    }
    memcpy(f, g_, sizeof(g_));
  }
  memcpy(bm::a, ans, (tp + 1) << 2);
  bm::work(tp);
  k = bm::fr.k;
  p::k = k;
  p::f[k] = 1;
  for (i = 1; i <= k; i++) p::f[k - i] = mod - bm::fr[i];
  p::pow(n);
  res = 0;
  for (i = 1; i <= k; i++) inc(res, mul(ans[i], p::s[i - 1]));
  printf("%d", res);
}