Under construction

Still being built. Things may change

Beyond the Rescue

Time limit3sMemory limit256 MB

Summary
Find the fastest path from s to t in a weighted tree that avoids every street the guards walk on their cyclic route, printed modulo 998244353 or -1.
Level

Hard9 of 10

Topics
Tree, Shortest path, Intervals
Solved
No attempts yet

Statement

Riatla is a little-known member of the Assassins Order (well-known assassins, as you can guess, do not live long). After performing one mission, Riatla faces a problem: the streets of the city are flooded by guards, and he needs a new escape plan from the crime scene.

The city has a tree-like structure. There are nn squares, connected with n−1n-1 two-way streets, and there is exactly one path between every two squares.

The guards patrol the city in a cyclic route. They choose a sequence of squares v1,v2,…,vkv_1, v_2, \ldots, v_k. After visiting square viv_i, the guards head to square vi+1v_{i+1}. If the two squares are not directly connected, the guards take the shortest path between them. After visiting vkv_k, they go to v1v_1 and start the route again.

Riatla is good at disguising. Squares are crowded, so he can stay on a square without being noticed, even if the guards are on the same square. Streets are nearly empty, though, so if Riatla and the guards are on the same street at any moment, the guards shoot him with bows, regardless of the distance between them.

Each street takes cic_i time for the guards and did_i time for Riatla to cross. Compute the minimal time Riatla needs to get from square ss, where he is now, to square tt, where his friends are waiting. Print the answer modulo 998 244 353998\,244\,353.

Input

The first line contains one integer tt, the number of test cases. Each test case starts with two integers nn and kk, the number of squares and the number of important squares on the guards' path (2≤n,k≤200 0002 \le n, k \le 200\,000).

Each of the next n−1n-1 lines contains four integers uiu_i, viv_i, cic_i, did_i: the two squares joined by a street, the time the guards need to walk it, and the time Riatla needs to walk it (1≤ui,vi≤n1 \le u_i, v_i \le n; 1≤ci,di≤1081 \le c_i, d_i \le 10^8). The given graph is guaranteed to be a tree.

The next line contains kk integers aia_i, the important squares on the guards' path in visiting order (1≤ai≤n1 \le a_i \le n; ai≠ai+1a_i \ne a_{i+1}; a1≠aka_1 \ne a_k).

The last line contains two integers ss and tt, the starting square and the target square (1≤s,t≤n1 \le s, t \le n; s≠ts \ne t).

The sum of nn and the sum of kk over all test cases do not exceed 200 000200\,000 each.

Output

For each test case, print on its own line the minimal time Riatla needs, modulo 998 244 353998\,244\,353. If Riatla cannot reach tt without being spotted, print −1-1.

Examples1

  1. Example 1

    Input
    2
    5 4
    1 2 1 4
    2 3 1 4
    3 4 1 4
    4 5 10 10
    1 4 1 5
    1 4
    2 2
    1 2 2 1
    1 2
    1 2
    
    Expected output
    16
    -1