#include <bits/stdc++.h>
using namespace std;
long long n, m;
bool debug = false;
int k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string s[30], tmp;
int nxt[100005];
struct Matrix {
  int n, m;
  long long a[5][5];
  Matrix() {}
  Matrix(int n, int m) : n(n), m(m) {}
  void init(long long num) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) a[i][j] = num;
  }
  Matrix operator*(Matrix b) {
    Matrix o = Matrix(n, b.m);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < b.m; j++) {
        o.a[i][j] = 0;
        for (int k = 0; k < m; k++) {
          o.a[i][j] = (o.a[i][j] + (a[i][k] * b.a[k][j]) % 1000000007);
        }
      }
    }
    return o;
  }
  Matrix pow(long long p) {
    Matrix o = Matrix(n, m);
    Matrix b = *this;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) o.a[i][j] = (i == j);
    while (p > 0) {
      if (p & 1) o = o * b;
      b = b * b;
      p >>= 1;
    }
    return o;
  }
};
void Kmp_init(string &str) {
  int k = -1, j = 0;
  nxt[0] = -1;
  int plen = (int)str.size();
  while (j < plen) {
    while (k != -1 && str[k] != str[j]) k = nxt[k];
    nxt[++j] = ++k;
  }
}
int Kmp(string &s, string &p) {
  int j = 0, k = 0, ans = 0, slen = (int)s.size(), plen = (int)p.size();
  while (j < slen) {
    while (k != -1 && s[j] != p[k]) k = nxt[k];
    j++;
    k++;
    if (k == plen) {
      ans++;
      k = nxt[k];
    }
  }
  return ans;
}
char cs[100005];
long long dd() {
  scanf("%s", cs);
  tmp = cs;
  int x;
  for (x = 1; s[x].size() < tmp.size(); x++)
    ;
  if (x > n) {
    return 0;
  }
  Kmp_init(tmp);
  int a = Kmp(s[x], tmp), b = Kmp(s[x + 1], tmp), c = Kmp(s[x + 2], tmp),
      d = Kmp(s[x + 3], tmp);
  d = d - c - b;
  c = c - b - a;
  if (x == n) return a;
  long long k = n - x - 1;
  Matrix f(1, 3);
  f.a[0][0] = a;
  f.a[0][1] = b;
  f.a[0][2] = 1;
  Matrix u(3, 3), v(3, 3);
  u.a[0][0] = 0;
  u.a[0][1] = 1;
  u.a[0][2] = 0;
  u.a[1][0] = 1;
  u.a[1][1] = 1;
  u.a[1][2] = 0;
  u.a[2][0] = 0;
  u.a[2][1] = c;
  u.a[2][2] = 1;
  v.a[0][0] = 0;
  v.a[0][1] = 1;
  v.a[0][2] = 0;
  v.a[1][0] = 1;
  v.a[1][1] = 1;
  v.a[1][2] = 0;
  v.a[2][0] = 0;
  v.a[2][1] = d;
  v.a[2][2] = 1;
  Matrix t = u * v;
  t = t.pow(k / 2);
  if (k & 1) t = t * u;
  f = f * t;
  return f.a[0][1];
}
int main() {
  scanf("%lld%lld", &n, &m);
  s[1] = "a";
  s[2] = "b";
  for (int i = 3; i <= 29; i++) s[i] = s[i - 1] + s[i - 2];
  while (m--) printf("%lld\n", dd() % 1000000007);
  return 0;
}
