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 maxL = 200 + 10;
const int MOD = 10007;
inline int inc(int a, int b) {
  return (a + b >= MOD) ? (a + b - MOD) : (a + b);
}
inline int dec(int a, int b) { return (a >= b) ? (a - b) : (a + MOD - b); }
inline int mul(int a, int b) { return 1LL * a * b % MOD; }
inline void updata(int &x, int y) { x = inc(x, y); }
inline int power(int x, int k) {
  int tmp = 1;
  while (k) {
    if (k & 1) tmp = mul(tmp, x);
    x = mul(x, x);
    k >>= 1;
  }
  return tmp;
}
char s[maxL];
int n, m, dp[1250][maxL][maxL], g[1250], val[1250];
inline void prepare(int N) {
  dp[0][1][m] = 1;
  for (int i = 0; i <= N; i++) {
    g[i + 1] = mul(g[i], 26);
    for (int j = 1; j <= m; j++) {
      for (int k = j; k <= m; k++) {
        if (s[j] == s[k]) {
          if (k - j <= 1)
            updata(g[i + 1], dp[i][j][k]);
          else
            updata(dp[i + 1][j + 1][k - 1], dp[i][j][k]);
          updata(dp[i + 1][j][k], mul(dp[i][j][k], 25));
        } else {
          updata(dp[i + 1][j + 1][k], dp[i][j][k]);
          updata(dp[i + 1][j][k - 1], dp[i][j][k]);
          updata(dp[i + 1][j][k], mul(dp[i][j][k], 24));
        }
      }
    }
  }
  for (int i = 1; i <= N; i++) {
    if (i & 1) {
      val[i] = mul(g[i / 2], 26);
      for (int j = 1; j <= m; j++) updata(val[i], dp[i / 2][j][j]);
    } else
      val[i] = g[i / 2];
  }
}
vector<int> p[1250];
int tot, best, delta[1250], F[1250], ln, fail[1250], f[1250];
inline void BM(int *a, int n, int *c, int &ln) {
  tot = best = 0;
  for (int i = 1; i <= n; i++) {
    int del = a[i];
    for (int j = 0, Sz = p[tot].size(); j < Sz; j++) {
      del = dec(del, mul(a[i - j - 1], p[tot][j]));
    }
    delta[i] = del;
    if (!del) continue;
    fail[tot] = i;
    if (!tot) {
      p[++tot].resize(i);
      continue;
    }
    int k = mul(del, power(delta[fail[best]], MOD - 2));
    vector<int> cur;
    cur.resize(i - fail[best] - 1);
    cur.push_back(k);
    k = dec(MOD, k);
    vector<int> &ls = p[best];
    for (int j = 0, Sz = ls.size(); j < Sz; j++) cur.push_back(mul(ls[j], k));
    if (cur.size() < p[tot].size()) cur.resize(p[tot].size());
    for (int j = 0, Sz = p[tot].size(); j < Sz; j++) updata(cur[j], p[tot][j]);
    if (i - fail[best] + (int)ls.size() >= (int)cur.size()) best = tot;
    p[++tot] = cur;
  }
  ln = p[tot].size();
  for (int i = 0; i < ln; i++) c[i + 1] = p[tot][i];
  return;
  for (int i = ln + 1; i <= n; i++) {
    int tmp = a[i];
    for (int j = 1; j <= ln; j++) {
      tmp = dec(tmp, mul(c[j], a[i - j]));
    }
    printf("%d\n", tmp);
  }
}
int A[1250], B[1250];
int tc[2610];
inline void Mul(int *c, int *a, int *b) {
  for (int i = 0; i < ln + ln; i++) tc[i] = 0;
  for (int i = 0; i < ln; i++) {
    for (int j = 0; j < ln; j++) updata(tc[i + j], mul(a[i], b[j]));
  }
  for (int i = ln + ln - 2; i >= ln; i--) {
    for (int j = ln - 1; j >= 0; j--)
      tc[i - ln + j] = dec(tc[i - ln + j], mul(tc[i], f[j]));
    tc[i] = 0;
  }
  for (int i = 0; i < ln; i++) c[i] = tc[i];
}
inline int solve(int n) {
  if (n <= ln) return val[n];
  n -= ln;
  f[ln] = 1;
  for (int i = 1; i <= ln; i++) f[ln - i] = dec(MOD, F[i]), f[ln - i] %= MOD;
  A[0] = 1;
  B[1] = 1;
  while (n) {
    if (n & 1) Mul(A, A, B);
    Mul(B, B, B);
    n >>= 1;
  }
  int tmp = 0;
  for (int i = 0; i < ln; i++) {
    updata(tmp, mul(A[i], val[i + ln]));
  }
  return tmp;
}
int main() {
  scanf("%s", s + 1);
  scanf("%d", &n);
  m = strlen(s + 1);
  prepare(6 * m + 10);
  BM(val, 6 * m + 10, F, ln);
  int Ans = solve(n + m);
  printf("%d\n", Ans);
  return 0;
}