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 = 2 * 1e2 + 10;
const int mod = 10007;
int tr[N][N];
int tp[N * N];
int n;
char mde[N];
int m;
int ctt;
int trp[N << 1][N << 1];
int S;
int ans;
struct Grph {
  int v[2 * N * N];
  int x[2 * N * N];
  int ct;
  int al[N * N];
  int dp[N][N * N];
  bool book[N][N * N];
  inline void add(int u, int V) {
    v[++ct] = V;
    x[ct] = al[u];
    al[u] = ct;
  }
  inline int dfs(int cnt, int u) {
    if (cnt < 0) return 0;
    if (book[cnt][u]) return dp[cnt][u];
    book[cnt][u] = true;
    for (int i = al[u]; i; i = x[i])
      (dp[cnt][u] += dfs(cnt - tp[u], v[i])) %= mod;
    return dp[cnt][u];
  }
} g1, g2;
struct mar {
  int mp[N << 1][N << 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]) %= mod;
    for (int i = 1; i <= S; i++)
      for (int j = 1; j <= S; j++) mp[i][j] = trp[i][j];
  }
} trs, res;
int f[N];
int g[N];
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)
          g1.add(tr[i][j], ctt), g2.add(ctt, tr[i][j]);
        else
          g1.add(tr[i][j], tr[i + 1][j - 1]),
              g2.add(tr[i + 1][j - 1], tr[i][j]);
      } else {
        tp[tr[i][j]] = 1;
        g1.add(tr[i][j], tr[i + 1][j]), g1.add(tr[i][j], 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++) g1.book[i][ctt] = true;
  g1.dp[0][ctt] = 1;
  for (int i = 0; i < n; i++) g2.book[i][tr[1][n]] = true;
  g2.dp[tp[tr[1][n]]][tr[1][n]] = 1;
  for (int i = 0; i < n; i++) g1.dfs(i, tr[1][n]);
  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[n + i][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] * g1.dp[i][tr[1][n]]) %= mod;
    (ans *= 26) %= mod;
    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]]) %= mod;
  } else {
    for (int i = 0; i < n; i++) (ans += f[i] * g1.dp[i][tr[1][n]]) %= mod;
  }
  printf("%d", ans);
  return 0;
}