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 = 330, TO = 100100, M = 660, P = 10007;
struct edge {
  int n, v;
} e[TO << 1];
int n, m, S, T, R, fl, ans;
int hd[TO], l[TO], r[TO], g[N][N], c[TO], di[TO], du[TO];
int f[TO][N], w[2][N], vi[TO], a[M][M], b[M][M];
char s[N];
queue<int> q;
void add(int u, int v) {
  e[++fl] = (edge){hd[u], v};
  hd[u] = fl;
}
void dfs(int u) {
  for (int i = hd[u], v; v = e[i].v, i; i = e[i].n) {
    du[v]++;
    if (!vi[v]) vi[v] = 1, dfs(v);
  }
}
void bld() {
  T++;
  for (int i = 1; i <= T - 1; i++) {
    if (s[l[i] + 1] == s[r[i] - 1])
      c[i] = 1, r[i] - l[i] > 3 ? add(i, g[l[i] + 1][r[i] - 1]) : add(i, T);
    else
      c[i] = 0, add(i, g[l[i] + 1][r[i]]), add(i, g[l[i]][r[i] - 1]);
  }
}
void wrk() {
  dfs(1);
  q.push(1);
  f[1][!c[1]] = 1;
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int i = hd[u], v; v = e[i].v, i; i = e[i].n) {
      if (v != T) {
        di[v] = di[u] + 1 + c[u];
        for (int j = 0; j <= di[u] + 1; j++) (f[v][j + !c[v]] += f[u][j]) %= P;
      } else
        for (int j = 0; j <= di[u] + 1; j++)
          (w[di[u] == n - 2][j] += f[u][j]) %= P;
      if (!--du[v]) q.push(v);
    }
  }
}
void mul(int a[M][M], int b[M][M], int c[M][M]) {
  static int d[M][M];
  for (int i = 1; i <= R; i++)
    for (int j = 1; j <= R; j++) d[i][j] = 0;
  for (int i = 1; i <= R; i++)
    for (int j = i; j <= R; j++)
      for (int k = i; k <= j; k++) d[i][j] += a[i][k] * b[k][j] % P;
  for (int i = 1; i <= R; i++)
    for (int j = 1; j <= R; j++) c[i][j] = d[i][j] % P;
}
void qpw(int a[M][M], int y, int b[M][M]) {
  static int c[M][M];
  for (int i = 1; i <= R; i++)
    for (int j = 1; j <= R; j++) b[i][j] = (i == j), c[i][j] = a[i][j];
  for (; y; y >>= 1, mul(c, c, c))
    if (y & 1) mul(b, c, b);
}
void mtm() {
  R = 3 * n;
  for (int i = n + 1; i <= n * 2; i++)
    a[i - n][i - n] = 24, a[i][i] = 25, a[i + n][i + n] = 26, a[i][i + n] = 1;
  for (int i = 2; i <= 2 * n; i++) a[i - 1][i] = 1;
  qpw(a, m / 2, b);
  if (m & 1) {
    for (int i = 1; i <= T - 1; i++)
      if (l[i] + 3 == r[i] && c[i])
        for (int k = 0; k <= n / 2; k++) {
          int j = n - 2 * k;
          (ans += P - f[i][j] * b[n - j + 1][k + n] % P) %= P;
        }
    mul(a, b, b);
  }
  for (int k = 0; k <= (n + 1) / 2; k++) {
    int i = n - 2 * k, j = i + 1;
    if (j >= 0) (ans += w[0][j] * b[n - j + 1][k + 2 * n] % P) %= P;
    if (i >= 0) (ans += w[1][i] * b[n - i + 1][k + 2 * n] % P) %= P;
  }
}
int main() {
  scanf("%s%d", s + 1, &m);
  n = strlen(s + 1);
  m += n;
  for (int i = 0; i <= n - 1; i++)
    for (int j = n + 1; j >= i + 2; j--) g[i][j] = ++T, l[T] = i, r[T] = j;
  bld();
  wrk();
  mtm();
  printf("%d\n", ans);
}