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>
#pragma GCC target("pclmul")
using ul = std::uint32_t;
using ull = std::uint64_t;
using li = std::int32_t;
using ll = std::int64_t;
using uss = std::uint8_t;
const ul tau = 30;
std::string f[tau + 1];
ul ord[1000000];
class sam_t {
 public:
  ul las;
  class node {
   public:
    ul ch[2];
    ul len = 0;
    ul fa = 0;
    ul cnt = 0;
    node() { std::memset(ch, 0, sizeof(ch)); }
  };
  std::vector<node> st;
  void add(ul c) {
    ul p = las;
    ul np = las = st.size();
    st.push_back(node());
    st[np].len = st[p].len + 1;
    for (; p && !st[p].ch[c]; p = st[p].fa) {
      st[p].ch[c] = np;
    }
    if (!p) {
      st[np].fa = 1;
    } else {
      ul q = st[p].ch[c];
      if (st[q].len == st[p].len + 1) {
        st[np].fa = q;
      } else {
        ul nq = st.size();
        st.push_back(node());
        st[nq] = st[q];
        st[nq].cnt = 0;
        st[nq].len = st[p].len + 1;
        st[q].fa = st[np].fa = nq;
        for (; p && st[p].ch[c] == q; p = st[p].fa) {
          st[p].ch[c] = nq;
        }
      }
    }
  }
  void init() {
    las = 1;
    st.resize(0);
    st.resize(2);
  }
};
sam_t sam[tau + 1];
ull k;
ul m;
const ul maxlen = 1e5;
char str[maxlen + 2];
ul ans[100];
const ul mod = 1e9 + 7;
ul plus(ul a, ul b) { return a + b < mod ? a + b : a + b - mod; }
ul minus(ul a, ul b) { return a < b ? a + mod - b : a - b; }
ul mul(ul a, ul b) { return ull(a) * ull(b) % mod; }
void exgcd(li a, li b, li& x, li& y) {
  if (b) {
    exgcd(b, a % b, y, x);
    y -= a / b * x;
  } else {
    x = 1;
    y = 0;
  }
}
ul inverse(ul a) {
  li x, y;
  exgcd(a, mod, x, y);
  return x < 0 ? x + li(mod) : x;
}
ul cc[tau + 1];
ul linearrec(const ul s[], const ul tcc[], ul len, ull n) {
  static ul cc[1473];
  static ul ret[1473];
  static ul temp[2943];
  if (n < len) {
    return s[n];
  }
  if (len == 0) {
    return 0;
  }
  std::memcpy(cc, tcc, sizeof(ul) * (len + 1));
  std::memset(ret, 0, sizeof(ul) * len);
  ret[0] = 1;
  ul dret = 0;
  for (ull t = ull(1) << 63 - __builtin_clzll(n); t; t >>= 1) {
    std::memset(temp, 0, sizeof(ul) * (dret + dret + 1));
    for (ul i = 0; i <= dret; ++i) {
      temp[i + i] = plus(temp[i + i], mul(ret[i], ret[i]));
      for (ul j = i + 1; j <= dret; ++j) {
        ul tp = mul(ret[i], ret[j]);
        temp[i + j] = plus(temp[i + j], plus(tp, tp));
      }
    }
    for (ul i = dret + dret; i >= len; --i) {
      ul lambda = minus(0, temp[i]);
      if (!lambda) {
        continue;
      }
      for (ul j = 0; j <= len; ++j) {
        temp[i - j] = plus(temp[i - j], mul(cc[j], lambda));
      }
    }
    std::memcpy(ret, temp, sizeof(ul) * len);
    dret = std::min(dret + dret, len - ul(1));
    if (t & n) {
      for (ul i = dret + 1; i; --i) {
        ret[i] = ret[i - 1];
      }
      ret[0] = 0;
      ++dret;
      if (dret == len) {
        ul lambda = minus(0, ret[len]);
        if (lambda) {
          for (ul i = 0; i <= len; ++i) {
            ret[len - i] = plus(ret[len - i], mul(cc[i], lambda));
          }
        }
        --dret;
      }
    }
  }
  ul out = 0;
  for (ul i = 0; i != len; ++i) {
    out = plus(out, mul(s[i], ret[i]));
  }
  return out;
}
ul bm(const ul s[], ul cc[], ul nn) {
  static ul bb[100];
  static ul tt[100];
  cc[0] = 1;
  bb[0] = 1;
  ul tl;
  ul bl = 0;
  ul l = 0;
  ul m = 1;
  ul b = 1;
  for (ul n = 0; n != nn; ++n) {
    ul d = 0;
    for (ul i = 0; i <= l; ++i) {
      d = plus(d, mul(cc[i], s[n - i]));
    }
    if (d == 0) {
      ++m;
    } else if (l + l <= n) {
      std::memcpy(tt, cc, sizeof(ul) * (l + 1));
      tl = l;
      std::memset(&cc[l + 1], 0, sizeof(ul) * (n - l - l + 1));
      l = n + 1 - l;
      ul lambda = mul(inverse(b), d);
      for (ul i = 0; i <= bl; ++i) {
        cc[i + m] = minus(cc[i + m], mul(lambda, bb[i]));
      }
      bl = tl;
      std::memcpy(bb, tt, sizeof(ul) * (bl + 1));
      b = d;
      m = 1;
    } else {
      ul lambda = mul(inverse(b), d);
      for (ul i = 0; i <= bl; ++i) {
        cc[i + m] = minus(cc[i + m], mul(lambda, bb[i]));
      }
      ++m;
    }
  }
  return l;
}
int main() {
  f[1] = "a";
  f[2] = "b";
  for (ul i = 3; i <= tau; ++i) {
    f[i] = f[i - 1] + f[i - 2];
  }
  for (ul i = 1; i <= tau; ++i) {
    sam[i].init();
    sam[i].st[1].cnt = 1;
    for (char c : f[i]) {
      sam[i].add(c - 'a');
      ++sam[i].st[sam[i].las].cnt;
    }
    for (ul j = 1; j != sam[i].st.size(); ++j) {
      ord[j] = j;
    }
    std::sort(ord + 1, ord + sam[i].st.size(),
              [&](ul a, ul b) { return sam[i].st[a].len < sam[i].st[b].len; });
    for (ul it = sam[i].st.size() - 1; it >= 2; --it) {
      ul j = ord[it];
      sam[i].st[sam[i].st[j].fa].cnt += sam[i].st[j].cnt;
    }
  }
  cc[0] = 1;
  cc[1] = 1e9 + 6;
  cc[2] = 1e9 + 5;
  cc[3] = 1;
  cc[4] = 1;
  std::scanf("%llu%u", &k, &m);
  for (ul Case = 1; Case <= m; ++Case) {
    std::scanf("%s", str + 1);
    for (ul i = 1; i <= tau; ++i) {
      ul curr = 1;
      for (ul j = 1; str[j]; ++j) {
        curr = sam[i].st[curr].ch[str[j] - 'a'];
        if (!curr) {
          break;
        }
      }
      if (!curr) {
        ans[i] = 0;
      } else {
        ans[i] = sam[i].st[curr].cnt;
      }
    }
    std::printf("%u\n", linearrec(ans, cc, tau + 1, k));
  }
  return 0;
}