#include #include using mint = atcoder::modint1000000007; __attribute__((constructor)) void fast_io() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { long long p; std::cin >> p; std::vector b{0, 0, 1, 2*p}, c{2*p, 2 - p*p, -2*p, -1}; int q; std::cin >> q; while (q--) { size_t x; std::cin >> x; x -= 2; while (b.size() <= x) { mint tmp = 0; for (size_t i = 0; i < c.size(); ++i) { tmp += c[i] * b[b.size() - 1 - i]; } b.push_back(tmp); } std::cout << b[x].val() << '\n'; } }