Kozak Vus and the Holiday#10164

Kozak Vus and the Holiday

2.5 seconds
256.642 megabytes
Hard

In the kingdom of Potokolandia, the residents are known for their meticulous nature, especially when it comes to planning celebrations. They schedule all events a century in advance to ensure everything runs smoothly. Cossack Vus wants to invite his friend, Cossack Vukh, to visit one of the kingdom's cities and attend as many celebrations as possible.

The kingdom consists of cities connected by n-1 bidirectional roads, allowing travel between any two cities, possibly via other cities. Traveling along the -th road takes l_i days.

Each celebration in Potokolandia is defined by the city number c_i where it occurs and the day number d_i when it takes place. Cossack Vukh is efficient with his time; if he attends a celebration on day , he can leave that same day, arrive in another city the next day (if the road travel time l_i=1), and attend another celebration if one is scheduled.

Cossack Vukh is fortunate to arrive in the kingdom on day and can initially choose to arrive in any city. Cossack Vus wants to determine the maximum number of celebrations his friend can attend and seeks your help to find this out.

Input

The first line contains a single integer (1 \le n \le 2 \cdot 10^5) — the number of cities in the kingdom.

Each of the next n-1 lines contains three integers a_i, b_i, and l_i (1 \le a_i, b_i \le n, 1 \le l_i \le 10^9) — the cities connected by the road and the number of days required to travel it. The graph is guaranteed to be connected.

The next line contains a single integer (1 \le m \le 2 \cdot 10^5) — the number of celebrations in the kingdom.

Each of the next lines contains two integers c_i and d_i (1 \le c_i \le n, 1 \le d_i \le 10^9) — the city number and the day number of the -th celebration.

Output

Output a single number — the maximum number of celebrations Cossack Vukh can attend.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Note

For example, Cossack Vukh can initially arrive in city and wait one day for a celebration. On the first day, he can travel for two days to city , where a celebration occurs on the third day. On the third day, he can travel to city , where another celebration is held on the fourth day. However, he cannot attend the last celebration because it takes days to reach city . Thus, he attends celebrations.