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 maxn = 1e5 + 100, mod = 1e9 + 7;
struct matrix {
  int n, m, a[3][3];
  matrix() {
    n = m = 1;
    memset(a, 0, sizeof a);
  }
  matrix(int first, int second) {
    n = first, m = second;
    memset(a, 0, sizeof a);
  }
  matrix(int first, int second, vector<int> v) {
    n = first, m = second;
    int p = 0;
    for (int(i) = (0); (i) < (n); ++(i))
      for (int(j) = (0); (j) < (m); ++(j)) a[i][j] = v[p++];
  }
  inline matrix operator*(matrix first) {
    matrix ans(n, first.m);
    for (int(i) = (0); (i) < (n); ++(i))
      for (int(j) = (0); (j) < (first.m); ++(j))
        for (int(k) = (0); (k) < (m); ++(k)) {
          int second = (1LL * a[i][k] * first.a[k][j]) % mod;
          ans.a[i][j] = (ans.a[i][j] + second) % mod;
        }
    return ans;
  }
  inline matrix operator^(long long r) {
    matrix ans(n, m);
    if (!r) {
      for (int(i) = (0); (i) < (n); ++(i)) ans.a[i][i] = 1;
      return ans;
    }
    ans = (*this) ^ (r / 2LL);
    ans = ans * ans;
    if (r % 2LL) ans = ans * (*this);
    return ans;
  }
  inline void print() {
    cout << "Matrix\n";
    for (int(i) = (0); (i) < (n); ++(i)) {
      for (int(j) = (0); (j) < (m); ++(j)) cout << a[i][j] << ' ';
      cout << '\n';
    }
  }
};
string f[maxn], s[maxn];
long long k;
int n;
int au[maxn][2], nx = 1, root, pr[maxn], h[maxn], mx, cnt[maxn];
vector<int> node[maxn];
int lst[maxn];
inline void build(int first) {
  int v = root;
  for (int(i) = (0); (i) < (s[first].size()); ++(i)) {
    int c = s[first][i] - 'a';
    if (au[v][c] == -1) {
      h[nx] = h[v] + 1;
      mx = ((mx) > (h[nx]) ? (mx) : (h[nx]));
      node[h[nx]].push_back(nx);
      au[v][c] = nx++;
    }
    v = au[v][c];
  }
  lst[first] = v;
}
inline void det() {
  for (int(i) = (0); (i) < (mx + 1); ++(i))
    for (auto &(v) : (node[i]))
      for (int(c) = (0); (c) < (2); ++(c)) {
        if (au[v][c] + 1) {
          int u = au[v][c];
          if (v == root)
            pr[u] = root;
          else
            pr[u] = au[pr[v]][c];
        } else {
          if (v == root)
            au[v][c] = root;
          else
            au[v][c] = au[pr[v]][c];
        }
      }
}
inline void interstellar() {
  for (int(i) = (mx); (i) > (-11); --(i))
    for (auto &(v) : (node[i]))
      if (pr[v] != root) cnt[pr[v]] += cnt[v];
}
inline vector<int> inception(string t) {
  memset(cnt, 0, sizeof(cnt));
  int v = root;
  for (int(i) = (0); (i) < (t.size()); ++(i)) {
    v = au[v][t[i] - 'a'];
    cnt[v]++;
  }
  interstellar();
  vector<int> ans;
  for (int(i) = (0); (i) < (n); ++(i)) ans.push_back(cnt[lst[i]]);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  memset(au, -1, sizeof(au));
  node[0].push_back(root);
  cin >> k >> n;
  --k;
  for (int(i) = (0); (i) < (n); ++(i)) {
    cin >> s[i];
    build(i);
  }
  if (!k) {
    for (int(i) = (0); (i) < (n); ++(i)) {
      if (s[i] == "a")
        cout << "1\n";
      else
        cout << "0\n";
    }
    return 0;
  }
  det();
  f[0] = "a", f[1] = "b";
  int first = 1;
  while (f[first].size() < 100000 && first < k) {
    ++first;
    f[first] = f[first - 1] + f[first - 2];
  }
  if (first == k) {
    vector<int> v = inception(f[first]);
    for (int(i) = (0); (i) < (n); ++(i)) cout << v[i] << '\n';
    return 0;
  }
  ++first;
  f[first] = f[first - 1] + f[first - 2];
  if (first == k) {
    vector<int> v = inception(f[first]);
    for (int(i) = (0); (i) < (n); ++(i)) cout << v[i] << '\n';
    return 0;
  }
  vector<int> L = inception(f[first]), L1 = inception(f[first - 1]),
              LL = inception(f[first] + f[first]),
              LL1 = inception(f[first] + f[first - 1]),
              L1L = inception(f[first - 1] + f[first]);
  long long r = k - (long long)first - 1LL;
  for (int(i) = (0); (i) < (n); ++(i)) {
    int first = LL1[i] - L[i] - L1[i], second = L1L[i] - L[i] - L1[i],
        z = LL[i] - L[i] - L[i];
    matrix memento[3];
    memento[2] = matrix(3, 3, {1, 1, first, 1, 0, 0, 0, 0, 1});
    memento[0] = matrix(3, 3, {1, 1, second, 1, 0, 0, 0, 0, 1});
    memento[1] = matrix(3, 3, {1, 1, z, 1, 0, 0, 0, 0, 1});
    matrix the_prestige = memento[0] * memento[1];
    matrix ans = memento[2];
    if (r % 2LL) ans = ans * memento[0];
    ans = ans * (the_prestige ^ (r / 2LL));
    matrix darknight(3, 1, {L[i], L1[i], 1});
    ans = ans * darknight;
    cout << ans.a[0][0] << '\n';
  }
  return 0;
}