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 = 1e4 + 7, N = 205;
int len, id[N][N], num, dp[N][N * N], tra[N][N], c[N * N];
int head[N * N], nxt[N * N << 1], to[N * N << 1], cnt, f[N], g[N];
bool book[N][N * N];
inline void add(int x, int y) {
  ++cnt;
  nxt[cnt] = head[x];
  head[x] = cnt;
  to[cnt] = y;
  return;
}
struct node {
  int mat[N << 1][N << 1];
  node operator*(node &a) const {
    node res;
    memset(res.mat, 0, sizeof(res.mat));
    for (int i = 1; i <= len; i++)
      for (int k = i; k <= len; k++)
        for (int j = k; j <= len; j++)
          (res.mat[i][j] += (mat[i][k] * a.mat[k][j])) %= MOD;
    return res;
  }
} p, ans;
char s[N];
int n, m;
int dfs(int sum, int x) {
  if (sum < 0) return 0;
  if (book[sum][x]) return dp[sum][x];
  book[sum][x] = 1;
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    (dp[sum][x] += dfs(sum - c[x], y)) %= MOD;
  }
  return dp[sum][x];
}
int main() {
  scanf("%s%d", s + 1, &m);
  n = strlen(s + 1);
  len = n + (n + 1) / 2 * 2 - 1;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) id[i][j] = ++num;
  ++num;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      if (s[i] == s[j] && j <= i + 1)
        add(num, id[i][j]);
      else if (s[i] == s[j])
        add(id[i + 1][j - 1], id[i][j]);
      else
        c[id[i][j]] = 1, add(id[i + 1][j], id[i][j]),
        add(id[i][j - 1], id[i][j]);
  for (int i = 0; i < n; i++) book[i][id[1][n]] = 1;
  dp[c[id[1][n]]][id[1][n]] = 1;
  for (int i = 0; i < n; i++) dfs(i, num);
  for (int i = 1; i < n; i++) p.mat[i][i] = 24;
  for (int i = 0; i < (n + 1) / 2; i++) p.mat[n + i][n + i] = 25;
  for (int i = 0; i < (n + 1) / 2; i++)
    p.mat[n + (n + 1) / 2 + i][n + (n + 1) / 2 + i] = 26;
  for (int i = 1; i < n + (n + 1) / 2 - 1; i++) p.mat[i][i + 1]++;
  for (int i = 0; i < (n + 1) / 2; i++) p.mat[n + i][n + (n + 1) / 2 + i]++;
  for (int i = 1; i <= len; i++) ans.mat[i][i] = 1;
  for (int i = (n + m) / 2; i > 0; p = p * p, i >>= 1)
    if (i & 1) ans = ans * p;
  for (int i = 0; i < n; i++)
    f[i] = ans.mat[n - i][n + (n + 1) / 2 - 1 + (n - i + 1) / 2],
    g[i] = ans.mat[n - i][n - 1 + (n - i + 1) / 2];
  if ((n + m) & 1) {
    int op = 0;
    for (int i = 0; i < n; i++) (op += (f[i] * dp[i][num])) %= MOD;
    (op *= 26) %= MOD;
    for (int i = 0; i < 26; i++)
      for (int j = 1; j <= n; j++)
        if (s[j] == ('a' + i))
          for (int k = 0; k < n; k++) (op += (g[k] * dp[k][id[j][j]])) %= MOD;
    printf("%d", op);
  } else {
    int op = 0;
    for (int i = 0; i < n; i++) (op += (f[i] * dp[i][num])) %= MOD;
    printf("%d", op);
  }
  return 0;
}