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 = 310, mo = 10007;
char c[N];
int n, m, ans, t;
int f[N][N][N], su[N];
struct mat {
  int a[N][N];
} a, b;
long long c2[N][N];
mat operator*(const mat& a, const mat& b) {
  mat c;
  memset(c2, 0, sizeof c2);
  for (int i = 1, _e = t; i <= _e; ++i)
    for (int j = 1, _e = t; j <= _e; ++j)
      for (int k = 1, _e = t; k <= _e; ++k) c2[i][k] += a.a[i][j] * b.a[j][k];
  for (int i = 1, _e = t; i <= _e; ++i)
    for (int j = 1, _e = t; j <= _e; ++j) c.a[i][j] = c2[i][j] % mo;
  return c;
}
mat ksm(mat x, int y) {
  mat b;
  memset(b.a, 0, sizeof b.a);
  for (int i = 1, _e = t; i <= _e; ++i) b.a[i][i] = 1;
  for (; y; y >>= 1, x = x * x)
    if (y & 1) b = b * x;
  return b;
}
int main() {
  scanf("%s\n%d", c + 1, &m);
  n = strlen(c + 1);
  f[1][n][0] = 1;
  for (int i = 1, _e = n; i <= _e; ++i)
    for (int j = n, _e = i; j >= _e; --j)
      if (c[i] == c[j]) {
        for (int k = 0, _e = n; k <= _e; ++k)
          if (i + 1 <= j - 1)
            (f[i + 1][j - 1][k] = (f[i + 1][j - 1][k] + f[i][j][k]) % mo);
          else
            (su[k] = (su[k] + f[i][j][k]) % mo);
      } else {
        for (int k = 0, _e = n - 1; k <= _e; ++k) {
          (f[i + 1][j][k + 1] = (f[i + 1][j][k + 1] + f[i][j][k]) % mo);
          (f[i][j - 1][k + 1] = (f[i][j - 1][k + 1] + f[i][j][k]) % mo);
        }
      }
  t = n + (n + 1 >> 1) + 1;
  a.a[t][t] = 26;
  for (int i = 1, _e = n; i <= _e; ++i) {
    a.a[i][i] = 24;
    a.a[i][n + (n - i + 1) / 2] = su[i];
    if (i < n) a.a[i][i + 1] = 1;
  }
  for (int i = n + 1, _e = t - 1; i <= _e; ++i) {
    a.a[i][i] = 25;
    if (i > n + 1)
      a.a[i][i - 1] = 1;
    else
      a.a[i][t] = 1;
  }
  b = ksm(a, n + m + 1 >> 1);
  ans = (b.a[1][t] + su[0] * b.a[t - 1][t]) % mo;
  if (n + m & 1) {
    for (int i = 0, _e = n; i <= _e; ++i) su[i] = 0;
    for (int i = 1, _e = n - 1; i <= _e; ++i)
      if (c[i] == c[i + 1])
        for (int j = 0, _e = n; j <= _e; ++j)
          (su[j] = (su[j] + f[i][i + 1][j]) % mo);
    for (int i = 1, _e = n; i <= _e; ++i) a.a[i][n + (n - i + 1) / 2] = su[i];
    a.a[t][t] = 0;
    b = ksm(a, n + m + 1 >> 1);
    ans = ((ans - b.a[1][t] - su[0] * b.a[t - 1][t]) % mo + mo) % mo;
  }
  cout << ans;
}