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 MAXN = 2 * 1e2 + 10;
const int P = 10007;
int tr[MAXN][MAXN];
int tp[MAXN * MAXN];
int n;
char mde[MAXN];
int m, ctt, S, ans;
int trp[MAXN << 1][MAXN << 1];
struct Grph {
  int to[2 * MAXN * MAXN];
  int nxt[2 * MAXN * MAXN];
  int ccnt;
  int home[MAXN * MAXN], dp[MAXN][MAXN * MAXN];
  bool book[MAXN][MAXN * MAXN];
  inline void add(int u, int v) {
    to[++ccnt] = v;
    nxt[ccnt] = home[u];
    home[u] = ccnt;
  }
  inline int dfs(int cnt, int u) {
    if (cnt < 0) return 0;
    if (book[cnt][u]) return dp[cnt][u];
    book[cnt][u] = 1;
    for (int i = home[u]; i; i = nxt[i])
      (dp[cnt][u] += dfs(cnt - tp[u], to[i])) %= P;
    return dp[cnt][u];
  }
} g2;
struct mar {
  int mp[MAXN << 1][MAXN << 1];
  inline int* operator[](const int x) { return mp[x]; }
  void operator*=(const mar& b) {
    for (int i = 1; i <= S; ++i)
      for (int j = 1; j <= S; ++j) trp[i][j] = 0;
    for (int i = 1; i <= S; ++i)
      for (int k = i; k <= S; ++k)
        for (int j = k; j <= S; ++j) (trp[i][j] += mp[i][k] * b.mp[k][j]) %= P;
    for (int i = 1; i <= S; ++i)
      for (int j = 1; j <= S; ++j) mp[i][j] = trp[i][j];
  }
} trs, res;
int f[MAXN], g[MAXN];
int main() {
  scanf("%s", mde + 1);
  scanf("%d", &m);
  for (n = 1; mde[n + 1] != '\0'; ++n)
    ;
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; ++j) tr[i][j] = ++ctt;
  ++ctt;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      if (mde[i] == mde[j]) {
        if (j - i <= 1)
          g2.add(ctt, tr[i][j]);
        else
          g2.add(tr[i + 1][j - 1], tr[i][j]);
      } else {
        tp[tr[i][j]] = 1;
        g2.add(tr[i + 1][j], tr[i][j]), g2.add(tr[i][j - 1], tr[i][j]);
      }
    }
  }
  for (int i = 0; i < n; ++i) g2.book[i][tr[1][n]] = 1;
  g2.dp[tp[tr[1][n]]][tr[1][n]] = 1;
  for (int i = 0; i < n; ++i) g2.dfs(i, ctt);
  for (int i = 1; i < n; ++i) trs[i][i] = 24;
  int t = (n + 1) / 2;
  for (int i = 0; i < t; ++i) trs[i + n][n + i] = 25;
  for (int i = 0; i < t; ++i) trs[n + t + i][n + t + i] = 26;
  for (int i = 1; i < n + t - 1; ++i) trs[i][i + 1]++;
  for (int i = 0; i < t; ++i) trs[n + i][n + t + i]++;
  S = n + (t << 1) - 1;
  for (int i = 1; i <= S; ++i) res[i][i] = 1;
  for (int p = (n + m) >> 1; p; p >>= 1, trs *= trs)
    if (p & 1) res *= trs;
  for (int i = 0, v; i < n; ++i)
    v = (n - i + 1) / 2, f[i] = res[n - i][n + t + v - 1],
    g[i] = res[n - i][n + v - 1];
  if ((n + m) & 1) {
    for (int i = 0; i < n; ++i) (ans += f[i] * g2.dp[i][ctt]) %= P;
    (ans *= 26) %= P;
    for (int i = 1; i <= 26; ++i) {
      for (int j = 1; j <= n; ++j) {
        if (mde[j] == 'a' + i - 1)
          for (int k = 0; k < n; ++k) (ans += g[k] * g2.dp[k][tr[j][j]]) %= P;
      }
    }
  } else {
    for (int i = 0; i < n; ++i) (ans += f[i] * g2.dp[i][ctt]) %= P;
  }
  printf("%d", ans);
  return 0;
}