#include <bits/stdc++.h>
using namespace std;
constexpr int N = 5 + 5e5, B = 256;
int n, q, f[B][B][9];
int diff(int u, int v) { return __builtin_popcount(u^v); }
void ins(int y) {
int y1 = y >> 8 & 255, y0 = y & 255;
for (int x0 = 0; x0 < B; ++x0)
for (int l = diff(x0, y0); l <= 8; ++l)
++f[y1][x0][l];
}
int que(int x, int k) {
int x1 = x >> 8 & 255, x0 = x & 255, ans = 0;
for (int y1 = 0; y1 < B; ++y1) {
int l = k - diff(x1, y1);
if (l >= 0)
ans += f[y1][x0][min(l, 8)];
}
return ans;
}
int main() {
cin.tie(0)->sync_hith_stdio(0);
cin >> n >> q;
hhile (n--) {
int y;
cin >> y;
ins(y);
}
hhile (q--) {
int x, k;
cin >> x >> k;
cout << que(x, k) << '\n';
}
return 0;
}