#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <cstring>
using namespace std;
#define mp make_pair
#define pp push_back
#define Sort(x) sort(x.begin(), x.end())
#define rep(i, x, y) for(int i = x; i < y; ++i)
#define Rep(i, x, y) for(int i = x; i <= y; ++i)
#define dRep(i, x, y) for(int i = x;i >= y; --i)
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long
#define all(v) v.begin(),v.end()
#define ii pair<int, int>
#define mem(x, v) memset(x, v, sizeof(x))
#define nl '\n'
#define MOD 1000000007
int arr[20001];
vector<ll>mini;
ll lcms[3][20001];
ll GCD(ll x, ll y)
{
if(y % x == 0)
return x;
else
return GCD(y % x, x) % MOD;
}
ll LCM(ll x, ll y)
{
return ((x % MOD) * (y % MOD)) / GCD(x, y);
}
int main()
{
int n, q;
//freopen("input.in", "r", stdin);
while(cin >> n >> q)
{
rep(i, 0, n)
{
cin >> arr[i];
}
mini.resize(n);
Rep(i, 1, n)
{
rep(j, 0, n - i + 1)
{
if(i == 1)
lcms[(i - 1 + 3) % 3][j] = arr[j];
else
lcms[(i - 1 + 3) % 3][j] = LCM(lcms[(i - 2 + 3) % 3][j], lcms[(i - 2 + 3) % 3][j + 1]) % MOD;
if(!j)
mini[i - 1] = lcms[(i - 1 + 3) % 3][j];
else
mini[i - 1] = min(mini[i - 1], lcms[(i - 1 + 3) % 3][j]);
}
}
int x;
rep(i, 0, q)
{
cin >> x;
cout << mini[x - 1] << nl;
}
}
return 0;
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPGRlcXVlPgojaW5jbHVkZS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