#include <bits/stdc++.h>
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 4611686018427387903;
const int Sz = 1110111;
using namespace std;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
}
string s;
int k;
inline long long binpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1ll) res = (res * a) % Mod;
    b >>= 1;
    a = (a * a) % Mod;
  }
  return res;
}
struct matrix {
  long long a[2][2];
  int n;
  matrix() {
    n = 2;
    memset(a, 0, sizeof a);
  }
  inline matrix operator*(matrix &b) {
    matrix c;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++)
          c.a[i][j] = (c.a[i][j] + a[i][k] * b.a[k][j]) % Mod;
    return c;
  }
  inline void show() {
    for (int i = 0; i < n; i++, cout << endl)
      for (int j = 0; j < n; j++) cout << a[i][j] << ' ';
  }
};
inline void binpow(matrix &a, matrix b, long long n) {
  while (n) {
    if (n & 1) a = a * b;
    b = b * b;
    n >>= 1;
  }
}
int main() {
  Read_rap();
  cin >> s;
  cin >> k;
  long long pw = 1, a = 0;
  for (int i = 0; i < (int)(s.size()); i++) {
    if (s[i % (int)(s.size())] == '0' || s[i % (int)(s.size())] == '5')
      a = (a + pw) % Mod;
    pw = (pw * 2) % Mod;
  }
  matrix res, con;
  res.a[0][1] = a;
  con.a[0][0] = pw;
  con.a[1][0] = 1;
  con.a[0][1] = 0;
  con.a[1][1] = 1;
  binpow(res, con, k);
  cout << res.a[0][0];
  return 0;
}
