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;
template <typename T>
void chkmax(T &x, T y) {
  x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
  x = x > y ? y : x;
}
const int INF = (1ll << 30);
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = 0;
  } while (ch > '9' || ch < '0');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  x = f ? x : -x;
}
template <typename T>
void write(T x) {
  if (x < 0) x = ~x + 1, putchar('-');
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const long long N = 2e5 + 7;
const long long mod = 1e9 + 7;
string f[N], tp, a, b, c;
long long n, m, cnt, lens, len[N], nxt[N];
char ch[N];
struct Matrix {
  long long num[3][3];
  inline void print() {
    for (long long i = 0; i < 2; i++) {
      for (long long j = 0; j < 2; j++) {
        printf("%lld ", num[i][j]);
      }
      puts("");
    }
  }
  inline void init() {
    for (long long i = 0; i < 2; i++) {
      for (long long j = 0; j < 2; j++) {
        num[i][j] = 0;
      }
    }
  }
} ans, base;
Matrix operator*(Matrix a, Matrix b) {
  Matrix c;
  c.init();
  for (long long i = 0; i < 2; i++) {
    for (long long j = 0; j < 2; j++) {
      for (long long k = 0; k < 2; k++) {
        c.num[i][j] =
            (c.num[i][j] + 1ll * a.num[i][k] * b.num[k][j] % mod) % mod;
      }
    }
  }
  return c;
}
inline void qpow(long long b) {
  if (b < 0) return;
  base.init();
  base.num[0][0] = base.num[0][1] = base.num[1][0] = 1;
  while (b) {
    if (b & 1) ans = ans * base;
    base = base * base;
    b >>= 1;
  }
}
inline long long fib(long long x) {
  ans.num[0][0] = ans.num[0][1] = 1;
  if (x == 0) return 0;
  qpow(x - 2);
  return ans.num[0][0];
}
inline void init() {
  f[1] = 'a';
  f[2] = 'b';
  for (long long i = 3;; i++) {
    f[i] = f[i - 1] + f[i - 2];
    len[i] = f[i].length();
    cnt = i;
    if (len[i - 1] >= N - 7) break;
  }
  base.num[0][0] = base.num[0][1] = base.num[1][0] = 1;
}
inline long long get() {
  long long ret = 0;
  for (long long i = 0, j = 0, le = tp.length(); i < le; i++) {
    while (j >= 0 && ch[j + 1] != tp[i]) j = nxt[j];
    j++;
    if (j == lens) ret++, j = nxt[j];
  }
  return ret;
}
inline long long solve() {
  nxt[0] = -1;
  lens = strlen(ch + 1);
  for (long long i = 2, j = 0; i <= lens; i++) {
    while (j >= 0 && ch[j + 1] != ch[i]) j = nxt[j];
    j++;
    nxt[i] = j;
  }
  long long p = lower_bound(len + 1, len + cnt + 1, lens) - len;
  ++p;
  a = f[p].substr(0, lens - 1);
  b = f[p].substr(len[p] - lens + 1, lens - 1);
  c = f[p + 1].substr(len[p + 1] - lens + 1, lens - 1);
  if (n <= p + 1) {
    tp = f[n];
    return get();
  }
  long long n0, n1, n2, n3;
  long long pos = n - p, ret = 0;
  tp = c + a;
  n0 = get();
  tp = b + a;
  n1 = get();
  tp = f[p];
  n2 = get();
  tp = f[p + 1];
  n3 = get();
  ret = (ret + 1ll * (fib(pos) - (pos & 1)) * n0 % mod) % mod;
  ret = (ret + 1ll * (fib(pos - 1) - 1 + (pos & 1)) * n1 % mod) % mod;
  ans.init();
  ans.num[0][0] = n3;
  ans.num[0][1] = n2;
  qpow(pos - 1);
  ret = (ret + ans.num[0][0]) % mod;
  return ret;
}
signed main() {
  read(n);
  read(m);
  init();
  for (long long i = 1; i <= m; i++) {
    scanf("%s", ch + 1);
    printf("%lld\n", solve());
  }
  return 0;
}