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 long long mod = 1e9 + 7;
const int N = 1e6 + 10;
string s[101];
string x;
long long dp[101];
long long n;
int m;
int fail[N];
struct matrix {
  long long v[4][4];
  matrix() {
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++) v[i][j] = 0;
  }
  matrix(long long u[4][4]) {
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++) v[i][j] = u[i][j];
  }
  matrix operator*(const matrix a) const {
    matrix ans;
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++)
        for (int k = 0; k < 4; k++) {
          ans.v[i][j] += (v[i][k] * a.v[k][j]);
          ans.v[i][j] = (ans.v[i][j] + mod) % mod;
        }
    return ans;
  }
  void setunit() {
    for (int i = 0; i < 4; i++) v[i][i] = 1;
  }
};
long long mtx[4][4] = {
    {1, 2, -1, -1},
    {1, 0, 0, 0},
    {0, 1, 0, 0},
    {0, 0, 1, 0},
};
matrix calc(long long i) {
  matrix tmp(mtx);
  matrix ans;
  ans.setunit();
  while (i) {
    if (i & 1ll) ans = tmp * ans;
    tmp = tmp * tmp;
    i = i / 2ll;
  }
  return ans;
}
long long kmp(int p) {
  int m = x.length(), n = s[p].length();
  if (m > n) return 0;
  for (int i = 1, j = fail[0] = -1; i < m; i++) {
    while (j >= 0 && x[j + 1] != x[i]) j = fail[j];
    if (x[j + 1] == x[i]) j++;
    fail[i] = j;
  }
  int ans = 0;
  for (int i = 0, j = -1; i < n; i++) {
    while (j >= 0 && x[j + 1] != s[p][i]) j = fail[j];
    if (x[j + 1] == s[p][i]) j++;
    if (j == m - 1) {
      ans++;
      j = fail[j];
    }
  }
  return (long long)ans;
}
long long calc(int a, int b) {
  string p = s[a] + s[b];
  int s1 = s[a].length();
  int m = x.length(), n = p.length();
  if (m > n) return 0;
  for (int i = 1, j = fail[0] = -1; i < m; i++) {
    while (j >= 0 && x[j + 1] != x[i]) j = fail[j];
    if (x[j + 1] == x[i]) j++;
    fail[i] = j;
  }
  int ans = 0;
  for (int i = 0, j = -1; i < n; i++) {
    while (j >= 0 && x[j + 1] != p[i]) j = fail[j];
    if (x[j + 1] == p[i]) j++;
    if (j == m - 1) {
      if ((i - m + 1 < s1) && (i + 1) > s1) ans++;
      j = fail[j];
    }
  }
  return (long long)ans;
}
int main() {
  s[1] = "a";
  s[2] = "b";
  for (int i = 3; i <= 30; i++) s[i] = s[i - 1] + s[i - 2];
  cin >> n >> m;
  while (m--) {
    cin >> x;
    if (n <= 25) {
      cout << kmp((int)n) << endl;
      continue;
    }
    int len = x.length();
    int r = 1;
    while (s[r].length() < len) r++;
    long long add1 = calc(r, r), add2 = calc(r + 1, r);
    for (int i = 1; i <= r + 2; i++) dp[i] = kmp(i);
    dp[r + 3] = dp[r + 2] + dp[r + 1] + add1;
    dp[r + 4] = dp[r + 3] + dp[r + 2] + add2;
    dp[r + 5] = dp[r + 4] + dp[r + 3] + add1;
    dp[r + 6] = dp[r + 5] + dp[r + 4] + add2;
    if (n <= r + 6) {
      cout << dp[n] << endl;
      continue;
    }
    matrix mat = calc(n - r - 6);
    long long ans = 0;
    for (int i = 0; i < 4; i++) ans += mat.v[0][i] * dp[r + 6 - i];
    ans = ans % mod;
    while (ans < 0) ans += mod;
    cout << ans << endl;
  }
}