## implementation

#include <iostream>
#include <vector>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
typedef long long ll;
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }

ll powi(ll x, ll y, ll p) { assert (y >= 0); x %= p; if (x < 0) x += p; ll z = 1; for (ll i = 1; i <= y; i <<= 1) { if (y & i) z = z * x % p; x = x * x % p; } return z; } // O(log y)
ll inv(ll x, ll p) { assert ((x % p + p) % p != 0); return powi(x, p-2, p); } // p must be a prime, O(log p)

unsigned xor128_x = 123456789, xor128_y = 362436069, xor128_z = 521288629, xor128_w = 88675123;
unsigned xor128() {
unsigned t = xor128_x ^ (xor128_x << 11);
xor128_x = xor128_y; xor128_y = xor128_z; xor128_z = xor128_w;
return xor128_w = xor128_w ^ (xor128_w >> 19) ^ (t ^ (t >> 8));
}
void generateA(int N, vector<int> & A) {
for(int i = 0; i < N; ++ i) A[i] = xor128() % 100003;
}
const int mod = 100003;

int main() {
int n, q; cin >> n >> q;
vector<int> a(n); generateA(n, a);
vector<int> in_a(mod); repeat (i,n) in_a[a[i]] = true;
while (q --) {
int b; cin >> b;
int ans = -1;
if (b == 0) {
ans = 0;
} else if (n < 1000) {
ans = -1;
repeat (i,n) setmax<int>(ans, a[i] *(ll) b % mod);
} else {
int b_inv = inv(b, mod);
repeat_reverse (c,mod) {
if (in_a[b_inv *(ll) c % mod]) {
ans = c;
break;
}
}
}
cout << ans << endl;
}
return 0;
}