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;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + int(ch - '0');
  return x * f;
}
const int MAXN = 2e5 + 5, P = 1e9 + 7;
int pls(int a, int b) { return a + b < P ? a + b : a + b - P; }
int mns(int a, int b) { return a < b ? a + P - b : a - b; }
int mul(int a, int b) { return 1ll * a * b % P; }
long long k;
int m, nxt[MAXN];
string s[30], t;
void kmp_init(const string& s) {
  nxt[0] = -1;
  int n = s.length();
  for (int i = 1, j = -1; i < n; i++) {
    while (j != -1 && s[j + 1] != s[i]) j = nxt[j];
    if (s[j + 1] == s[i]) j++;
    nxt[i] = j;
  }
}
int kmp_count(const string& s, const string& t) {
  int ans = 0;
  int sn = s.length(), tn = t.length();
  for (int i = 0, j = -1; i < tn; i++) {
    while (j != -1 && s[j + 1] != t[i]) j = nxt[j];
    if (s[j + 1] == t[i]) j++;
    if (j == sn - 1) {
      ans++;
      j = nxt[j];
    }
  }
  return ans;
}
struct Matrix {
  int A[3][3];
  void clear() {
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++) A[i][j] = 0;
  }
  void setU() {
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++) A[i][j] = (i == j);
  }
  int* operator[](int k) { return A[k]; }
  const int* operator[](int k) const { return A[k]; }
  Matrix operator*(const Matrix& B) const {
    Matrix ret;
    ret.clear();
    for (int i = 0; i < 3; i++)
      for (int k = 0; k < 3; k++)
        for (int j = 0; j < 3; j++)
          ret[i][j] = pls(ret[i][j], mul(A[i][k], B[k][j]));
    return ret;
  }
} T1, T2, D, F;
Matrix qpow(Matrix a, long long n) {
  Matrix ret;
  ret.setU();
  for (; n; n >>= 1, a = a * a)
    if (n & 1) ret = ret * a;
  return ret;
}
void solve() {
  cin >> t;
  int n = t.length();
  kmp_init(t);
  int bas = 1;
  for (; s[bas].length() <= n; bas++)
    ;
  long long a = kmp_count(t, s[bas]), b = kmp_count(t, s[bas + 1]),
            c = kmp_count(t, s[bas + 2]), d = kmp_count(t, s[bas + 3]);
  long long p = c - a - b, q = d - b - c;
  F.clear();
  T1.clear(), T2.clear(), D.clear();
  F[0][0] = b;
  F[1][0] = a;
  F[2][0] = 1;
  T1[0][0] = 1, T1[0][1] = 1, T1[0][2] = q;
  T1[1][0] = 1;
  T1[2][2] = 1;
  T2[0][0] = 1;
  T2[0][1] = 1;
  T2[0][2] = p;
  T2[1][0] = 1;
  T2[2][2] = 1;
  D = T1 * T2;
  F = qpow(D, (k - bas - 1) / 2) * F;
  if ((k - bas) % 2 == 0) F = T2 * F;
  cout << F[0][0] << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> k >> m;
  s[1] = "a", s[2] = "b";
  for (int i = 3; i <= 29; i++) s[i] = s[i - 1] + s[i - 2];
  if (k <= 29) {
    while (m--) {
      cin >> t;
      kmp_init(t);
      cout << kmp_count(t, s[k]) << endl;
    }
  } else {
    while (m--) solve();
  }
  return 0;
}