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;
using ll = long long;
int MOD = 1000000007;
vector<vector<ll>> ones(int n) {
  vector<vector<ll>> r(n, vector<ll>(n));
  for (int i = 0; i < n; i++) r[i][i] = 1;
  return r;
}
vector<vector<ll>> operator*(vector<vector<ll>> &a, vector<vector<ll>> &b) {
  int n = a.size(), m = b[0].size(), z = a[0].size();
  vector<vector<ll>> r(n, vector<ll>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      for (int k = 0; k < z; k++) r[i][j] += a[i][k] * b[k][j], r[i][j] %= MOD;
  return r;
}
vector<vector<ll>> be(vector<vector<ll>> b, ll e) {
  vector<vector<ll>> r = ones(b.size());
  while (e) {
    if (e & 1LL) r = r * b;
    b = b * b;
    e >>= 1;
  }
  return r;
}
vector<int> construct_borders(string &s) {
  int n = s.size();
  vector<int> border(n + 1);
  border[0] = -1;
  for (int i = 1, j = -1; i <= n; i++) {
    while (j != -1 && s[j] != s[i - 1]) j = border[j];
    border[i] = ++j;
  }
  vector<int> ans(n + 1);
  ans[0] = -1;
  for (int i = 1, j = -1; i <= n; i++) {
    j = border[i - 1];
    while (j != -1 && s[j] != s[i - 1]) j = ans[j];
    j++;
    if (i == n || s[j] != s[i])
      ans[i] = j;
    else
      ans[i] = ans[j];
  }
  return ans;
}
short int kmp(string &t, string &p, vector<int> &border) {
  int n = t.size(), m = p.size();
  short int ans = 0;
  for (int i = 0, j = 0; i <= n - m;) {
    while (j < m && p[j] == t[i + j]) j++;
    if (j == m) ans++;
    i += j - border[j];
    j = max(0, border[j]);
  }
  return ans;
}
struct SuffixAutomaton {
  vector<map<char, int>> edges;
  vector<int> link;
  vector<int> length;
  int last;
  SuffixAutomaton(string s) {
    edges.push_back(map<char, int>());
    link.push_back(-1);
    length.push_back(0);
    last = 0;
    for (int i = 0; i < s.size(); i++) {
      edges.push_back(map<char, int>());
      length.push_back(i + 1);
      link.push_back(0);
      int r = edges.size() - 1;
      int p = last;
      while (p >= 0 && edges[p].find(s[i]) == edges[p].end()) {
        edges[p][s[i]] = r;
        p = link[p];
      }
      if (p != -1) {
        int q = edges[p][s[i]];
        if (length[p] + 1 == length[q]) {
          link[r] = q;
        } else {
          edges.push_back(edges[q]);
          length.push_back(length[p] + 1);
          link.push_back(link[q]);
          int qq = edges.size() - 1;
          link[q] = qq;
          link[r] = qq;
          while (p >= 0 && edges[p][s[i]] == q) {
            edges[p][s[i]] = qq;
            p = link[p];
          }
        }
      }
      last = r;
    }
  }
};
string fibonacci[28];
ll k;
vector<SuffixAutomaton> automaton;
void build_fibonacci() {
  fibonacci[0] = "a";
  fibonacci[1] = "b";
  for (int i = 2; i < 28; i++)
    fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2];
}
void build_automaton() {
  for (int i = 0; i < 28; i++)
    automaton.push_back(SuffixAutomaton(fibonacci[i]));
}
bool find_fast(string &w, SuffixAutomaton &a) {
  bool ans = false;
  int n = 0;
  for (int i = 0; i < w.size(); i++) {
    if (a.edges[n].find(w[i]) == a.edges[n].end()) {
      ans = true;
      break;
    }
    n = a.edges[n][w[i]];
  }
  return !ans;
}
void search(string &s, short int &p, short int &p1, short int &p2,
            short int &p3) {
  vector<int> borders = construct_borders(s);
  for (int i = 1; i < min(k, 28LL); i++) {
    int sz = fibonacci[i].size();
    if (sz < s.size()) continue;
    if (find_fast(s, automaton[i])) {
      p = i + 1;
      p1 = kmp(fibonacci[i], s, borders);
      p2 = kmp(fibonacci[i + 1], s, borders);
      p3 = kmp(fibonacci[i + 2], s, borders);
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  build_fibonacci();
  build_automaton();
  int m;
  cin >> k >> m;
  for (int i = 0; i < m; i++) {
    string s;
    cin >> s;
    short int p, p1, p2, p3;
    p = -1;
    p1 = -1;
    p2 = -1;
    p3 = -1;
    if (k == 1 && s == "a") {
      cout << 1 << '\n';
      continue;
    }
    search(s, p, p1, p2, p3);
    if (p == -1 && p1 == -1) {
      cout << 0 << '\n';
      continue;
    }
    if (p1 == p2 && p3 == p2 + p1) {
      vector<vector<ll>> b(2, vector<ll>(2));
      vector<vector<ll>> f(2, vector<ll>(1));
      b[0] = {1, 1};
      b[1] = {1, 0};
      f[0] = {p1};
      f[1] = {0};
      vector<vector<ll>> c_exp = be(b, k - p);
      vector<vector<ll>> ans = c_exp * f;
      cout << ans[0][0] << '\n';
    } else {
      if (p1 != p2 && p3 == p2 + p1) {
        vector<vector<ll>> b(3, vector<ll>(3));
        vector<vector<ll>> f(3, vector<ll>(1));
        b[0] = {2, 1, 1};
        b[1] = {1, 1, 0};
        b[2] = {0, 0, 1};
        f[0] = {p2};
        f[1] = {p1};
        f[2] = {1};
        vector<vector<ll>> c_exp = be(b, (k - p) / 2);
        vector<vector<ll>> ans = c_exp * f;
        if ((p & 1) == (k & 1LL))
          cout << ans[1][0] << '\n';
        else
          cout << ans[0][0] << '\n';
      }
      if (p1 == p2 && p3 != p2 + p1) {
        vector<vector<ll>> b(3, vector<ll>(3));
        vector<vector<ll>> f(3, vector<ll>(1));
        b[0] = {2, 1, 1};
        b[1] = {1, 1, 1};
        b[2] = {0, 0, 1};
        f[0] = {p2};
        f[1] = {p1};
        f[2] = {1};
        vector<vector<ll>> c_exp = be(b, (k - p) / 2);
        vector<vector<ll>> ans = c_exp * f;
        if ((p & 1) == (k & 1LL))
          cout << ans[1][0] << '\n';
        else
          cout << ans[0][0] << '\n';
      }
      if (p1 != p2 && p3 != p2 + p1) {
        vector<vector<ll>> b(3, vector<ll>(3));
        vector<vector<ll>> f(3, vector<ll>(1));
        b[0] = {2, 1, 2};
        b[1] = {1, 1, 1};
        b[2] = {0, 0, 1};
        f[0] = {p2};
        f[1] = {p1};
        f[2] = {1};
        vector<vector<ll>> c_exp = be(b, (k - p) / 2);
        vector<vector<ll>> ans = c_exp * f;
        if ((p & 1) == (k & 1LL))
          cout << ans[1][0] << '\n';
        else
          cout << ans[0][0] << '\n';
      }
    }
  }
  return 0;
}