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 mod = 1e9 + 7;
inline int ad(int x, int y) { return (x + y) % mod; }
inline int mu(int x, int y) { return 1LL * x * y % mod; }
struct mat {
  int val[2][2];
  int n;
  mat(int _n = 0, int x = 0) {
    n = _n;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (i == j)
          val[i][j] = x;
        else
          val[i][j] = 0;
  }
  int *operator[](int x) { return val[x]; }
};
inline mat operator*(mat a, mat b) {
  mat ans(a.n, 0);
  for (int i = 0; i < a.n; i++)
    for (int j = 0; j < a.n; j++)
      for (int k = 0; k < a.n; k++)
        ans[i][j] = ad(ans[i][j], mu(a[i][k], b[k][j]));
  return ans;
}
inline mat bpow(mat a, long long b) {
  mat ans(a.n, 1);
  while (b) {
    if (b & 1) ans = ans * a;
    b >>= 1;
    a = a * a;
  }
  return ans;
}
int fib(long long n) {
  mat A(2, 0);
  A[0][0] = A[0][1] = A[1][0] = 1;
  A = bpow(A, n);
  return A[0][0];
}
int get(int x, int y, int a, int b, long long n) {
  if (n == 0) return x;
  if (n == 1) return y;
  int xx = mu(x, fib(n - 2));
  int yy = mu(y, fib(n - 1));
  int z = n & 1;
  int A = mu(a, ad(fib(n - 1), mod - z));
  int B = (n == 2 ? 0 : mu(b, ad(fib(n - 2), mod + z - 1)));
  int answer = ad(ad(xx, yy), ad(A, B));
  return answer;
}
const int maxn = 1e5 + 10;
int f[maxn];
inline void build(const string &s) {
  f[1] = 0;
  int k = 0;
  for (int i = 1; i < s.size(); i++) {
    while (k && s[i] != s[k]) k = f[k];
    if (s[i] == s[k]) k++;
    f[i + 1] = k;
  }
}
inline int oc_tim(const string &s, const string &t, bool bul = 0) {
  if (bul == 0) build(t);
  int k = 0, ans = 0;
  for (int i = 0; i < s.size(); i++) {
    while (k && s[i] != t[k]) k = f[k];
    if (s[i] == t[k]) k++;
    if (k == t.size()) {
      k = f[k];
      ans++;
    }
  }
  return ans;
}
string pat[maxn], lef[maxn], rig[maxn];
int dp[maxn], num[maxn], jav[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long k, q;
  cin >> k >> q;
  k--;
  for (int i = 0; i < q; i++) cin >> pat[i];
  for (int itt = 0; itt < q; itt++) {
    string s = pat[itt];
    oc_tim("a", s, 1);
    int sz = s.size();
    if (sz == 1) {
      if (s == "a") jav[itt] = (k < 2 ? 1 - k : fib(k - 2));
      if (s == "b") jav[itt] = (k == 0 ? 0 : fib(k - 1));
      continue;
    }
    lef[0] = rig[0] = "a";
    lef[1] = rig[1] = "b";
    int cur = 2;
    int cnt = 4;
    bool f = 0;
    while (cnt) {
      lef[cur] = lef[cur - 1] + lef[cur - 2];
      int ez = lef[cur].size();
      int mn = min(sz - 1, ez);
      if (ez >= sz - 1) f = 1;
      lef[cur] = lef[cur].substr(0, mn);
      rig[cur] = rig[cur - 1] + rig[cur - 2];
      rig[cur] = rig[cur].substr(ez - mn, mn);
      num[cur] = oc_tim(rig[cur - 1] + lef[cur - 2], s);
      dp[cur] = dp[cur - 1] + dp[cur - 2] + num[cur];
      dp[cur] %= mod;
      cur++;
      cnt -= f;
    }
    if (k < cur) {
      jav[itt] = dp[k];
      continue;
    }
    jav[itt] =
        get(dp[cur - 2], dp[cur - 1], num[cur - 2], num[cur - 1], 2 + k - cur);
  }
  for (int i = 0; i < q; i++) cout << jav[i] << "\n";
}