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>
using namespace std;
const long long MOD = 1000000007;
vector<string> fiboString;
void prepare(const int maxl) {
  fiboString.push_back("a");
  fiboString.push_back("b");
  while (fiboString[fiboString.size() - 2].size() < maxl) {
    fiboString.push_back(fiboString.back() + fiboString[fiboString.size() - 2]);
  }
}
struct Matrix {
  long long data[4][4];
  Matrix(const int num = 0) {
    memset(data, 0, sizeof(data));
    if (num == 1) {
      for (int i = 0; i < 4; ++i) {
        data[i][i] = 1;
      }
    } else if (num > 1) {
      data[0][0] = 0;
      data[0][1] = 1;
      data[1][0] = 1;
      data[1][1] = 1;
      data[1][num] = 1;
      data[2][2] = data[3][3] = 1;
    }
  }
  long long* operator[](const int i) { return data[i]; }
};
Matrix operator*(Matrix a, Matrix b) {
  Matrix ret;
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 4; ++j) {
      for (int k = 0; k < 4; ++k) {
        (ret[i][j] += a[i][k] * b[k][j]) %= MOD;
      }
    }
  }
  return ret;
}
Matrix multiply(const Matrix a, const long long n) {
  Matrix ret(1);
  for (int i = 60; i >= 0; --i) {
    ret = ret * ret;
    if (n >> i & 1) {
      ret = ret * a;
    }
  }
  return ret;
}
Matrix step(const long long n) {
  Matrix odd(2), even(3), mul = even * odd, ret = multiply(mul, n >> 1);
  if (n & 1) {
    ret = odd * ret;
  }
  return ret;
}
int KMP(const string s, string p) {
  p = p + ' ';
  int l1 = s.size(), l2 = p.size();
  vector<int> next;
  next.push_back(-1);
  for (int i = 1; i < l2; ++i) {
    next.push_back(next.back());
    while (next.back() != -1 && p[next.back()] != p[i - 1]) {
      next.back() = next[next.back()];
    }
    ++next.back();
  }
  int ret = 0, t = 0;
  for (int i = 0; i < l1; ++i) {
    while (t != -1 && s[i] != p[t]) {
      t = next[t];
    }
    ++t;
    if (t == l2 - 1) {
      ++ret;
    }
  }
  return ret;
}
long long solve(const long long n, const string s) {
  if (n < fiboString.size()) {
    return KMP(fiboString[n], s);
  }
  int pt = 0;
  while (fiboString[pt].size() < s.size()) {
    ++pt;
  }
  string sFormer = fiboString[pt], sLatter = fiboString[pt + 1];
  long long cntFormer = KMP(sFormer, s), cntLatter = KMP(sLatter, s),
            cntFormerLatter = KMP(
                sFormer.substr(sFormer.size() - s.size() + 1, s.size() - 1) +
                    sLatter.substr(0, s.size() - 1),
                s),
            cntLatterFormer = KMP(
                sLatter.substr(sLatter.size() - s.size() + 1, s.size() - 1) +
                    sFormer.substr(0, s.size() - 1),
                s);
  Matrix met = step(n - pt);
  return (cntFormer * met[0][0] + cntLatter * met[0][1] +
          cntLatterFormer * met[0][2] + cntFormerLatter * met[0][3]) %
         MOD;
}
int main() {
  ios::sync_with_stdio(false);
  long long k;
  int m;
  cin >> k >> m;
  --k;
  int maxlen = 0;
  vector<string> queries;
  for (int i = 0; i < m; ++i) {
    string tmp;
    cin >> tmp;
    queries.push_back(tmp);
    maxlen = max(maxlen, (int)tmp.size());
  }
  prepare(maxlen);
  for (int i = 0; i < m; ++i) {
    cout << solve(k, queries[i]) << endl;
  }
  return 0;
}
