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 MAXN = 2e6 + 5, M = 4e5;
const int Mo = 1e9 + 7;
struct Matrix {
  int a[4][4];
} mat, ans, d;
char fib[32][MAXN], s[MAXN], a[MAXN], b[MAXN], ab[MAXN], ba[MAXN], bb[MAXN];
int len[32], t, m, lens, nxt[MAXN], p[MAXN], sum[MAXN];
long long n;
void mul(Matrix &c, Matrix &a, Matrix &b) {
  Matrix d;
  memset(d.a, 0, sizeof d.a);
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++)
      for (int k = 0; k < 4; k++)
        d.a[i][j] = ((long long)d.a[i][j] + 1ll * a.a[i][k] * b.a[k][j]) % Mo;
  memcpy(c.a, d.a, sizeof c.a);
}
void pushs(char *a, char *b) {
  int len = strlen(b + 1);
  for (int i = 1; i <= len; i++) a[i] = b[i];
  a[len + 1] = a[0];
}
void add(char *a, char *b, char *c) {
  int lenb = strlen(b + 1);
  for (int i = 1; i <= lenb; i++) a[i] = b[i];
  int lenc = strlen(c + 1);
  for (int i = lenb + 1; i <= lenb + lenc; i++) a[i] = c[i - lenb];
  a[lenb + lenc + 1] = a[0];
}
int find(char *t, char *s) {
  int lent = strlen(t + 1), lens = strlen(s + 1);
  int j = 0, ans = 0;
  for (int i = 2; i <= lens; i++) {
    while (j && s[j + 1] != s[i]) j = nxt[j];
    if (s[j + 1] == s[i]) j++;
    nxt[i] = j;
  }
  j = 0;
  for (int i = 1; i <= lent; i++) {
    while (j && s[j + 1] != t[i]) j = nxt[j];
    if (s[j + 1] == t[i]) j++;
    if (j == lens) ans++, j = nxt[j];
  }
  return ans;
}
void solve() {
  scanf("%s", s + 1);
  lens = strlen(s + 1);
  if (n <= m) {
    printf("%d\n", find(fib[n], s));
    return;
  }
  int num;
  for (int i = 1; i <= m; i++) {
    if (lens <= len[i]) {
      pushs(a, fib[i]);
      pushs(b, fib[i + 1]);
      num = i;
      break;
    }
  }
  add(ab, a, b);
  add(ba, b, a);
  add(bb, b, b);
  int num_a = find(a, s);
  int num_b = find(b, s);
  int num_ab = find(ab, s) - num_a - num_b;
  int num_ba = find(ba, s) - num_b - num_a;
  int num_bb = find(bb, s) - num_b - num_b;
  memset(mat.a, 0, sizeof mat.a);
  memset(ans.a, 0, sizeof ans.a);
  for (int i = 0; i < 4; i++) ans.a[i][i] = 1;
  mat.a[1][0] = 1;
  mat.a[0][1] = mat.a[1][1] = 1;
  mat.a[0][2] = mat.a[3][2] = 1;
  mat.a[2][3] = 1;
  long long y = n - num - 1;
  for (; y; y >>= 1, mul(mat, mat, mat))
    if (y & 1) mul(ans, ans, mat);
  int sum = 0;
  (sum += 1ll * ans.a[1][0] * (num_a + num_ba) % Mo) %= Mo;
  (sum += 1ll * ans.a[1][1] * num_b % Mo) %= Mo;
  (sum += 1ll * ans.a[1][2] * num_ab % Mo) %= Mo;
  (sum += 1ll * ans.a[1][3] * num_bb % Mo) %= Mo;
  printf("%d\n", sum);
}
int main() {
  int t;
  scanf("%I64d%d", &n, &t);
  len[1] = len[2] = 1;
  fib[1][1] = 'a', fib[2][1] = 'b';
  for (int i = 3; i < 30; i++) {
    if (len[i - 1] + len[i - 2] > M) break;
    add(fib[i], fib[i - 1], fib[i - 2]);
    len[i] = len[i - 1] + len[i - 2];
    m = i;
  }
  for (int i = 1; i <= t; i++) solve();
}