C. Shichieichou's Guidance
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

"The so-called Shichieichou (Seven-Shadow Butterflies) are the fragments of human memory..."

"The 'memories' of those who left behind attachments or regrets during their lifetime exist in this world in the form of butterflies."

"...Even though they are just memories, these are things that should not remain in this world."

"Someone must guide them back to where they truly belong."

"This is the Yamanomatsuri (Mountain Festival), which has been managed by the Sorakado family for generations."

"...There is one specific memory that I must find, no matter what..."

To fulfill the duties of the Sorakado family and to find that indispensable memory, Sorakado Ao needs to guide the Shichieichou scattered across the mountain toward the "Mayoi no Tachibana" (The Lost Mandarin Orange) during the Yamanomatsuri.

The mountain paths of Torishirojima can be represented as a tree$$$^{\text{∗}}$$$ with $$$n$$$ nodes, rooted at node $$$1$$$. It is guaranteed that every leaf node in the tree has the same depth (i.e., the distance to the root).

Due to the rugged mountain paths and the deep night, Ao's movement must follow these rules:

  1. Ao starts at time $$$0$$$ from any leaf node of her choice. Her goal is to reach the root node $$$1$$$, where the "Mayoi no Tachibana" is located.
  2. Ao can spend $$$1$$$ unit of time to move from her current node to its parent node.
  3. During the journey, Ao may use Inari's power at most once: she can spend $$$1$$$ unit of time to take a side path and move from her current non-root node at depth $$$d$$$ to any node at depth $$$d-1$$$.
  4. When Ao is at a node, she can successfully guide all Shichieichou at that location that have not yet disappeared (i.e., those with the current time $$$ \leq t_i$$$).

To allow as many Shichieichou as possible to return, please tell Ao the maximum number of butterflies she can guide.

$$$^{\text{∗}}$$$A tree with $$$n$$$ vertices is an undirected connected graph with $$$n$$$ vertices and $$$n-1$$$ edges. A rooted tree is a tree in which one of the vertices is special and is called the root.

Input

Each test contains multiple test cases. The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^4$$$), representing the number of test cases.

For each test case:

  • The first line contains two integers $$$n$$$, $$$m$$$ ($$$2 \le n \le 2 \times 10^5$$$, $$$0 \le m \le 2 \times 10^5$$$), representing the number of nodes in the tree and the number of Shichieichou, respectively.
  • The next $$$n-1$$$ lines each contain two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$), representing an edge in the tree.
  • The next $$$m$$$ lines each contain two integers $$$a_i$$$, $$$t_i$$$ ($$$1 \le a_i \le n$$$, $$$0 \le t_i \le n$$$), representing the location and the disappearance time of the $$$i$$$-th Shichieichou.

It is guaranteed that the sum of $$$n$$$ over all test cases and the sum of $$$m$$$ over all test cases do not exceed $$$2 \times 10^5$$$. It is also guaranteed that the given edges form a tree, and that all leaf nodes have the same depth.

Output

For each test case, output a single integer representing the maximum number of Shichieichou Ao can guide.

Example
Input
3
3 2
1 2
1 3
3 0
1 1
6 3
1 2
1 3
2 4
2 5
3 6
6 1
2 1
1 1
8 5
1 2
1 3
2 4
3 6
4 5
6 7
6 8
5 2
4 2
6 8
3 1
1 5
Output
2
2
3
Note

In the first test case, the tree is rooted at node $$$1$$$, and nodes $$$2$$$ and $$$3$$$ are both leaves. Starting from node $$$3$$$, one Seven-Shadow Butterfly can be guided at time $$$t=0$$$. Then, moving to node $$$1$$$, another butterfly can be guided at time $$$t=1$$$. Therefore, the answer is $$$2$$$.