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;
vector<bool> bittify(const char *s) {
  int n = strlen(s);
  vector<bool> bits;
  bits.reserve(n);
  for (int i = 0; i < (n); ++i) bits.push_back(s[i] == 'b');
  return bits;
}
void multiply(long long a[2][2], long long b[2][2]) {
  long long c[2][2] = {0LL};
  for (int i = 0; i < (2); ++i)
    for (int j = 0; j < (2); ++j)
      for (int k = 0; k < (2); ++k)
        c[i][j] = (c[i][j] + (a[i][k] * b[k][j]) % 1000000007) % 1000000007;
  for (int i = 0; i < (2); ++i)
    for (int j = 0; j < (2); ++j) a[i][j] = c[i][j];
}
map<long long, long long> fibcache;
long long fibonacci(const long long &n) {
  if (n <= 0)
    return 0LL;
  else if (n <= 2)
    return 1LL;
  else if (fibcache.find(n) != fibcache.end())
    return fibcache[n];
  else {
    long long f[2][2] = {{1LL, 1LL}, {1LL, 0LL}};
    long long x[2][2] = {{1LL, 0LL}, {0LL, 1LL}};
    long long nn = n - 1LL, m = 0;
    for (int i = 62; i >= 0; --i) {
      m <<= 1;
      multiply(x, x);
      if (m) fibcache[m + 1] = x[0][0];
      if (nn & (1LL << i)) {
        m |= 1LL;
        multiply(x, f);
        fibcache[m + 1] = x[0][0];
      }
    }
    return x[0][0];
  }
}
void replace(const vector<bool> &b, vector<bool> &b1, vector<bool> &b2) {
  b1.clear();
  b2.clear();
  int n = b.size(), two = false;
  int zeros = 0, ones = 0;
  for (int i = 0; i < (n); ++i) {
    if (b[i])
      ++ones, zeros = 0;
    else
      ++zeros, ones = 0;
    if (ones >= 3 || zeros >= 2) return;
  }
  for (int i = 0; i < (n); ++i) {
    if (b[i]) {
      if (i < n - 1) {
        if (b[i + 1])
          b1.push_back(0);
        else
          b1.push_back(1), ++i;
      } else
        b1.push_back(0), two = true;
    } else
      b1.push_back(1);
  }
  if (two) {
    b2 = b1;
    b2[b1.size() - 1] = 1;
  }
}
char *str(const vector<bool> &b) {
  char *s = new char[b.size() + 1];
  memset(s, 0, (b.size() + 1) * sizeof(char));
  for (int i = 0; i < (b.size()); ++i) s[i] = b[i] ? 'b' : 'a';
  return s;
}
inline bool operator<(const vector<bool> &a, const vector<bool> &b) {
  if (a.size() != b.size()) return a.size() < b.size();
  for (int i = 0; i < (a.size()); ++i)
    if (a[i] != b[i]) return a[i] < b[i];
  return false;
}
map<pair<vector<bool>, int>, long long> calccache;
long long calculate(const vector<bool> &b, const int &k) {
  if (k < 1 || b.empty())
    return 0LL;
  else if (b.size() == 1) {
    if (b[0])
      return fibonacci(k - 1);
    else
      return fibonacci(k - 2) + (k == 1);
  } else {
    pair<vector<bool>, int> id(b, k);
    if (calccache.find(id) != calccache.end())
      return calccache[id];
    else {
      vector<bool> b1, b2;
      replace(b, b1, b2);
      long long r1 = calculate(b1, k - 1);
      long long r2 = calculate(b2, k - 1);
      return calccache[id] = (r1 + r2) % 1000000007;
    }
  }
}
int main() {
  int k, m;
  char str[100000 + 2];
  for (scanf("%d%d", &k, &m); m--;) {
    scanf("%s", str);
    vector<bool> bitstr = bittify(str);
    long long ans = calculate(bitstr, k);
    printf("%I64d\n", ans);
  }
  return 0;
}