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;
long long n, m;
bool debug = false;
int k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string s[30], tmp;
int nxt[3105];
struct Matrix {
  int n, m;
  long long a[5][5];
  Matrix() {}
  Matrix(int n, int m) : n(n), m(m) {}
  void init(long long num) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) a[i][j] = num;
  }
  Matrix operator*(Matrix b) {
    Matrix o = Matrix(n, b.m);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < b.m; j++) {
        o.a[i][j] = 0;
        for (int k = 0; k < m; k++) {
          o.a[i][j] = (o.a[i][j] + (a[i][k] * b.a[k][j]) % 1000000007);
        }
      }
    }
    return o;
  }
  Matrix pow(long long p) {
    Matrix o = Matrix(n, m);
    Matrix b = *this;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) o.a[i][j] = (i == j);
    while (p > 0) {
      if (p & 1) o = o * b;
      b = b * b;
      p >>= 1;
    }
    return o;
  }
};
void Kmp_init(string &str) {
  int k = -1, j = 0;
  nxt[0] = -1;
  int plen = (int)str.size();
  while (j < plen) {
    while (k != -1 && str[k] != str[j]) k = nxt[k];
    nxt[++j] = ++k;
  }
}
int Kmp(string &s, string &p) {
  int j = 0, k = 0, ans = 0, slen = (int)s.size(), plen = (int)p.size();
  while (j < slen) {
    while (k != -1 && s[j] != p[k]) k = nxt[k];
    j++;
    k++;
    if (k == plen) {
      ans++;
      k = nxt[k];
    }
  }
  return ans;
}
char cs[3105];
long long dd() {
  scanf("%s", cs);
  tmp = cs;
  int x;
  for (x = 1; s[x].size() < tmp.size(); x++)
    ;
  if (x > n) {
    return 0;
  }
  Kmp_init(tmp);
  int a = Kmp(s[x], tmp), b = Kmp(s[x + 1], tmp), c = Kmp(s[x + 2], tmp),
      d = Kmp(s[x + 3], tmp);
  d = d - c - b;
  c = c - b - a;
  if (x == n) return a;
  long long k = n - x - 1;
  Matrix f(1, 3);
  f.a[0][0] = a;
  f.a[0][1] = b;
  f.a[0][2] = 1;
  Matrix u(3, 3), v(3, 3);
  u.a[0][0] = 0;
  u.a[0][1] = 1;
  u.a[0][2] = 0;
  u.a[1][0] = 1;
  u.a[1][1] = 1;
  u.a[1][2] = 0;
  u.a[2][0] = 0;
  u.a[2][1] = c;
  u.a[2][2] = 1;
  v.a[0][0] = 0;
  v.a[0][1] = 1;
  v.a[0][2] = 0;
  v.a[1][0] = 1;
  v.a[1][1] = 1;
  v.a[1][2] = 0;
  v.a[2][0] = 0;
  v.a[2][1] = d;
  v.a[2][2] = 1;
  Matrix t = u * v;
  t = t.pow(k / 2);
  if (k & 1) t = t * u;
  f = f * t;
  return f.a[0][1];
}
int main() {
  scanf("%lld%lld", &n, &m);
  s[1] = "a";
  s[2] = "b";
  for (int i = 3; i <= 29; i++) s[i] = s[i - 1] + s[i - 2];
  while (m--) printf("%lld\n", dd() % 1000000007);
  return 0;
}