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 = 205;
const int P = 1e4 + 7;
template <typename T>
void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  x *= f;
}
template <typename T>
void write(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void writeln(T x) {
  write(x);
  puts("");
}
void update(int &x, int y) {
  x += y;
  if (x >= P) x -= P;
}
namespace LinearSequence {
const int MAXN = 1205;
int cnt, delta[MAXN], fail[MAXN];
int k, h[MAXN], r[MAXN];
vector<int> a[MAXN];
int power(int x, int y) {
  if (y == 0) return 1;
  int tmp = power(x, y / 2);
  if (y % 2 == 0)
    return tmp * tmp % P;
  else
    return tmp * tmp % P * x % P;
}
void times(int *a, int *b, int *res) {
  static int tmp[MAXN];
  memset(tmp, 0, sizeof(tmp));
  for (int i = 0; i <= k - 1; i++)
    for (int j = 0; j <= k - 1; j++) update(tmp[i + j], 1ll * a[i] * b[j] % P);
  for (int i = 2 * k - 2; i >= k; i--) {
    int tnp = tmp[i];
    tmp[i] = 0;
    for (int j = 1; j <= k; j++) update(tmp[i - j], 1ll * tnp * r[j] % P);
  }
  memcpy(res, tmp, sizeof(tmp));
}
int getans(int n) {
  if (n <= k) return h[n];
  static int res[MAXN], now[MAXN];
  n -= k, res[0] = 1, now[1] = 1;
  if (k == 1) now[1] = 0, now[0] = r[1];
  while (n != 0) {
    if (n % 2 == 1) times(res, now, res);
    times(now, now, now);
    n /= 2;
  }
  int ans = 0;
  for (int i = 0; i <= k - 1; i++) update(ans, 1ll * res[i] * h[k + i] % P);
  return ans;
}
void work(int n, int *val, int m) {
  a[cnt = 0].clear();
  for (int i = 1; i <= n; i++) {
    delta[i] = val[i];
    for (unsigned j = 0; j < a[cnt].size(); j++)
      update(delta[i], P - 1ll * val[i - j - 1] * a[cnt][j] % P);
    if (delta[i] == 0) continue;
    fail[cnt] = i;
    if (cnt == 0) {
      a[++cnt].clear();
      a[cnt].resize(i);
      continue;
    }
    int mul = 1ll * delta[i] * power(delta[fail[cnt - 1]], P - 2) % P;
    a[++cnt].clear(), a[cnt].resize(i - fail[cnt - 2] - 1);
    a[cnt].push_back(mul);
    for (auto x : a[cnt - 2]) a[cnt].push_back(1ll * x * (P - mul) % P);
    if (a[cnt].size() < a[cnt - 1].size()) a[cnt].resize(a[cnt - 1].size());
    for (unsigned j = 0; j < a[cnt - 1].size(); j++)
      update(a[cnt][j], a[cnt - 1][j]);
  }
  k = a[cnt].size();
  for (int i = 1; i <= 2 * k; i++) h[i] = val[i], r[i] = a[cnt][i - 1];
  writeln(getans(m));
}
}  // namespace LinearSequence
char s[MAXN];
int len, n, ans[MAXN * 8], done[MAXN * 4];
int dp[MAXN * 4][MAXN][MAXN];
int main() {
  scanf("%s", s + 1);
  len = strlen(s + 1), read(n);
  dp[0][1][len] = 1;
  for (int k = 1; k <= len * 4 + 5; k++) {
    done[k] = done[k - 1] * 26 % P;
    for (int i = 1; i <= len; i++)
      for (int j = i; j <= len; j++) {
        if (s[i] == s[j]) {
          if (i + 1 <= j - 1)
            update(dp[k][i + 1][j - 1], dp[k - 1][i][j]);
          else
            update(done[k], dp[k - 1][i][j]);
          update(dp[k][i][j], dp[k - 1][i][j] * 25 % P);
        } else {
          if (i == j)
            update(done[k], dp[k - 1][i][j] * 2 % P);
          else {
            update(dp[k][i + 1][j], dp[k - 1][i][j]);
            update(dp[k][i][j - 1], dp[k - 1][i][j]);
          }
          update(dp[k][i][j], dp[k - 1][i][j] * 24 % P);
        }
      }
  }
  for (int i = 1; i <= len * 8 + 5; i++) {
    if (i & 1) {
      ans[i] = done[i / 2] * 26 % P;
      for (int j = 1; j <= len; j++) update(ans[i], dp[i / 2][j][j]);
    } else
      ans[i] = done[i / 2];
  }
  LinearSequence ::work(len * 7 + 5, ans + len, n);
  return 0;
}