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
#include <bits/stdc++.h>
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
T sqr(const T &x) {
  return x * x;
}
template <class T>
T lowbit(const T &x) {
  return (x ^ (x - 1)) & x;
}
template <class T>
int countbit(const T &n) {
  return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));
}
template <class T>
bool checkmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool checkmax(T &a, const T &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
const int md = (int)1e9 + 7;
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
inline int mul(int a, int b) {
  return (long long)a * b % md;
  unsigned long long x = (long long)a * b;
  unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m;
  asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(md));
  return m;
}
namespace matrix {
const int MATRIX_SIZE = 4;
struct mat {
  int a[MATRIX_SIZE][MATRIX_SIZE];
  mat(const int type = 0) {
    memset(a, 0, sizeof(a));
    if (type == 1) {
      for (int i = 0; i < MATRIX_SIZE; i++) {
        a[i][i] = 1;
      }
    }
  }
  int *operator[](const int i) { return a[i]; }
};
void set_row(mat &a, int row_id, std::vector<int> row) {
  for (int i = 0; i < MATRIX_SIZE; i++) {
    a[row_id][i] = row[i];
  }
}
int multiply_column(std::vector<int> v, mat &a, int col_id) {
  int ret = 0;
  for (int i = 0; i < MATRIX_SIZE; i++) {
    ::add(ret, ::mul(v[i], a[i][col_id]));
  }
  return ret;
}
mat operator*(mat a, mat b) {
  mat ret(0);
  for (int i = 0; i < MATRIX_SIZE; i++) {
    for (int j = 0; j < MATRIX_SIZE; j++) {
      add(ret[i][j], mul(a[i][0], b[0][j]));
      add(ret[i][j], mul(a[i][1], b[1][j]));
      add(ret[i][j], mul(a[i][2], b[2][j]));
      add(ret[i][j], mul(a[i][3], b[3][j]));
    }
  }
  return ret;
}
mat power(const mat a, long long n) {
  mat ret(1);
  for (int i = 60; i >= 0; i--) {
    ret = ret * ret;
    if (n >> i & 1) {
      ret = ret * a;
    }
  }
  return ret;
}
}  // namespace matrix
namespace kmp {
std::vector<int> get_fail(const std::string s) {
  std::vector<int> fail;
  fail.resize((int(s.size())), -1);
  for (int i = 1, j = -1; i < (int(s.size())); i++) {
    while (j >= 0 && s[j + 1] != s[i]) {
      j = fail[j];
    }
    if (s[j + 1] == s[i]) {
      ++j;
      fail[i] = j;
    } else {
      fail[i] = -1;
    }
  }
  return fail;
}
int match_count(const std::string pattern, const std::string text) {
  std::vector<int> fail = get_fail(pattern);
  int ret = 0, j = -1;
  for (int i = 0; i < (int(text.size())); i++) {
    while (j >= 0 && pattern[j + 1] != text[i]) {
      j = fail[j];
    }
    if (pattern[j + 1] == text[i]) {
      ++j;
    }
    if (j + 1 == (int(pattern.size()))) {
      ret++;
      j = fail[j];
    }
  }
  return ret;
}
}  // namespace kmp
namespace solver {
using matrix::mat;
std::vector<std::string> f(30);
void init() {
  f[1] = "a";
  f[2] = "b";
  for (int i = 3; i < 30; i++) {
    f[i] = f[i - 1] + f[i - 2];
  }
}
void solve(long long n, std::string s) {
  int top = 2;
  while ((int(f[top].size())) < (int(s.size())) ||
         (int(f[top - 1].size())) < (int(s.size()))) {
    top++;
  }
  if (n <= top) {
    printf("%d\n", kmp::match_count(s, f[n]));
  } else {
    std::string middle1 =
        f[top].substr((int(f[top].size())) - (int(s.size())) + 1) +
        f[top - 1].substr(0, (int(s.size())) - 1);
    std::string middle2 =
        f[top - 1].substr((int(f[top - 1].size())) - (int(s.size())) + 1) +
        f[top].substr(0, (int(s.size())) - 1);
    int k1 = kmp::match_count(s, middle1);
    int k2 = kmp::match_count(s, middle2);
    int a = kmp::match_count(s, f[top - 1]);
    int b = kmp::match_count(s, f[top]);
    mat work(0);
    matrix::set_row(work, 0, std::vector<int>{1, 0, 1, 1});
    matrix::set_row(work, 1, std::vector<int>{0, 1, 0, 1});
    matrix::set_row(work, 2, std::vector<int>{0, 0, 1, 1});
    matrix::set_row(work, 3, std::vector<int>{0, 0, 1, 2});
    mat tmp = matrix::power(work, ((n - top) / 2));
    int value_a =
        matrix::multiply_column(std::vector<int>{k1, k2, a, b}, tmp, 2);
    int value_b =
        matrix::multiply_column(std::vector<int>{k1, k2, a, b}, tmp, 3);
    int ret = value_b;
    if ((n - top) & 1) {
      ret = value_a;
      add(ret, value_b);
      add(ret, k1);
    }
    printf("%d\n", ret);
  }
}
}  // namespace solver
int main() {
  solver::init();
  long long n;
  int m;
  std::string s;
  std::cin >> n >> m;
  for (int i = 0; i < m; i++) {
    std::cin >> s;
    solver::solve(n, s);
  }
  return 0;
}
