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 <class T>
void read(T &x) {
  x = 0;
  char c = getchar();
  long long f = 0;
  while (c < '0' || c > '9') f |= (c == '-'), c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  if (f) x = -x;
}
template <class T>
bool checkmax(T &a, T b) {
  return b > a ? a = b, 1 : 0;
}
template <class T>
bool checkmin(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
const long long mod = 1e9 + 7;
template <class T>
void my_add(T &a, T b) {
  a = a + b > mod ? a + b - mod : a + b;
}
template <class T>
void my_sub(T &a, T b) {
  a = a - b < 0 ? a - b + mod : a - b;
}
namespace moonpie {
const long long N = 1e5 + 5, mh = 998244353;
long long n, m, len, base, F[30], nxt[N];
string s, t, Fs[30], F1, F2;
long long get_num(string a) {
  long long res = 0;
  for (long long i = 0, j = 0; i < a.length(); ++i) {
    while (j >= 0 && t[j + 1] != a[i]) j = nxt[j];
    if (++j == len) ++res, j = nxt[j];
  }
  return res;
}
struct matrix_base {
  long long ma[2][2];
} bm;
struct matrix_ans {
  long long ma[2];
} ans;
inline void mul_base() {
  matrix_base res;
  memset(res.ma, 0, sizeof(res.ma));
  for (long long i = 0; i < 2; ++i)
    for (long long j = 0; j < 2; ++j)
      for (long long k = 0; k < 2; ++k)
        my_add(res.ma[i][j], bm.ma[i][k] * bm.ma[k][j] % mod);
  bm = res;
}
inline void mul_ans() {
  matrix_ans res;
  memset(res.ma, 0, sizeof(res.ma));
  for (long long i = 0; i < 2; ++i)
    for (long long j = 0; j < 2; ++j)
      my_add(res.ma[i], ans.ma[j] * bm.ma[j][i] % mod);
  ans = res;
}
long long calc() {
  len = s.length();
  t = "%" + s;
  nxt[0] = -1;
  for (long long i = 2, j = 0; i <= len; ++i) {
    while (j >= 0 && t[j + 1] != t[i]) j = nxt[j];
    nxt[i] = ++j;
  }
  F[1] = F[2] = 1;
  Fs[1] = "a";
  Fs[2] = "b";
  for (long long i = 3;; ++i) {
    if (F[i - 2] > len) {
      Fs[i] = Fs[i - 1] + Fs[i - 2];
      base = i - 1;
      break;
    }
    F[i] = F[i - 1] + F[i - 2];
    Fs[i] = Fs[i - 1] + Fs[i - 2];
  }
  string a, b, c;
  for (long long i = 0; i < len - 1; ++i) a += Fs[base - 1][i];
  for (long long i = Fs[base - 1].length() - (len - 1);
       i < Fs[base - 1].length(); ++i)
    b += Fs[base - 1][i];
  for (long long i = Fs[base].length() - (len - 1); i < Fs[base].length(); ++i)
    c += Fs[base][i];
  long long vc = get_num(c + a);
  long long vb = get_num(b + a);
  if (n - base <= 1) {
    return get_num(Fs[n]);
  }
  ans.ma[0] = 0;
  ans.ma[1] = 1;
  memset(bm.ma, 0, sizeof(bm.ma));
  bm.ma[0][1] = bm.ma[1][0] = bm.ma[1][1] = 1;
  long long y = n - base;
  for (long long i = 0; (1ll << i) <= y; ++i, mul_base())
    if (y & (1ll << i)) mul_ans();
  long long B = ans.ma[0] - (y % 2 == 1);
  ans.ma[0] = 0;
  ans.ma[1] = 1;
  memset(bm.ma, 0, sizeof(bm.ma));
  bm.ma[0][1] = bm.ma[1][0] = bm.ma[1][1] = 1;
  for (long long i = 0; (1ll << i) <= y - 1; ++i, mul_base())
    if ((y - 1) & (1ll << i)) mul_ans();
  long long C = ans.ma[0] - ((y - 1) % 2 == 1);
  ans.ma[0] = get_num(Fs[base]);
  ans.ma[1] = get_num(Fs[base] + Fs[base - 1]);
  memset(bm.ma, 0, sizeof(bm.ma));
  bm.ma[0][1] = bm.ma[1][0] = bm.ma[1][1] = 1;
  for (long long i = 0; (1ll << i) <= y; ++i, mul_base())
    if (y & (1ll << i)) mul_ans();
  return (ans.ma[0] + B * vb % mod + C * vc % mod) % mod;
}
void solve() {
  cin >> n >> m;
  for (long long i = 1; i <= m; ++i) {
    cin >> s;
    printf("%lld\n", calc());
  }
}
}  // namespace moonpie
signed main() {
  moonpie::solve();
  return 0;
}