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 N = 307;
const int mod = 1e4 + 7;
int n, m, maxn, g[N];
char s[N];
struct Matix {
  int f[N][N];
  void clear() {
    for (int i = 1, iE = maxn; i <= iE; i++)
      for (int j = 1, jE = maxn; j <= jE; j++) f[i][j] = 0;
  }
  void start() {
    clear();
    for (int i = 1, iE = maxn; i <= iE; i++) f[i][i] = 1;
  }
} G;
Matix operator*(Matix aa, Matix bb) {
  Matix res;
  res.clear();
  for (int i = 1, iE = maxn; i <= iE; i++)
    for (int j = i, jE = maxn; j <= jE; j++)
      for (int k = i, kE = j; k <= kE; k++)
        (res.f[i][j] += 1ll * aa.f[i][k] * bb.f[k][j]) %= mod;
  return res;
}
Matix operator^(Matix aa, int bb) {
  Matix res;
  res.start();
  for (; bb; aa = aa * aa, bb >>= 1)
    if (bb & 1) res = res * aa;
  return res;
}
int dp[N][N][N], cnt[N];
int main() {
  scanf("%s", s + 1), n = strlen(s + 1);
  scanf("%d", &m);
  int len = (m + n + 1) / 2;
  maxn = n + (n + 3) / 2;
  dp[1][n][0] = 1;
  for (int Len = n, LenE = 1; Len >= LenE; Len--)
    for (int l = 1, lE = n - Len + 1; l <= lE; l++) {
      int r = l + Len - 1;
      if (s[l] ^ s[r]) {
        for (int k = n - 1, kE = 1; k >= kE; k--) dp[l][r][k] = dp[l][r][k - 1];
        dp[l][r][0] = 0;
        for (int k = 0, kE = n - 1; k <= kE; k++)
          (dp[l + 1][r][k] += dp[l][r][k]) %= mod,
              (dp[l][r - 1][k] += dp[l][r][k]) %= mod;
      } else if (r - l + 1 > 2)
        for (int k = 0, kE = n - 1; k <= kE; k++)
          (dp[l + 1][r - 1][k] += dp[l][r][k]) %= mod;
    }
  for (int l = 1, lE = n; l <= lE; l++)
    for (int r = l, rE = min(l + 1, n); r <= rE; r++)
      if (s[l] == s[r])
        for (int k = 0, kE = n - 1; k <= kE; k++)
          (cnt[k] += dp[l][r][k]) %= mod;
  for (int i = 1, iE = n - 1; i <= iE; i++) G.f[i][i + 1] = 1;
  for (int i = 2, iE = n; i <= iE; i++) G.f[i][i] = 24;
  for (int i = n + 1, iE = maxn - 1; i <= iE; i++)
    G.f[i][i] = 25, G.f[i][i + 1] = 1;
  G.f[maxn][maxn] = 26;
  for (int i = 0, iE = n - 1; i <= iE; i++)
    G.f[i + 1][maxn - (n + 1 - i) / 2] = cnt[i];
  int res = (G ^ (len + 1)).f[1][maxn];
  if (!((n + m) & 1))
    printf("%d\n", res);
  else {
    for (int l = 1, lE = n; l <= lE; l++)
      for (int k = 0, kE = n - 1; k <= kE; k++)
        (cnt[k] += mod - dp[l][l][k]) %= mod;
    for (int i = 0, iE = n - 1; i <= iE; i++)
      G.f[i + 1][maxn - (n + 1 - i) / 2] = cnt[i];
    G.f[maxn][maxn] = 0;
    printf("%d\n", (res + mod - (G ^ (len + 1)).f[1][maxn]) % mod);
  }
  return 0;
}