{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eClaris loves painting very much, so he painted a tree with beautiful colors.\u003cbr\u003e\u003cbr\u003eThe tree is a rooted tree with $n$ nodes which are conveniently labeled by $1,2,...,n$. Its root is the $1$-st node, and the $i$-th node is painted with color $c_i$. If $c_i\u003dc_j$, then we think these two nodes have the same color.\u003cbr\u003e\u003cbr\u003eWe define $depth_i$ as the distance between the $i$-th node and the root, and simply, the distance between two adjacent nodes is always $1$.\u003cbr\u003e\u003cbr\u003eStanding in front of this beautiful tree, Claris comes up with $m$ questions.\u003cbr\u003eIn each question, there are two integers $x$ and $d$, which means that Claris wants to know the number of different kinds of colors occur in $S$, where $S\u003d\\left\\{v|v\\ in\\ x\u0027s\\ subtree\\ and\\ depth_v\\leq depth_x+d\\right\\}$.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input contains an integer $T(1\\leq T\\leq 500)$, denoting the number of test cases.\u003cbr\u003e\u003cbr\u003eIn every test case, there are two integers $n(1\\leq n\\leq 100000)$ and $m(1\\leq m\\leq 100000)$ in the first line, denoting the number of nodes and queries.\u003cbr\u003eThe second line contains $n$ integers, the $i$-th integer $c_i(1\\leq c_i\\leq n)$ denotes the color of the $i$-th node.\u003cbr\u003eThe third line contains $n-1$ integers, the $i$-th integer $f_{i+1}(1\\leq f_i\u0026lt;i)$ denotes the father of the $i+1$-th node.\u003cbr\u003eIn the following $m$ lines, each line contains two integers $x(1\\leq x\\leq n)$ and $d(0\\leq d\u0026lt;n)$, denoting each query.\u003cbr\u003e\u003cbr\u003eThe input has been encoded, if you read $x$ and $d$, the real $x$ and $d$ are $x \\oplus last$ and $d \\oplus last$, where $last$ is the answer of the previous query and $\\oplus$ means bitwise exclusive-or.\u003cbr\u003e\u003cbr\u003eNotice : \u003cbr\u003eIf it is the first query in this test case, then $last\u003d0$.\u003cbr\u003eIt is guaranteed that $\\sum n \\leq 500000$ and $\\sum m \\leq 500000$.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each query output a single integer in a line, denoting the answer.\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n5 8\r\n1 3 3 2 2\r\n1 1 3 3\r\n1 0\r\n0 0\r\n3 0\r\n1 3\r\n2 1\r\n2 0\r\n6 2\r\n4 1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n2\r\n3\r\n1\r\n1\r\n2\r\n1\r\n1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}