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;
int n;
char s[3005];
int mat[3005][2];
void calc() {
  mat[0][0] = mat[0][1] = 0;
  mat[0][s[0] - 'a'] = 1;
  int j = 0;
  for (int i = 1; i < n; i++) {
    mat[i][0] = mat[j][0];
    mat[i][1] = mat[j][1];
    mat[i][s[i] - 'a'] = i + 1;
    j = mat[j][s[i] - 'a'];
  }
  mat[n][0] = mat[j][0];
  mat[n][1] = mat[j][1];
}
int dp[3003][3005];
int dp2[3003][3005];
int mark[3003][3005];
int mark2[3003][3005];
int pass;
int f(int i, int state) {
  if (i == 1) return mat[state][0];
  if (i == 2) return mat[state][1];
  if (mark[i][state] == pass) return dp[i][state];
  mark[i][state] = pass;
  int x = f(i - 1, state);
  return dp[i][state] = f(i - 2, x);
}
inline int add(int a, int b) {
  a += b;
  if (a >= (1000000007)) {
    a -= (1000000007);
  }
  return a;
}
int g(int i, int state) {
  if (i == 1) return mat[state][0] == n;
  if (i == 2) return mat[state][1] == n;
  if (mark2[i][state] == pass) return dp2[i][state];
  mark2[i][state] = pass;
  int x = f(i - 1, state);
  return dp2[i][state] = add(g(i - 1, state), g(i - 2, x));
}
int main() {
  long long k;
  int m;
  scanf("%lld %d", &k, &m);
  for (int i = 0; i < m; i++) {
    scanf(" %s", s);
    n = strlen(s);
    calc();
    pass++;
    printf("%d\n", g(k, 0));
  }
  return 0;
}