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 C = 30;
bool X[33][1500010];
int P[1500010];
long long k, m, F[33], G[11111];
string S;
struct Mat {
  long long X[3][3];
};
Mat operator*(Mat A, Mat B) {
  Mat Ans;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      long long tmp = 0;
      for (int k = 0; k < 3; k++)
        tmp = (tmp + A.X[i][k] * B.X[k][j]) % 1000000007;
      Ans.X[i][j] = tmp;
    }
  return Ans;
}
int match(bool *X, int l, int r) {
  int t = -1, ans = 0;
  for (int i = l; i <= r; i++) {
    while (t != -1 && S[t + 1] != X[i]) t = P[t];
    if (S[t + 1] == X[i]) t++;
    if (t == S.size() - 1) {
      ans++;
      t = P[t];
    }
  }
  return ans;
}
int main() {
  scanf("%lld%lld", &k, &m);
  X[1][1] = 0;
  X[2][1] = 1;
  F[1] = (F[2] = 1);
  for (int i = 3; i <= C; i++) {
    F[i] = F[i - 1] + F[i - 2];
    for (int j = 1; j <= F[i - 1]; j++) X[i][j] = X[i - 1][j];
    for (int j = 1; j <= F[i - 2]; j++) X[i][j + F[i - 1]] = X[i - 2][j];
  }
  for (int i = 1; i <= C; i++)
    for (int j = 1; j <= F[i]; j++) X[i][j + F[i]] = X[i][j];
  while (m--) {
    cin >> S;
    int K = 0;
    while (F[K] < 3 * S.size()) K++;
    P[0] = -1;
    int t = -1;
    for (int i = 0; i < S.size(); i++) S[i] -= 'a';
    for (int i = 1; i < S.size(); i++) {
      while (t != -1 && S[t + 1] != S[i]) t = P[t];
      if (S[t + 1] == S[i]) t++;
      P[i] = t;
    }
    for (int i = 1; i <= K; i++) G[i] = match(X[i], 1, F[i]);
    long long A =
        match(X[K - 1], F[K - 1] - S.size() + 2, F[K - 1] + S.size() - 1);
    long long B = match(X[K], F[K] - S.size() + 2, F[K] + S.size() - 1);
    if (k <= K)
      printf("%lld\n", ((G[k] % 1000000007 + 1000000007) % 1000000007));
    else {
      long long s = (k - K + 1) / 2;
      Mat ori, ans;
      ori.X[0][0] = 2;
      ori.X[0][1] = 1;
      ori.X[0][2] = (A + B) % 1000000007;
      ori.X[1][0] = 1;
      ori.X[1][1] = 1;
      ori.X[1][2] = B;
      ori.X[2][0] = 0;
      ori.X[2][1] = 0;
      ori.X[2][2] = 1;
      memset(ans.X, 0, sizeof ans.X);
      for (int i = 0; i < 3; i++) ans.X[i][i] = 1;
      while (s) {
        if (s & 1) ans = ans * ori;
        ori = ori * ori;
        s >>= 1;
      }
      int b = (k - K) % 2;
      printf("%lld\n",
             ((G[K] * ans.X[b][0] + G[K - 1] * ans.X[b][1] + ans.X[b][2]) %
                  1000000007 +
              1000000007) %
                 1000000007);
    }
  }
  return 0;
}