#include <bits/stdc++.h>

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro,...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro,nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro,nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro,nargs) macro ## nargs
#define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)
#define DBN1(a)            cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)        cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)        cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)    cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)    cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"

#define endl '\n'
#define DBN1D(x) cerr<<#x<<endl;for(auto _:x){cerr<<_<<" ";}cerr<<endl
#define DBN2D(x) cerr<<#x<<endl;for(auto _:x){for(auto __:_){cerr<<__<<" ";}cerr<<endl;}cerr<<"------"<<endl
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp(x,y) make_pair(x,y)
#define mpp(w,x,y,z) mp(mp(w,x),mp(y,z))
using namespace std;
typedef long long loli;
typedef vector<loli> vl;
typedef vector<vl> vvl;
typedef pair<loli,loli> pll;
typedef pair<pll,pll> pllll;

vl in,out,depth;
vvl edge,din;
int cnt=0;

int bs(vl&arr,int n,loli t,int l,int u){
    if(l==u){
        assert(u==0);
        return -1;
    }
    //    DBN("l",t,l,u);
    int mid=(l+u)/2;
    if(u-l==1){
        if(arr[l]>=t)
            return l;
        return u;
    }
    if(arr[mid]<t)
        return bs(arr,n,t,mid,u);
    else
        return bs(arr,n,t,l,mid);
}

void dfs(loli x){
    in[x]=++cnt;
    din[depth[x]].push_back(in[x]);
    for(auto v:edge[x]){
        depth[v]=depth[x]+1;
        dfs(v);
    }
    out[x]=++cnt;
}

void solve(){
    int n;
    cin>>n;
    edge.assign(n+1,vl());
    depth.resize(n+1,0);
    din.resize(n);
    in.resize(n+1);
    out=in;
    for(int i=2;i<=n;++i){
        int p;
        cin>>p;
        edge[p].push_back(i);
    }
    dfs(1);
//    DBN2D(din);
    int q;
    cin>>q;
    for(auto x:vl(q)){
        int u,d;
        cin>>u>>d;
        if(depth[u]==d){
            cout<<1<<endl;
        }else if(depth[u]>d){
            cout<<0<<endl;
        }else{
//            DBN(u,d);
//            DBN1D(in);
//            DBN1D(out);
//            DBN1D(din[d]);
            int l=bs(din[d],din[d].size(),in[u],0,din[d].size());
            int r=bs(din[d],din[d].size(),out[u],0,din[d].size());
//            DBN(l,r,r-l);
            cout<<r-l<<endl;

        }
    }
}

int main(){
    sync;
    solve();
    return 0;
}
#include <bits/stdc++.h>

long long func(std::vector<std::pair<long long, long long>> &vw, std::vector<long long> &boxsize, int l, int r) {
  std::vector<long long> box;
  for (int i = 0; i < (int)boxsize.size(); ++i) {
    if (i < l || i > r) box.push_back(boxsize[i]);
  }

  std::vector<bool> used(box.size(), false);
  std::sort(box.begin(), box.end());

  long long res = 0LL;
  for (int i = 0; i < (int)vw.size(); ++i) {
    long long value = vw[i].first;
    long long weight = vw[i].second;

    int index = std::lower_bound(box.begin(), box.end(), weight) - box.begin();
    while (index < (int)box.size() && used[index]) ++index;
    if (index < (int)box.size()) { used[index] = true; res += value; }
  }

  return res;
}

int main() {
  int n, m, q;
  std::cin >> n >> m >> q;
  std::vector<std::pair<long long, long long>> vw(n);
  for (int i = 0; i < n; ++i) std::cin >> vw[i].second >> vw[i].first;
  std::vector<long long> boxsize(m);
  for (int i = 0; i < m; ++i) std::cin >> boxsize[i];

  std::sort(vw.begin(), vw.end(), std::greater<std::pair<long long, long long>>());

  std::vector<long long> res;
  for (int i = 0; i < q; ++i) {
    int l, r;
    std::cin >> l >> r;
    --l; --r;
    res.push_back(func(vw, boxsize, l, r));    
  }

  for (long long ans : res) std::cout << ans << std::endl;
  return 0;  
}
