#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <cstring>
#define For(i,x,y) for(int i = (x); i <= (y); i ++ )
#define fori(i,x,y) for(int i = (x); i < (y); i ++ )
#define sz(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define mst(x,a) memset(x,a,sizeof(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define db double
//#define endl '\n' 
#define debug(a) cout << #a << ": " << a << endl
using namespace std;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
typedef pair<int,int>pa;
typedef pair<ll,ll>pai;
typedef pair<db,db> pdd;
const db eps = 1e-6;
const db pi = acos(-1.0);

template<typename T1, typename T2> void ckmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> void ckmax(T1 &a, T2 b) { if (a < b) a = b; }
int read() {
    int x = 0, f = 0; char ch = getchar();
    while (!isdigit(ch)) f |= ch == '-', ch = getchar();
    while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
    return f ? -x : x;
}
template<typename T> void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x >= 10) print(x / 10);
    putchar(x % 10 + '0');
}
template<typename T> void print(T x, char let) {
    print(x), putchar(let);
}
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 2e5 + 10;

vector<int>e[maxn];
int dpt[maxn<<1];

int dfs_clock, seq[maxn], dfn[maxn], fa[maxn];
int in[maxn<<1], out[maxn<<1];
vector<vector<int>>dir(maxn);
void dfs(int x, int dis){
    in[x] = ++dfs_clock;
    //seq[dfn[x] = ++dfs_clock] = x;
    dir[dis].pb(in[x]);
   // dir.pb({dpt[x],dfn[x]});
    for(auto v:e[x]){
        dfs(v,dis+1);
    }
    out[x] = ++dfs_clock;
}
int pre[maxn];
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    For(v,2,n){
        cin>>fa[v];
        e[fa[v]].pb(v);
    }
    dfs(1,0);
   // debug("ok");
   // sort(ALL(dir));
    int q;
    cin>>q;
    while(q--){
        int u, d;
        cin>>u>>d;
        const auto di= dir[d];
        cout<<(lower_bound(di.cbegin(),di.cend(),out[u]) - lower_bound(di.cbegin(),di.cend(),in[u]) )<<endl;
    }
  //  }
    return 0;
}
#include <iostream>
using namespace std;

const int N_MX = 1e3;
int n;
int x[N_MX], y[N_MX];
int ans;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            double grad = double(y[j] - y[i]) / (x[j] - x[i]);
            if (grad >= -1.0 && grad <= 1.0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}