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>
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;
}
struct matrix {
  int mat[4][4];
  int sz;
  matrix() {
    sz = 4;
    memset(mat, 0, sizeof(mat));
  }
  void vec() {
    for (int i = 0; i < sz; i++) {
      mat[i][i] = 1;
    }
  }
  void set(int col_id, std::vector<int> col) {
    for (int i = 0; i < sz; i++) {
      mat[i][col_id] = col[i];
    }
  }
  int multiply(std::vector<int> v, int col_id) {
    int ret = 0;
    for (int i = 0; i < sz; i++) {
      add(ret, mul(v[i], mat[i][col_id]));
    }
    return ret;
  }
};
matrix operator*(matrix a, matrix b) {
  matrix ret;
  for (int i = 0; i < ret.sz; i++) {
    for (int j = 0; j < ret.sz; j++) {
      ret.mat[i][j] = 0;
      for (int k = 0; k < ret.sz; k++) {
        add(ret.mat[i][j], mul(a.mat[i][k], b.mat[k][j]));
      }
    }
  }
  return ret;
}
matrix operator^(matrix a, long long b) {
  matrix ret;
  ret.vec();
  while (b) {
    if (b & 1) {
      ret = ret * a;
    }
    b >>= 1;
    a = a * a;
  }
  return ret;
}
struct solver {
  std::string f[110];
  void init() {
    f[1] = "a";
    f[2] = "b";
    for (int i = 3; i < 30; i++) {
      f[i] = f[i - 1] + f[i - 2];
    }
  }
  std::vector<int> get_fail(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 kmp(std::string pattern, 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;
  }
  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(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(s, middle1);
      int k2 = kmp(s, middle2);
      int a = kmp(s, f[top - 1]);
      int b = kmp(s, f[top]);
      matrix work;
      work.set(0, std::vector<int>{1, 0, 0, 0});
      work.set(1, std::vector<int>{0, 1, 0, 0});
      work.set(2, std::vector<int>{1, 0, 1, 1});
      work.set(3, std::vector<int>{1, 1, 1, 2});
      matrix tmp = work ^ ((n - top) / 2);
      int value_a = tmp.multiply(std::vector<int>{k1, k2, a, b}, 2);
      int value_b = tmp.multiply(std::vector<int>{k1, k2, a, b}, 3);
      int ret = value_b;
      if ((n - top) & 1) {
        ret = value_a;
        add(ret, value_b);
        add(ret, k1);
      }
      printf("%d\n", ret);
    }
  }
} task;
int main() {
  task.init();
  long long n;
  int m;
  std::string s;
  std::cin >> n >> m;
  for (int i = 0; i < m; i++) {
    std::cin >> s;
    task.solve(n, s);
  }
  return 0;
}