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 + 5;
const long long mod = 1e9 + 7;
struct Matrix {
  int n, m;
  long long a[10][10];
  Matrix() { memset(this->a, 0, sizeof(this->a)); }
  Matrix(int n, int m) {
    this->n = n;
    this->m = m;
    memset(this->a, 0, sizeof(this->a));
  }
};
Matrix operator*(Matrix a, Matrix b) {
  Matrix out = Matrix(a.n, b.m);
  for (int i = 0; i < a.n; i++) {
    for (int j = 0; j < b.m; j++) {
      for (int p = 0; p < a.m; p++) {
        out.a[i][j] = (out.a[i][j] + a.a[i][p] * b.a[p][j]) % mod;
      }
    }
  }
  return out;
}
Matrix fastPow(Matrix x, long long p) {
  Matrix answer = Matrix(x.n, x.m), current = x;
  for (int i = 0; i < x.n; i++) {
    answer.a[i][i] = 1;
  }
  while (p != 0) {
    if (p % 2 != 0) {
      answer = answer * current;
    }
    p /= 2;
    current = current * current;
  }
  return answer;
}
string fString[35];
void precalcStrings() {
  fString[1] = "a";
  fString[2] = "b";
  for (int i = 3; i <= 30; i++) {
    fString[i] = fString[i - 1] + fString[i - 2];
  }
}
int match(string s, string pattern) {
  vector<int> f;
  f.assign(pattern.size() + 1, 0);
  int len = 0;
  f[0] = 0;
  for (int i = 1; i < pattern.size(); i++) {
    if (pattern[len] == pattern[i]) {
      len++;
      f[i] = len;
    } else {
      while (pattern[len] != pattern[i] && len != 0) len = f[len - 1];
      if (pattern[len] == pattern[i]) {
        len++;
        f[i] = len;
      } else {
        f[i] = 0;
      }
    }
  }
  len = 0;
  int answer = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == pattern[len]) {
      len++;
      if (len == pattern.size()) {
        answer++;
        len = f[pattern.size() - 1];
      }
    } else {
      while (s[i] != pattern[len] && len != 0) len = f[len - 1];
      if (s[i] == pattern[len]) {
        len++;
      } else {
        len = 0;
      }
    }
  }
  return answer;
}
string getPrefix(string s, int len) {
  string out = "";
  for (int i = 0; i < len; i++) out += s[i];
  return out;
}
string getSuffix(string s, int len) {
  string out = "";
  for (int i = s.size() - len; i < s.size(); i++) out += s[i];
  return out;
}
long long k;
string s;
int val[2];
string prefix;
string suffix[2];
long long dp[MAXN];
void solve() {
  if (k < 30) {
    cout << match(fString[k], s) << '\n';
    return;
  }
  int n = s.size();
  int ind;
  for (int i = 1; i < 30; i++) {
    if (fString[i].size() > s.size()) {
      ind = i;
      break;
    }
  }
  prefix = getPrefix(fString[ind], n - 1);
  suffix[0] = getSuffix(fString[ind], n - 1);
  suffix[1] = getSuffix(fString[ind + 1], n - 1);
  val[0] = match(suffix[0] + prefix, s);
  val[1] = match(suffix[1] + prefix, s);
  Matrix A = Matrix(1, 4);
  A.a[0][0] = match(fString[ind], s);
  A.a[0][1] = match(fString[ind + 1], s);
  A.a[0][2] = val[1];
  A.a[0][3] = val[0];
  Matrix B = Matrix(4, 4);
  B.a[0][0] = 0;
  B.a[0][1] = 1;
  B.a[0][2] = 0;
  B.a[0][3] = 0;
  B.a[1][0] = 1;
  B.a[1][1] = 1;
  B.a[1][2] = 0;
  B.a[1][3] = 0;
  B.a[2][0] = 0;
  B.a[2][1] = 1;
  B.a[2][2] = 0;
  B.a[2][3] = 1;
  B.a[3][0] = 0;
  B.a[3][1] = 0;
  B.a[3][2] = 1;
  B.a[3][3] = 0;
  cout << (A * fastPow(B, k - ind - 1)).a[0][1] << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  precalcStrings();
  int T;
  cin >> k >> T;
  while (T--) {
    cin >> s;
    solve();
  }
}