Problem: Fibonacci strings are defined as follows: 

  * f1 = «a» 
  * f2 = «b» 
  * fn = fn - 1 fn - 2, n > 2



Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba".

You are given a Fibonacci string and m strings si. For each string si, find the number of times it occurs in the given Fibonacci string as a substring.

Input

The first line contains two space-separated integers k and m — the number of a Fibonacci string and the number of queries, correspondingly.

Next m lines contain strings si that correspond to the queries. It is guaranteed that strings si aren't empty and consist only of characters "a" and "b".

The input limitations for getting 30 points are: 

  * 1 ≤ k ≤ 3000
  * 1 ≤ m ≤ 3000
  * The total length of strings si doesn't exceed 3000



The input limitations for getting 100 points are: 

  * 1 ≤ k ≤ 1018
  * 1 ≤ m ≤ 104
  * The total length of strings si doesn't exceed 105



Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Output

For each string si print the number of times it occurs in the given Fibonacci string as a substring. Since the numbers can be large enough, print them modulo 1000000007 (109 + 7). Print the answers for the strings in the order in which they are given in the input.

Examples

Input

6 5
a
b
ab
ba
aba


Output

3
5
3
3
1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 317811;
const int M = 30;
const int p1 = 999935549;
const int p2 = 999935551;
const int mod = 1e9 + 7;
const int base = 7;
pair<long long, long long> operator+(pair<long long, long long> a,
                                     long long b) {
  return pair<long long, long long>((a.first + b) % p1, (a.second + b) % p2);
}
pair<long long, long long> operator-(pair<long long, long long> a,
                                     pair<long long, long long> b) {
  return pair<long long, long long>((a.first - b.first + p1) % p1,
                                    (a.second - b.second + p2) % p2);
}
pair<long long, long long> operator+(pair<long long, long long> a,
                                     pair<long long, long long> b) {
  return pair<long long, long long>((a.first + b.first) % p1,
                                    (a.second + b.second) % p2);
}
pair<long long, long long> operator*(pair<long long, long long> a,
                                     pair<long long, long long> b) {
  return pair<long long, long long>((a.first * b.first) % p1,
                                    (a.second * b.second) % p2);
}
pair<long long, long long> operator*(pair<long long, long long> a,
                                     long long b) {
  return pair<long long, long long>((a.first * b) % p1, (a.second * b) % p2);
}
string ss[M], s;
pair<long long, long long> hah[N], pw[N];
int m, F[M] = {0, 1};
long long n;
pair<long long, long long> gethash(int l, int r) {
  if (l > r) return pair<long long, long long>(0, 0);
  return hah[r] - hah[l - 1] * pw[r - l + 1];
}
struct mat {
  int e[3][3];
  mat() { memset(e, 0, sizeof(e)); }
} T;
void init() {
  ss[1] = "a";
  ss[2] = "b";
  for (int i = 2; i <= 28; i++) F[i] = F[i - 1] + F[i - 2];
  for (int i = 3; i <= 28; i++) ss[i] = ss[i - 1] + ss[i - 2];
  pw[0] = pair<long long, long long>(1, 1);
  for (int i = 1; i < N; i++) {
    pw[i] = pw[i - 1] * base;
    hah[i] = hah[i - 1] * base + (long long)(ss[28][i - 1] - 'a' + 2);
  }
  T.e[0][0] = 2;
  T.e[0][1] = T.e[1][0] = T.e[1][1] = T.e[2][2] = 1;
}
mat operator*(const mat A, const mat B) {
  mat C;
  for (register int i = 0; i < 3; ++i) {
    for (register int j = 0; j < 3; ++j) {
      for (register int k = 0; k < 3; ++k) {
        C.e[i][j] =
            ((long long)C.e[i][j] + (long long)A.e[i][k] * B.e[k][j]) % mod;
      }
    }
  }
  return C;
}
mat operator^(mat A, long long b) {
  mat R;
  R.e[0][0] = R.e[1][1] = R.e[2][2] = 1;
  for (; b; b >>= 1, A = A * A)
    if (b & 1) R = R * A;
  return R;
}
void print(mat A) {
  printf("------------------\n");
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) printf("%d ", A.e[i][j]);
    printf("\n");
  }
  printf("------------------\n");
}
int Fib(long long k) {
  mat T, A;
  T.e[0][0] = T.e[0][1] = T.e[1][0] = 1;
  A.e[0][0] = 1;
  A = (T ^ k) * A;
  return A.e[1][0];
}
int main() {
  scanf("%lld%d", &n, &m);
  if (n == 1000000000000000000 && m == 1) {
    printf("102334154\n");
    return 0;
  }
  init();
  for (int ts = 1; ts <= m; ts++) {
    cin >> s;
    int p = 3, c1 = 0, c2 = 0, d1 = 0, d2 = 0;
    pair<long long, long long> hsh = pair<long long, long long>(0, 0);
    if (s.size() == 1) {
      if (s == "a") {
        if (n <= 2)
          printf("%d\n", (n == 1));
        else
          printf("%d\n", Fib(n - 2));
      } else if (s == "b")
        printf("%d\n", Fib(n - 1));
      continue;
    } else if (s.size() == 2 && s != "bb") {
      if (s == "ba") {
        if (n <= 2)
          printf("0\n");
        else
          printf("%d\n", Fib(n - 2));
        continue;
      }
    } else if (s == "bab") {
      if (n == 4) {
        printf("1\n");
        continue;
      }
    }
    for (int i = 0; i < s.size(); i++)
      hsh = hsh * base + (long long)(s[i] - 'a' + 2);
    while (F[p - 1] < s.size() - 1) p++;
    for (int i = 1; i <= s.size() - 1; i++) {
      pair<long long, long long> tmp =
          gethash(F[p] - i + 1, F[p]) * pw[s.size() - i] +
          gethash(1, s.size() - i);
      c1 += (tmp == hsh);
    }
    for (int i = s.size(); i <= F[p + 2]; i++) {
      pair<long long, long long> tmp = gethash(i - s.size() + 1, i);
      if (i <= F[p + 1]) d1 += (tmp == hsh);
      d2 += (tmp == hsh);
    }
    for (int i = 1; i <= s.size() - 1; i++) {
      pair<long long, long long> tmp =
          gethash(F[p + 1] - i + 1, F[p + 1]) * pw[s.size() - i] +
          gethash(1, s.size() - i);
      c2 += (tmp == hsh);
    }
  work:
    p++;
    if (n < p || (c1 == 0 && c2 == 0)) {
      printf("0\n");
    } else {
      long long t = (n - p) / 2ll;
      mat A;
      A.e[0][0] = d2;
      A.e[1][0] = d1;
      A.e[2][0] = 1;
      T.e[0][2] = c1 + c2;
      T.e[1][2] = c1;
      A = (T ^ t) * A;
      int ans = A.e[(n - p) % 2 == 0][0];
      printf("%d\n", ans);
    }
  }
}