A fairground has the form of a regular polygon consisting of n vertices, the vertices are numbered from 1 to n clockwise. The organizer divides the fair area by nβ3 dividing lines to obtain nβ2 triangular booths, the dividing lines do not intersect inside the polygon, the dividing line k passes through two distinct vertices ik,jk (1β€kβ€nβ3). Thus, a booth will have three sides, each side is a polygonal edge or dividing line. To encourage visitors to visit the stalls, the organizer will give prizes worth tk to visitors when passing through the kth dividing line.
Alice plans to enter the fairground from a booth whose face is an edge connecting vertices u and vertex (u then exit the fairground from a booth whose face is an edge connecting vertices v and vertex (v. Alice hopes that each booth will be visited no more than once and the total value of the rewards received will be the greatest. Note that uβ v and the operation is to divide and receive remainder.
Requirement: Alice has q assumptions, each assumption described by two integers u,v means that Alice enters from the edge connecting vertex u and vertex (u and comes out from the edge connecting vertex v and vertex (v, for each assumption, help Alice compute the maximum possible total value of the rewards that can be achieved.
### Input
- The first line contains two positive integers n,q (qβ€n);
- The k-th line (1β€kβ€nβ3) contains three positive integers ik,jk,tk describing the k-th dividing line (1β€ik,jkβ€n andikβ jk;tkβ€109);
- The second line s (1β€sβ€q) includes two positive integers u,v describing an assumption.
### Output
- Write out q lines, each line contains an integer that is the maximum total value of the rewards that can be achieved.
### Example
Input:
622412522631512
Output:
36
### Subtask
- Subtask 1 (40%) : nβ€10
- Subtask 2 (30%) : nβ€100
- Subtask 3 (30%) : nβ€105