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;
struct Matrix {
  static const int MAXN = 4;
  int r, c;
  long long a[MAXN][MAXN];
  long long* operator[](int i) { return a[i]; }
  const long long* operator[](int i) const { return a[i]; }
  void init(int row, int col) {
    this->r = row;
    this->c = col;
  }
  void fill(int row, int col, long long x = 0) {
    init(row, col);
    for (int i = 0; i < r; ++i) {
      ::fill(a[i], a[i] + c, x);
    }
  }
  void eye(int n, long long x = 1) {
    fill(n, n, 0);
    for (int i = 0; i < n; ++i) {
      a[i][i] = x;
    }
  }
  void set(const Matrix& o) {
    init(o.r, o.c);
    for (int i = 0; i < r; ++i) {
      copy(o[i], o[i] + c, a[i]);
    }
  }
};
void add(const Matrix& a, const Matrix& b, long long m, Matrix& ret) {
  static Matrix c;
  c.set(a);
  for (int i = 0; i < b.r; ++i) {
    for (int j = 0; j < b.c; ++j) {
      c[i][j] += b[i][j];
      if (c[i][j] >= m) {
        c[i][j] -= m;
      }
    }
  }
  ret.set(c);
}
void mul(const Matrix& a, const Matrix& b, long long m, Matrix& ret) {
  static Matrix c;
  c.init(a.r, b.c);
  for (int i = 0; i < c.r; ++i) {
    for (int j = 0; j < c.c; ++j) {
      long long x = 0;
      for (int k = 0; k < a.c; ++k) {
        x += a[i][k] * b[k][j] % m;
      }
      c[i][j] = x % m;
    }
  }
  ret.set(c);
}
void pow(const Matrix& a, long long b, long long m, Matrix& ret) {
  static Matrix c;
  c.set(a);
  ret.eye(c.r);
  while (b > 0) {
    if (b % 2 != 0) {
      mul(ret, c, m, ret);
    }
    b /= 2;
    mul(c, c, m, c);
  }
}
const int MAXN = 100100;
const int MAXF = 31;
const long long MOD = 1000000007;
int len[MAXF];
void init() {
  len[0] = len[1] = 1;
  for (int i = 2; i < MAXF; ++i) {
    len[i] = len[i - 1] + len[i - 2];
  }
}
void genpre(int n, const char str[], int pre[]) {
  static bool inf[MAXN];
  for (int i = n - 1; i >= 0; --i) {
    if (str[i] == 'a') {
      pre[i] = 0;
      inf[i] = false;
    } else if (str[i + 1] != 'a') {
      pre[i] = 1;
      inf[i] = str[i + 1] != 'b';
    } else {
      pre[i] = 2;
      inf[i] = true;
      for (int j = 3; i + len[j - 1] < n && inf[i]; ++j) {
        if (pre[i + len[j - 1]] >= j - 2 || inf[i + len[j - 1]]) {
          pre[i] = j;
        } else {
          inf[i] = false;
        }
      }
    }
  }
}
void gensuf(int n, const char str[], int suf[]) {
  static bool inf[MAXN];
  for (int i = 0; i < n; ++i) {
    suf[i] = str[i] == 'a' ? 0 : 1;
    inf[i] = true;
    for (int j = suf[i] + 2; len[j - 2] <= i && inf[i]; j += 2) {
      if (suf[i - len[j - 2]] % 2 != suf[i] % 2 &&
          (suf[i - len[j - 2]] >= j - 1 || inf[i - len[j - 2]])) {
        suf[i] = j;
      } else {
        inf[i] = false;
      }
    }
  }
}
int main() {
  int n, re;
  long long m, ans;
  static char str[MAXN];
  static int pre[MAXN], suf[MAXN];
  static long long diff[MAXF + 2], sum[MAXF];
  static Matrix odd, even, trans;
  init();
  scanf("%I64d%d", &m, &re);
  --m;
  for (int ri = 1; ri <= re; ++ri) {
    scanf("%s", str);
    n = strlen(str);
    fill(diff, diff + MAXF + 2, 0);
    if (strcmp(str, "a") == 0) {
      diff[0] = 1;
    } else if (strcmp(str, "b") == 0) {
      diff[1] = 1;
    } else if (strcmp(str, "ba") == 0) {
      diff[2] = 1;
    } else {
      genpre(n, str, pre);
      gensuf(n, str, suf);
      for (int i = 1; i < n; ++i) {
        if (str[i] != 'a' && len[suf[i - 1]] >= i && len[pre[i]] >= n - i) {
          for (int j = suf[i - 1] + 1; j < MAXF + 2; j += 2) {
            if (j >= pre[i] + 2) {
              ++diff[j];
            }
          }
        }
      }
    }
    fill(sum, sum + MAXF, 0);
    sum[0] = diff[0];
    sum[1] = diff[1];
    for (int i = 2; i < MAXF; ++i) {
      sum[i] = (sum[i - 1] + sum[i - 2] + diff[i]) % MOD;
    }
    if (m < MAXF) {
      ans = sum[m];
    } else {
      odd.fill(3, 3, 0);
      even.fill(3, 3, 0);
      odd[0][0] = even[0][0] = 1;
      odd[0][1] = even[0][1] = 1;
      odd[1][0] = even[1][0] = 1;
      odd[2][2] = even[2][2] = 1;
      odd[0][2] = diff[MAXF];
      even[0][2] = diff[MAXF + 1];
      mul(even, odd, MOD, trans);
      pow(trans, (m - MAXF + 1) / 2, MOD, trans);
      if (m % 2 != 0) {
        mul(odd, trans, MOD, trans);
      }
      ans = (trans[0][0] * sum[MAXF - 1] + trans[0][1] * sum[MAXF - 2] +
             trans[0][2] * 1) %
            MOD;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}