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 = 700030;
const int MOD = 1e9 + 7, H = 3137;
int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
int sub(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
int mul(int a, int b) { return (int)(((long long)a * b) % MOD); }
int suf[2 * MAXN];
int d[2 * MAXN];
int A[2 * MAXN][2];
int bio[2 * MAXN], dp[2 * MAXN], term[2 * MAXN];
int sink, alloc;
void init() {
  memset(suf, -1, sizeof suf);
  memset(A, -1, sizeof A);
  sink = alloc = 0;
}
void extend(char c) {
  int a = c - 'a';
  int newsink = ++alloc;
  A[sink][a] = newsink;
  d[newsink] = d[sink] + 1;
  int w = suf[sink];
  while (w != -1 && A[w][a] == -1) {
    A[w][a] = newsink;
    w = suf[w];
  }
  if (w == -1)
    suf[newsink] = 0;
  else if (d[A[w][a]] == d[w] + 1)
    suf[newsink] = A[w][a];
  else {
    int newnode = ++alloc;
    int v = A[w][a];
    memcpy(A[newnode], A[v], sizeof A[v]);
    A[w][a] = newnode;
    d[newnode] = d[w] + 1;
    suf[newsink] = newnode;
    suf[newnode] = suf[v];
    suf[v] = newnode;
    w = suf[w];
    while (w != -1 && A[w][a] == v && d[w] + 1 != d[v]) {
      A[w][a] = newnode;
      w = suf[w];
    }
  }
  sink = newsink;
}
int dfs(int node) {
  if (bio[node]++) return dp[node];
  dp[node] = term[node];
  for (int i = 0; i < 2; i++)
    if (A[node][i] != -1) dp[node] += dfs(A[node][i]);
  return dp[node];
}
void gen_term() {
  memset(term, 0, sizeof term);
  int tmp = sink;
  for (; tmp; tmp = suf[tmp]) term[tmp] = 1;
}
void build(string &s) {
  int n = (int)s.size();
  assert(n <= MAXN);
  for (int i = 0; i < n; i++) extend(s[i]);
  gen_term();
  memset(bio, 0, sizeof bio);
  dfs(0);
}
int pojav(string &s) {
  int n = (int)s.size();
  int tmp = 0;
  for (int i = 0; i < n; i++) {
    int c = s[i] - 'a';
    if (A[tmp][c] == -1) return 0;
    tmp = A[tmp][c];
  }
  return dp[tmp];
}
string str_x, str_y, str_yx, str_xy, str_yy;
vector<string> stringovi;
vector<int> koef;
int gran;
void gen(long long treba) {
  string a = "a", b = "b";
  if (treba == 1) {
    str_x = "";
    str_y = a;
    gran = 1;
  } else if (treba == 2) {
    str_x = a;
    str_y = b;
    gran = 2;
  } else {
    int kol = 0;
    for (; kol < treba - 2 && (int)a.size() < 100000; kol++) {
      string c = b + a;
      a = b;
      b = c;
    }
    gran = kol;
    str_x = a;
    str_y = b;
  }
  str_yx = str_y + str_x;
  str_xy = str_x + str_y;
  str_yy = str_y + str_y;
  stringovi = {str_x, str_y, str_yx, str_xy, str_yy};
}
const int VM = 11;
void mult(int a[VM][VM], int b[VM][VM], int c[VM][VM]) {
  for (int i = 0; i < VM; i++) {
    for (int j = 0; j < VM; j++) {
      c[i][j] = 0;
      for (int k = 0; k < VM; k++)
        c[i][j] = add(c[i][j], mul(a[i][k], b[k][j]));
    }
  }
}
void potenciraj(long long e) {
  if (e == 0)
    koef = {0, 1, 0, 0, 0};
  else if (e == 1)
    koef = {1, 1, 1, 0, 0};
  else if (e == 2)
    koef = {1, 2, 1, 1, 0};
  else {
    e -= 2;
    int ost = (int)(e % 2);
    e /= 2;
    int rez[2][VM][VM];
    memset(rez, 0, sizeof rez);
    for (int i = 0; i < VM; i++) rez[0][i][i] = 1;
    int mat[2][VM][VM];
    memset(mat, 0, sizeof mat);
    for (int i = 0; i < 5; i++) mat[0][i][i] = mat[0][i][5 + i] = 1;
    mat[0][4][10] = 1;
    for (int i = 0; i < 5; i++) {
      mat[0][5 + i][i] = 1;
      mat[0][5 + i][5 + i] = 2;
    }
    mat[0][5 + 3][10] = mat[0][5 + 4][10] = 1;
    mat[0][10][10] = 1;
    int indm = 0, indr = 0;
    for (; e; e /= 2, indm ^= 1) {
      if (e & 1) {
        mult(rez[indr], mat[indm], rez[1 ^ indr]);
        indr ^= 1;
      }
      mult(mat[indm], mat[indm], mat[1 ^ indm]);
    }
    int poc[VM] = {1, 1, 1, 0, 0, 1, 2, 1, 1, 0, 1};
    int zav[VM];
    memset(zav, 0, sizeof zav);
    for (int i = 0; i < VM; i++) {
      for (int j = 0; j < VM; j++)
        zav[i] = add(zav[i], mul(rez[indr][i][j], poc[j]));
    }
    if (ost) {
      for (int i = 0; i < 5; i++) koef.push_back(add(zav[i], zav[5 + i]));
      koef[4] = add(koef[4], 1);
    } else
      for (int i = 0; i < 5; i++) koef.push_back(zav[5 + i]);
  }
  koef[0] = sub(koef[0], add(koef[2], koef[3]));
  koef[1] = sub(koef[1], add(add(koef[2], koef[3]), mul(2, koef[4])));
}
int rje[MAXN];
char tmp_s[MAXN];
string sq[MAXN];
int main() {
  long long fb;
  int brq;
  scanf("%lld%d", &fb, &brq);
  gen(fb);
  for (int i = 0; i < brq; i++) {
    scanf(" %s", tmp_s);
    sq[i] = tmp_s;
  }
  if (fb <= gran)
    koef = {0, 1, 0, 0, 0};
  else {
    potenciraj(fb - gran - 2);
  }
  for (int i = 0; i < 5; i++) {
    init();
    build(stringovi[i]);
    for (int j = 0; j < brq; j++)
      rje[j] = add(rje[j], mul(koef[i], pojav(sq[j])));
  }
  for (int i = 0; i < brq; i++) printf("%d\n", rje[i]);
  return 0;
}