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 = 1e5 + 10;
const int mod = 1e9 + 7;
long long n, m;
int nex[N];
string tmp, s[30];
struct Matrix {
  int n, m;
  int a[5][5];
} u, v, f;
Matrix operator*(Matrix x, Matrix y) {
  Matrix z;
  z.n = x.n;
  z.m = y.m;
  for (int i = 1; i <= x.n; i++) {
    for (int j = 1; j <= y.m; j++) {
      int ans = 0;
      for (int k = 1; k <= x.m; k++) {
        ans += 1LL * x.a[i][k] * y.a[k][j] % mod;
        if (ans >= mod) ans -= mod;
      }
      z.a[i][j] = ans;
    }
  }
  return z;
}
Matrix operator^(Matrix x, long long p) {
  Matrix ans;
  ans.n = ans.m = x.n;
  memset(ans.a, 0, sizeof(ans.a));
  for (int i = 1; i <= x.n; i++) ans.a[i][i] = 1;
  while (p) {
    if (p & 1) ans = ans * x;
    x = x * x;
    p >>= 1;
  }
  return ans;
}
void Kmp_init() {
  int k = -1, j = 0;
  nex[0] = -1;
  int plen = tmp.size();
  while (j < plen) {
    while (k != -1 && tmp[k] != tmp[j]) k = nex[k];
    nex[++j] = ++k;
  }
}
int Kmp(string &s) {
  int j = 0, k = 0, ans = 0, slen = s.size(), plen = tmp.size();
  while (j < slen) {
    while (k != -1 && s[j] != tmp[k]) k = nex[k];
    j++;
    k++;
    if (k == plen) ans++, k = nex[k];
  }
  return ans;
}
void Solve() {
  cin >> tmp;
  int x;
  for (x = 1; s[x].size() < tmp.size(); x++)
    ;
  if (x > n) return (void)(puts("0"));
  Kmp_init();
  int a = Kmp(s[x]), b = Kmp(s[x + 1]), c = Kmp(s[x + 2]), d = Kmp(s[x + 3]);
  d = d - b - c;
  c = c - a - b;
  if (x == n) return (void)(printf("%d\n", a));
  if (x == n + 1) return (void)(printf("%d\n", b));
  long long k = n - x - 1;
  f.n = 1;
  f.m = 3;
  f.a[1][1] = a;
  f.a[1][2] = b;
  f.a[1][3] = 1;
  u.n = u.m = 3;
  u.a[1][1] = 0;
  u.a[1][2] = 1;
  u.a[1][3] = 0;
  u.a[2][1] = 1;
  u.a[2][2] = 1;
  u.a[2][3] = 0;
  u.a[3][1] = 0;
  u.a[3][2] = c;
  u.a[3][3] = 1;
  v.n = v.m = 3;
  v.a[1][1] = 0;
  v.a[1][2] = 1;
  v.a[1][3] = 0;
  v.a[2][1] = 1;
  v.a[2][2] = 1;
  v.a[2][3] = 0;
  v.a[3][1] = 0;
  v.a[3][2] = d;
  v.a[3][3] = 1;
  Matrix t = u * v;
  t = t ^ (k / 2);
  if (k & 1) t = t * u;
  f = f * t;
  printf("%d\n", f.a[1][2]);
}
int main() {
  scanf("%lld%lld", &n, &m);
  s[1] = "a";
  s[2] = "b";
  for (int i = 3; i <= 29; i++) s[i] = s[i - 1] + s[i - 2];
  while (m--) Solve();
  return 0;
}