#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
const int maxn = 15;
const int logk = 31;
int n, k, q;
int par[1 + maxn];
int nxt[1 << maxn];
int ans[1 << maxn];
int lift[1 << maxn][logk];
int find_nxt(int mask) {
vector<int> state(1 + n, 0);
for(int i = 1; i <= n; i++) {
state[i] = (mask >> (i - 1)) & 1;
}
vector<int> subtreexor(1 + n, 0);
for(int i = n; i >= 1; i--) {
int prevxor = subtreexor[i];
subtreexor[i] ^= state[i];
state[i] ^= prevxor;
subtreexor[par[i]] ^= subtreexor[i];
}
int res = 0;
for(int i = 1; i <= n; i++) {
res += (1 << (i - 1)) * state[i];
}
return res;
}
void solve() {
cin >> n >> k >> q;
for(int i = 2; i <= n; i++) {
cin >> par[i];
}
for(int i = 0; i < (1 << n); i++) {
nxt[i] = find_nxt(i);
}
for(int i = 0; i < (1 << n); i++) {
lift[i][0] = nxt[i];
}
for(int j = 1; j < logk; j++) {
for(int i = 0; i < (1 << n); i++) {
lift[i][j] = lift[lift[i][j - 1]][j - 1];
}
}
for(int i = 0; i < (1 << n); i++) {
ans[i] = i;
for(int j = logk - 1; j >= 0; j--) {
if((1 << j) & k) {
ans[i] = lift[ans[i]][j];
}
}
}
for(int qi = 1; qi <= q; qi++) {
int mask = 0;
for(int i = 0; i < n; i++) {
int x;
cin >> x;
mask += x * (1 << i);
}
cout << (ans[mask] & 1) << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}