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 = 1e5 + 5;
const int mod = 1e9 + 7;
string s, t;
int nxt[maxn], F[30];
string F1, F2, Fs[30];
struct matrix_base {
  int a[2][2];
  matrix_base() { memset(a, 0, sizeof a); }
  void mul() {
    int b[2][2];
    memset(b, 0, sizeof b);
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++)
        for (int k = 0; k < 2; k++)
          b[i][j] = ((long long)a[i][k] * a[k][j] % mod + b[i][j]) % mod;
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++) a[i][j] = b[i][j];
  }
} bm;
struct matrix_ans {
  int a[2];
  matrix_ans() { memset(a, 0, sizeof a); }
  void mul() {
    int b[2];
    memset(b, 0, sizeof b);
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++)
        b[i] = ((long long)a[j] * bm.a[j][i] % mod + b[i]) % mod;
    for (int i = 0; i < 2; i++) a[i] = b[i];
  }
} ans;
int get_num(const string &a) {
  int res = 0, len = s.length();
  for (int i = 0, j = 0, Len = a.length(); i < Len; i++) {
    while (j >= 0 && t[j + 1] != a[i]) j = nxt[j];
    if (++j == len) res++, j = nxt[j];
  }
  return res;
}
int Main(long long n) {
  cin >> s;
  int len = s.length();
  t = "%" + s;
  nxt[0] = -1;
  for (int i = 2, j = 0; i <= len; i++) {
    while (j >= 0 && t[j + 1] != t[i]) j = nxt[j];
    nxt[i] = ++j;
  }
  int base = 0;
  F[1] = F[2] = 1;
  Fs[1] = "a";
  Fs[2] = "b";
  for (int 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 (int i = 0; i < len - 1; i++) a += Fs[base - 1][i];
  for (int i = Fs[base - 1].length() - (len - 1), Len = Fs[base - 1].length();
       i < Len; i++)
    b += Fs[base - 1][i];
  for (int i = Fs[base].length() - (len - 1), Len = Fs[base].length(); i < Len;
       i++)
    c += Fs[base][i];
  int vc = get_num(c + a);
  int vb = get_num(b + a);
  if (n - base <= 1) return get_num(Fs[n]);
  ans.a[0] = 0, ans.a[1] = 1;
  bm.a[0][0] = 0;
  bm.a[0][1] = bm.a[1][0] = bm.a[1][1] = 1;
  long long y = n - base;
  for (int i = 0; (1LL << i) <= y; i++, bm.mul())
    if (y & (1LL << i)) ans.mul();
  int B = ans.a[0] - (y & 1);
  ans.a[0] = 0, ans.a[1] = 1;
  bm.a[0][0] = 0;
  bm.a[0][1] = bm.a[1][0] = bm.a[1][1] = 1;
  for (int i = 0; (1LL << i) <= y - 1; i++, bm.mul())
    if ((y - 1) & (1LL << i)) ans.mul();
  int C = ans.a[0] - ((y - 1) & 1);
  ans.a[0] = get_num(Fs[base]);
  ans.a[1] = get_num(Fs[base] + Fs[base - 1]);
  bm.a[0][0] = 0;
  bm.a[0][1] = bm.a[1][0] = bm.a[1][1] = 1;
  for (int i = 0; (1LL << i) <= y; i++, bm.mul())
    if (y & (1LL << i)) ans.mul();
  int res = ans.a[0];
  res = ((long long)B * vb % mod + (long long)C * vc % mod + res) % mod;
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  while (m--) cout << Main(n) << '\n';
  return 0;
}