#D4820. Single Source Shortest Path II

    ID: 4006 Type: Default 1000ms 134MiB

Single Source Shortest Path II

Single Source Shortest Path II

For a given weighted graph G=(V,E)G = (V, E), find the shortest path from a source to each vertex. For each vertex uu, print the total weight of edges on the shortest path from vertex 00 to uu.

Constraints

  • 1n10,0001 \leq n \leq 10,000
  • 0ci100,0000 \leq c_i \leq 100,000
  • E<500,000|E| < 500,000
  • All vertices are reachable from vertex 00

Input

In the first line, an integer nn denoting the number of vertices in GG is given. In the following nn lines, adjacency lists for each vertex uu are respectively given in the following format:

uu kk v1v_1 c1c_1 v2v_2 c2c_2 ... vkv_k ckc_k

Vertices in GG are named with IDs 0,1,...,n10, 1, ..., n-1. uu is ID of the target vertex and kk denotes its degree. vi(i=1,2,...k)v_i (i = 1, 2, ... k) denote IDs of vertices adjacent to uu and cic_i denotes the weight of a directed edge connecting uu and viv_i (from uu to viv_i).

Output

For each vertex, print its ID and the distance separated by a space character in a line respectively. Print in order of vertex IDs.

Example

Input

5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3

Output

0 0 1 2 2 2 3 1 4 3

inputFormat

Input

In the first line, an integer nn denoting the number of vertices in GG is given. In the following nn lines, adjacency lists for each vertex uu are respectively given in the following format:

uu kk v1v_1 c1c_1 v2v_2 c2c_2 ... vkv_k ckc_k

Vertices in GG are named with IDs 0,1,...,n10, 1, ..., n-1. uu is ID of the target vertex and kk denotes its degree. vi(i=1,2,...k)v_i (i = 1, 2, ... k) denote IDs of vertices adjacent to uu and cic_i denotes the weight of a directed edge connecting uu and viv_i (from uu to viv_i).

outputFormat

Output

For each vertex, print its ID and the distance separated by a space character in a line respectively. Print in order of vertex IDs.

Example

Input

5 0 3 2 3 3 1 1 2 1 2 0 2 3 4 2 3 0 3 3 1 4 1 3 4 2 1 0 1 1 4 4 3 4 2 2 1 3 3

Output

0 0 1 2 2 2 3 1 4 3

样例

5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
0 0

1 2 2 2 3 1 4 3

</p>