#include <bits/stdc++.h>
using namespace std;
typedef vector<int> big_int;
bool les(big_int a, big_int b)
{
double A = 0, B = 0;
for(int i = 1; i < 60; i++)
A += a[i] * log(i);
for(int i = 1; i < 60; i++)
B += b[i] * log(i);
return A < B;
}
big_int tr(int t)
{
big_int ret(60);
for(int i = 2; i * i <= t; i++)
while(t % i == 0)
ret[i]++, t /= i;
if(t)
ret[t]++;
return ret;
}
const int mod = 1e9 + 7;
int bpow(int x, int n)
{
if(n == 0)
return 1;
int t = bpow(x, n >> 1);
if(n % 2 == 0)
return 1LL * t * t % mod;
else
return 1LL * x * t % mod * t % mod;
}
int get(big_int t)
{
int ret = 1;
for(int i = 0; i < 60; i++)
ret = 1LL * ret * bpow(i, t[i]) % mod;
return ret;
}
main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
big_int ans[n + 1];
for(int i = 1; i <= n; i++)
{
big_int t(60);
t[2] = 1000000;
ans[i] = t;
}
map<big_int, int> lens;
for(int i = 0; i < n; i++)
{
int t;
cin >> t;
big_int T = tr(t);
map<big_int, int> nlens;
nlens[T] = 1;
for(auto it: lens)
{
big_int TT = T;
for(int i = 0; i < 60; i++)
TT[i] = max(TT[i], it.first[i]);
nlens[TT] = max(nlens[TT], it.second + 1);
}
lens = nlens;
for(auto it: lens)
if(les(it.first, ans[it.second]))
ans[it.second] = it.first;
}
for(int i = n - 1; i; i--)
if(les(ans[i + 1], ans[i]))
ans[i] = ans[i + 1];
int ANS[n + 1];
for(int i = 1; i <= n; i++)
ANS[i] = get(ans[i]);
while(q--)
{
int x;
cin >> x;
cout << ANS[x] << "\n";
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiB2ZWN0b3I8aW50PiBiaWdfaW50OwoKYm9vbCBsZXMoYmlnX2ludCBhLCBiaWdfaW50IGIpCnsKICAgI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BuLCBxOwogICAgY2luID4+IG4gPj4gcTsKICAgIGJpZ19pbnQgYW5zW24gKyAxXTsKICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKQogICAgewogICAgICAgIGJpZ19pbnQgdCg2MCk7CiAgICAgICAgdFsyXSA9IDEwMDAwMDA7CiAgICAgICAgYW5zW2ldID0gdDsKICAgIH0KICAgIG1hcDxiaWdfaW50LCBpbnQ+IGxlbnM7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgewogICAgICAgIGludCB0OwogICAgICAgIGNpbiA+PiB0OwogICAgICAgIGJpZ19pbnQgVCA9IHRyKHQpOwogICAgICAgIG1hcDxiaWdfaW50LCBpbnQ+IG5sZW5zOwogICAgICAgIG5sZW5zW1RdID0gMTsKICAgICAgICBmb3IoYXV0byBpdDogbGVucykKICAgICAgICB7CiAgICAgICAgICAgIGJpZ19pbnQgVFQgPSBUOwogICAgICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgNjA7IGkrKykKICAgICAgICAgICAgICAgIFRUW2ldID0gbWF4KFRUW2ldLCBpdC5maXJzdFtpXSk7CiAgICAgICAgICAgIG5sZW5zW1RUXSA9IG1heChubGVuc1tUVF0sIGl0LnNlY29uZCArIDEpOwogICAgICAgIH0KICAgICAgICBsZW5zID0gbmxlbnM7CiAgICAgICAgZm9yKGF1dG8gaXQ6IGxlbnMpCiAgICAgICAgICAgIGlmKGxlcyhpdC5maXJzdCwgYW5zW2l0LnNlY29uZF0pKQogICAgICAgICAgICAgICAgYW5zW2l0LnNlY29uZF0gPSBpdC5maXJzdDsKICAgIH0KICAgIGZvcihpbnQgaSA9IG4gLSAxOyBpOyBpLS0pCiAgICAgICAgaWYobGVzKGFuc1tpICsgMV0sIGFuc1tpXSkpCiAgICAgICAgICAgIGFuc1tpXSA9IGFuc1tpICsgMV07CiAgICBpbnQgQU5TW24gKyAxXTsKICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKQogICAgICAgIEFOU1tpXSA9IGdldChhbnNbaV0pOwogICAgd2hpbGUocS0tKQogICAgewogICAgICAgIGludCB4OwogICAgICAgIGNpbiA+PiB4OwogICAgICAgIGNvdXQgPDwgQU5TW3hdIDw8ICJcbiI7CiAgICB9Cgp9