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 P = 1e9 + 7;
string q;
long long n, N;
int Next[5000005], Q;
inline void up(int &x) {
  if (x >= P) x -= P;
}
struct matrix {
  int p[3][3], n, m;
  inline matrix operator*(const matrix &b) const {
    matrix c;
    c.n = n;
    c.m = b.m;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < b.m; j++) {
        c.p[i][j] = 0;
        for (int k = 0; k < m; k++)
          up(c.p[i][j] += 1ll * p[i][k] * b.p[k][j] % P);
      }
    return c;
  }
} one, fib, ret, A, O, E, zero;
int Find(string a, string b, int L, int R) {
  if (L > R) return 0;
  Next[0] = -1;
  int ret = 0;
  for (int i = 1, j = -1; i < b.length(); i++) {
    for (; j >= 0 && b[j + 1] != b[i]; j = Next[j])
      ;
    Next[i] = (j += b[j + 1] == b[i]);
  }
  for (int i = 0, j = -1; i < a.length(); i++) {
    for (; j >= 0 && b[j + 1] != a[i]; j = Next[j])
      ;
    j += (b[j + 1] == a[i]);
    if (j + 1 == b.length()) ret += (i >= L && i <= R), j = Next[j];
  }
  return ret;
}
void solve() {
  cin >> q;
  reverse(q.begin(), q.end());
  string a = "a", b = "b";
  while (a.length() < q.length()) a = a + b, swap(a, b), n--;
  ret.p[1][0] = ret.p[0][0] = 0;
  if (n > 2) {
    ret = A = fib;
    for (long long m = n - 3; m; m >>= 1, A = A * A)
      if (m & 1) ret = ret * A;
  } else
    ret.p[0][1] = (n == 1), ret.p[1][1] = (n == 2);
  int ans = 0;
  up(ans += 1ll * ret.p[0][1] * Find(a, q, 0, a.length() - 1) % P);
  up(ans += 1ll * ret.p[1][1] * Find(b, q, 0, b.length() - 1) % P);
  up(ans += 1ll * ret.p[1][0] *
            Find(a + b, q, a.length(), a.length() + q.length() - 2) % P);
  if (n > 3) {
    n -= 3;
    ret = zero;
    ret.n = 1;
    ret.m = 3;
    ret.p[0][2] = 1;
    A = E * O;
    for (long long m = n / 2; m; m >>= 1, A = A * A)
      if (m & 1) ret = ret * A;
    if (n & 1) ret = ret * E;
    up(ans += 1ll * ret.p[0][1] *
              Find(b + a, q, b.length(), b.length() + q.length() - 2) % P);
    up(ans += 1ll * ret.p[0][0] *
              Find(b + b, q, b.length(), b.length() + q.length() - 2) % P);
  }
  printf("%d\n", ans);
}
int main() {
  one.n = one.m = fib.n = fib.m = 2;
  fib.p[0][1] = fib.p[1][0] = fib.p[1][1] = 1;
  one.p[0][0] = one.p[1][1] = 1;
  O.n = O.m = 3;
  O.p[0][1] = O.p[1][0] = O.p[1][1] = O.p[2][2] = 1;
  E = O;
  E.p[2][1] = 1;
  scanf("%I64d%d", &N, &Q);
  while (Q--) n = N, solve();
}