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 inf = 1000000000;
const int MOD = 1000000007;
struct matrix {
  int mas[6][6];
  int sz;
};
matrix operator*(matrix &a, matrix &b) {
  matrix c;
  c.sz = a.sz;
  for (int i = 1; i <= c.sz; ++i)
    for (int j = 1; j <= c.sz; ++j) {
      c.mas[i][j] = 0;
      for (int k = 1; k <= c.sz; ++k)
        c.mas[i][j] =
            (c.mas[i][j] + (unsigned long long)a.mas[i][k] * b.mas[k][j]) % MOD;
    }
  return c;
}
matrix pow(matrix a, unsigned long long times) {
  matrix c;
  c.sz = a.sz;
  for (int i = 1; i <= c.sz; ++i)
    for (int j = 1; j <= c.sz; ++j) c.mas[i][j] = (i == j);
  while (times) {
    if (times & 1) c = c * a;
    a = a * a;
    times /= 2;
  }
  return c;
}
int pr[2000000];
int cnt(string a, string b) {
  string cur = a + "c" + b;
  pr[0] = 0;
  int ans = 0;
  for (int i = 1; i <= (int)(cur).size() - 1; ++i) {
    int j = pr[i - 1];
    while (j && cur[i] != cur[j]) j = pr[j - 1];
    if (cur[i] == cur[j]) ++j;
    pr[i] = j;
    if (i > (int)(a).size() && pr[i] >= (int)(a).size()) ++ans;
  }
  return ans;
}
int over(string f1, string f2, string s) {
  string cur = s + "c" + f1 + f2;
  pr[0] = 0;
  int ans = 0;
  for (int i = 1; i <= (int)(cur).size() - 1; ++i) {
    int j = pr[i - 1];
    while (j && cur[i] != cur[j]) j = pr[j - 1];
    if (cur[i] == cur[j]) ++j;
    pr[i] = j;
    int id = i - (int)(s).size() - 1;
    if (id >= (int)(f1).size() && id - (int)(s).size() + 1 < (int)(f1).size() &&
        pr[i] >= (int)(s).size())
      ++ans;
    if (id - (int)(s).size() + 1 >= (int)(f1).size()) break;
  }
  return ans;
}
int id;
string f[1000];
unsigned long long get_answer(unsigned long long n, string &s) {
  unsigned long long v = 2;
  while ((int)(f[v]).size() <= (int)(s).size() ||
         (int)(f[v - 1]).size() <= (int)(s).size())
    ++v;
  if (v >= n) return cnt(s, f[n]);
  string F = f[v] + f[v - 1];
  unsigned long long k1 = over(f[v], f[v - 1], s), k2 = over(F, f[v], s),
                     b = cnt(s, f[v]), a = cnt(s, f[v - 1]);
  if (n - v < 0) {
    for (int i = v + 1; i <= n; ++i) {
      unsigned long long c = b;
      if (i % 2 == v % 2)
        b = (0LL + b + a + k2) % MOD;
      else
        b = (0LL + b + a + k1) % MOD;
      a = c;
    }
    return b;
  }
  matrix G;
  G.sz = 4;
  memset(G.mas, 0, sizeof(G.mas));
  G.mas[1][1] = 1;
  G.mas[2][2] = 1;
  G.mas[1][3] = 1;
  G.mas[3][3] = 1;
  G.mas[4][3] = 1;
  G.mas[1][4] = 1;
  G.mas[2][4] = 1;
  G.mas[3][4] = 1;
  G.mas[4][4] = 2;
  unsigned long long dif = n - v;
  G = pow(G, dif / 2);
  unsigned long long aa, bb;
  unsigned long long tmp = ((unsigned long long)k1 * G.mas[1][4]) % MOD +
                           ((unsigned long long)k2 * G.mas[2][4]) % MOD +
                           ((unsigned long long)a * G.mas[3][4]) % MOD +
                           ((unsigned long long)b * G.mas[4][4]) % MOD;
  tmp %= MOD;
  bb = tmp;
  tmp = ((unsigned long long)k1 * G.mas[1][3]) % MOD +
        ((unsigned long long)k2 * G.mas[2][3]) % MOD +
        ((unsigned long long)a * G.mas[3][3]) % MOD +
        ((unsigned long long)b * G.mas[4][3]) % MOD;
  tmp %= MOD;
  aa = tmp;
  if (dif % 2 == 0) {
    return bb;
  } else {
    return (0LL + aa + bb + k1) % MOD;
  }
}
string s;
int main() {
  f[1] = "a";
  f[2] = "b";
  id = 2;
  for (;;) {
    ++id;
    f[id] = f[id - 1] + f[id - 2];
    if ((int)(f[id]).size() > 100000 && (int)(f[id - 1]).size() > 100000) break;
  }
  unsigned long long n, query;
  cin >> n >> query;
  while (query--) {
    cin >> s;
    cout << get_answer(n, s) << endl;
  }
}