Factories

Each query gives two factory sets on a weighted tree and asks for the minimum distance between any factory in one set and any in the other.

Hard9Divide and conquerTreeShortest pathNo attempts yetTime limit6sMemory limit512 MB

Problem

The kingdom of IOI has NN cities numbered 00 through N1N-1. The cities are joined by N1N-1 two-way roads, and you can travel from any city to any other city along a few of these roads.

Many companies in the kingdom make special products. Each company makes exactly one kind of product, and no two companies make the same kind. Every company owns one or more factories, and each factory is built in one of the cities. Several companies may own factories in the same city.

Sometimes a company CAC_A needs the product of another company CBC_B (CACBC_A \ne C_B). The product is then carried from one factory of CBC_B to one factory of CAC_A. The two companies choose the pair of factories that makes the distance between them as small as possible.

You are first given the number of cities and the roads of the kingdom, then QQ queries. Query jj reads as follows. Company UjU_j, which owns factories in cities Xj,0,,Xj,Sj1X_{j,0}, \dots, X_{j,S_j-1}, needs the product of company VjV_j, which owns factories in cities Yj,0,,Yj,Tj1Y_{j,0}, \dots, Y_{j,T_j-1}. For each query, report the smallest distance needed to carry the product.

Input

The first line contains two integers NN and QQ separated by a space. The kingdom has NN cities and your program is given QQ queries.

Line i+1i+1 of the next N1N-1 lines (0iN20 \le i \le N-2) contains three integers AiA_i, BiB_i, DiD_i separated by spaces. There is a road of length DiD_i between city AiA_i and city BiB_i.

The next 3Q3Q lines hold the queries. The information of query jj (0jQ10 \le j \le Q-1) occupies lines 3j+13j+1 through 3j+33j+3.

Line 3j+13j+1 contains two integers SjS_j and TjT_j separated by a space. Company UjU_j owns factories in SjS_j cities and company VjV_j owns factories in TjT_j cities.

Line 3j+23j+2 contains the SjS_j integers Xj,0,,Xj,Sj1X_{j,0}, \dots, X_{j,S_j-1} separated by spaces. Company UjU_j owns factories in these cities.

Line 3j+33j+3 contains the TjT_j integers Yj,0,,Yj,Tj1Y_{j,0}, \dots, Y_{j,T_j-1} separated by spaces. Company VjV_j owns factories in these cities.

Every input satisfies the following conditions.

  • 2N5000002 \le N \le 500\,000
  • 1Q1000001 \le Q \le 100\,000
  • 0AiN10 \le A_i \le N-1, 0BiN10 \le B_i \le N-1, AiBiA_i \ne B_i (0iN20 \le i \le N-2)
  • 1Di1000000001 \le D_i \le 100\,000\,000 (0iN20 \le i \le N-2)
  • You can reach every other city from any city along the roads.
  • 1SjN11 \le S_j \le N-1, 1TjN11 \le T_j \le N-1 (0jQ10 \le j \le Q-1)
  • 0Xj,kN10 \le X_{j,k} \le N-1 (0kSj10 \le k \le S_j-1), 0Yj,kN10 \le Y_{j,k} \le N-1 (0kTj10 \le k \le T_j-1)
  • Within one query, Xj,0,,Xj,Sj1,Yj,0,,Yj,Tj1X_{j,0}, \dots, X_{j,S_j-1}, Y_{j,0}, \dots, Y_{j,T_j-1} are pairwise different.
  • S0+S1++SQ11000000S_0 + S_1 + \dots + S_{Q-1} \le 1\,000\,000
  • T0+T1++TQ11000000T_0 + T_1 + \dots + T_{Q-1} \le 1\,000\,000

Output

Print the answer to each query on its own line, in the order the queries are given.

Hint

The three queries of the example are answered as follows.

  • In query 0, company U0U_0 owns factories in cities 0 and 6, and company V0V_0 owns factories in cities 3 and 4. The shortest route runs from the factory of V0V_0 in city 3 to the factory of U0U_0 in city 6, and its length is 12.
  • In query 1, company U1U_1 owns factories in cities 0, 1 and 3, and company V1V_1 owns factories in cities 4 and 6. The shortest route runs from the factory of V1V_1 in city 6 to the factory of U1U_1 in city 1, and its length is 3.
  • In query 2, company U2U_2 owns a factory in city 2 and company V2V_2 owns a factory in city 5. The distance from the factory of V2V_2 in city 5 to the factory of U2U_2 in city 2 is 11.