#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + int(ch - '0');
  return x * f;
}
const int MAXN = 2e5 + 5, P = 1e9 + 7;
int pls(int a, int b) { return a + b < P ? a + b : a + b - P; }
int mns(int a, int b) { return a < b ? a + P - b : a - b; }
int mul(int a, int b) { return 1ll * a * b % P; }
long long k;
int m, nxt[MAXN];
string s[30], t;
void kmp_init(const string& s) {
  nxt[0] = -1;
  int n = s.length();
  for (int i = 1, j = -1; i < n; i++) {
    while (j != -1 && s[j + 1] != s[i]) j = nxt[j];
    if (s[j + 1] == s[i]) j++;
    nxt[i] = j;
  }
}
int kmp_count(const string& s, const string& t) {
  int ans = 0;
  int sn = s.length(), tn = t.length();
  for (int i = 0, j = -1; i < tn; i++) {
    while (j != -1 && s[j + 1] != t[i]) j = nxt[j];
    if (s[j + 1] == t[i]) j++;
    if (j == sn - 1) {
      ans++;
      j = nxt[j];
    }
  }
  return ans;
}
struct Matrix {
  int A[3][3];
  void clear() {
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++) A[i][j] = 0;
  }
  void setU() {
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++) A[i][j] = (i == j);
  }
  int* operator[](int k) { return A[k]; }
  const int* operator[](int k) const { return A[k]; }
  Matrix operator*(const Matrix& B) const {
    Matrix ret;
    ret.clear();
    for (int i = 0; i < 3; i++)
      for (int k = 0; k < 3; k++)
        for (int j = 0; j < 3; j++)
          ret[i][j] = pls(ret[i][j], mul(A[i][k], B[k][j]));
    return ret;
  }
} T1, T2, D, F;
Matrix qpow(Matrix a, long long n) {
  Matrix ret;
  ret.setU();
  for (; n; n >>= 1, a = a * a)
    if (n & 1) ret = ret * a;
  return ret;
}
void solve() {
  cin >> t;
  int n = t.length();
  kmp_init(t);
  int bas = 1;
  for (; s[bas].length() <= n; bas++)
    ;
  long long a = kmp_count(t, s[bas]), b = kmp_count(t, s[bas + 1]),
            c = kmp_count(t, s[bas + 2]), d = kmp_count(t, s[bas + 3]);
  long long p = c - a - b, q = d - b - c;
  F.clear();
  T1.clear(), T2.clear(), D.clear();
  F[0][0] = b;
  F[1][0] = a;
  F[2][0] = 1;
  T1[0][0] = 1, T1[0][1] = 1, T1[0][2] = q;
  T1[1][0] = 1;
  T1[2][2] = 1;
  T2[0][0] = 1;
  T2[0][1] = 1;
  T2[0][2] = p;
  T2[1][0] = 1;
  T2[2][2] = 1;
  D = T1 * T2;
  F = qpow(D, (k - bas - 1) / 2) * F;
  if ((k - bas) % 2 == 0) F = T2 * F;
  cout << F[0][0] << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> k >> m;
  s[1] = "a", s[2] = "b";
  for (int i = 3; i <= 29; i++) s[i] = s[i - 1] + s[i - 2];
  if (k <= 29) {
    while (m--) {
      cin >> t;
      kmp_init(t);
      cout << kmp_count(t, s[k]) << endl;
    }
  } else {
    while (m--) solve();
  }
  return 0;
}
