/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 */

#include <bits/stdc++.h>

#define fora(i, n) for (int i = 1; i <= (int)(n); i++)

using namespace std;

const int N = 3e5 + 3, Q = 11;

vector<int> c[N];
int root, l, r, n, q, ans[Q][N], color[N];

void dfs( int j, int v ) {
	ans[j][v] = (l <= color[v] && color[v] <= r);
	for (int x : c[v])
		dfs(j, x), ans[j][v] += ans[j][x];
}

template <class T = int> inline T readInt(); 
template <class T> inline void writeInt( T x );
inline void writeChar( int x ); 
inline void flush();

int main() {
	n = readInt();
	q = readInt();
	fora(i, n) {
		int p = readInt();
		color[i] = readInt();
		if (!p)
			root = i;
		else
			c[p].push_back(i);
	}
	fora(j, q) {
		l = readInt();
		r = readInt();
		dfs(j, root);
	}
	fora(i, n)
		fora(j, q)
			writeInt(ans[j][i]), writeChar(" \n"[j == q]);
	flush();
	return 0;
}

/** Read */

static const int buf_size = 4096;

inline int getChar() {
	static char buf[buf_size];
	static int len = 0, pos = 0;
	if (pos == len)
		pos = 0, len = fread(buf, 1, buf_size, stdin);
	if (pos == len)
		return -1;
	return buf[pos++];
}

inline int readChar() {
	int c = getChar();
	while (c <= 32)
		c = getChar();
	return c;
}

template <class T>
inline T readInt() {
	int s = 1, c = readChar();
	T x = 0;
	if (c == '-')
		s = -1, c = getChar();
	while ('0' <= c && c <= '9')
		x = x * 10 + c - '0', c = getChar();
	return s == 1 ? x : -x;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
	if (write_pos == buf_size)
		fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
	write_buf[write_pos++] = x;
}

inline void flush() {
	if (write_pos)
		fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}

template <class T> 
inline void writeInt( T x ) {
	if (x < 0)
		writeChar('-'), x = -x;

	char s[24];
	int n = 0;
	while (x || !n)
		s[n++] = '0' + x % 10, x /= 10;
	while (n--)
		writeChar(s[n]);
}