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 mo = (int)1e9 + 7;
struct node {
  long long a[4][4];
  void init() { memset(a, 0, sizeof(a)); }
  void init1() {
    for (int i = 0; i < 4; ++i) a[i][i] = 1;
  }
};
int p[100010];
node multiply(node a, node b) {
  node res;
  res.init();
  for (int i = 0; i < 4; ++i)
    for (int j = 0; j < 4; ++j) {
      long long t = 0;
      for (int k = 0; k < 4; ++k) t += 1LL * a.a[i][k] * b.a[k][j];
      res.a[i][j] = t % mo;
    }
  return res;
}
node ksm(node a, long long k) {
  node res;
  res.init1();
  if (k == 1) return a;
  if (k == 0) return res;
  res = ksm(a, k >> 1), res = multiply(res, res);
  if (k & 1) res = multiply(res, a);
  return res;
}
int calculate(string &a, string &b) {
  if (b.length() > a.length()) return 0;
  int res = 0;
  p[0] = -1;
  for (int i = 0, j = 0; b[i] != 0; i++) {
    j = p[i];
    while (j >= 0 && b[i] != b[j]) j = p[j];
    p[i + 1] = j + 1;
  }
  for (int i = 0, j = 0; a[i] != 0; i++) {
    while (j >= 0 && a[i] != b[j]) j = p[j];
    j++;
    if (j == b.length()) res++, j = p[j];
  }
  return res;
}
int query(long long p, string &q) {
  if (p == 1) return q == "a" ? 1 : 0;
  if (p == 2) return q == "b" ? 1 : 0;
  string s1 = "a", s2 = "b";
  string s = "b";
  p -= 2;
  for (; p && s1.length() < q.length(); p--, s1 = s2, s2 = s) s = s2 + s1;
  int f1 = calculate(s1, q), f2 = calculate(s, q);
  if (!p) return f2;
  int g1, g2;
  s = s2.substr(s2.length() - q.length() + 1, q.length() - 1) +
      s2.substr(0, q.length() - 1);
  g1 = calculate(s, q);
  s = s1.substr(s1.size() - q.size() + 1, q.size() - 1) +
      s1.substr(0, q.size() - 1);
  g2 = calculate(s, q);
  node m1, m2;
  m1.init();
  m2.init();
  m1.a[0][0] = m1.a[0][1] = m1.a[0][2] = m1.a[1][0] = m1.a[2][2] = m1.a[3][3] =
      1;
  m2.a[0][0] = m2.a[0][1] = m2.a[0][3] = m2.a[1][0] = m2.a[2][2] = m2.a[3][3] =
      1;
  node t = multiply(m2, m1), res;
  bool flag = 0;
  if (p % 2) res = m1, flag = 1;
  for (p /= 2; p; p >>= 1, t = multiply(t, t))
    if (p & 1) {
      if (!flag)
        res = t, flag = 1;
      else
        res = multiply(res, t);
    }
  return (int)1LL *
         (1LL * res.a[0][0] * f2 + 1LL * res.a[0][1] * f1 +
          1LL * res.a[0][2] * g1 + 1LL * res.a[0][3] * g2) %
         mo;
}
string s;
int main() {
  long long n, m;
  scanf("%I64d%I64d", &n, &m);
  while (m--) {
    cin >> s;
    printf("%d\n", query(n, s));
  }
}