Kozak Vus and the Holiday
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 bidirectional roads, allowing travel between any two cities, possibly via other cities. Traveling along the -th road takes days.
Each celebration in Potokolandia is defined by the city number where it occurs and the day number 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 ), 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 Format
The first line contains a single integer () — the number of cities in the kingdom.
Each of the next lines contains three integers , , and (, ) — 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 () — the number of celebrations in the kingdom.
Each of the next lines contains two integers and (, ) — the city number and the day number of the -th celebration.
Output Format
Output a single number — the maximum number of celebrations Cossack Vukh can attend.
Examples
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.