import sys



f_i = sys.stdin



n = int(f_i.readline())



adj = [[(int(cost), int(v_n)) for v_n, cost in zip(x.split()[2::2], x.split()[3::2])] for x in f_i]



import heapq



def dijkstra():

    PQ = [(0, 0)]

    distance = [999900001] * n



    distance[0] = 0

    

    while PQ:

        uc = heapq.heappop(PQ)

        u = uc[1]

        

        for vc in adj[u]:

            v = vc[1]

            t_cost = distance[u] + vc[0]

            if t_cost < distance[v]:

                distance[v] = t_cost

                heapq.heappush(PQ, (t_cost, v))



    for v, d in enumerate(distance):

        print((v, d))





dijkstra()
import sys



f_i = sys.stdin



n = int(f_i.readline())



adj = [[]] * n

for x in f_i:

    x = list(map(int, x.split()))

    adj[x[0]] = [c_v for c_v in zip(x[3::2], x[2::2])]



import heapq



def dijkstra():

    PQ = [(0, 0)]

    isVisited = [False] * n

    distance = [999900001] * n



    distance[0] = 0

    

    while PQ:

        uc = heapq.heappop(PQ)

        u = uc[1]



        if uc[0] > distance[u]:

            continue



        isVisited[u] = True

        

        for vc in adj[u]:

            v = vc[1]

            if isVisited[v] == True:

                continue

            t_cost = distance[u] + vc[0]

            if t_cost < distance[v]:

                distance[v] = t_cost

                heapq.heappush(PQ, (t_cost, v))



    for v, d in enumerate(distance):

        print((v, d))





dijkstra()
import sys

f_i = sys.stdin
n = int(f_i.readline())
adj = [
    [(int(cost), int(v_n)) for v_n, cost in zip(x.split()[2::2], x.split()[3::2])]
    for x in f_i
]
import heapq


def dijkstra():
    PQ = [(0, 0)]
    distance = [999900001] * n
    distance[0] = 0
    while PQ:
        uc = heapq.heappop(PQ)
        u = uc[1]
        for vc in adj[u]:
            v = vc[1]
            t_cost = distance[u] + vc[0]
            if t_cost < distance[v]:
                distance[v] = t_cost
                heapq.heappush(PQ, (t_cost, v))
    for v, d in enumerate(distance):
        print((v, d))


dijkstra()

import sys

f_i = sys.stdin
n = int(f_i.readline())
adj = [[]] * n
for x in f_i:
    x = list(map(int, x.split()))
    adj[x[0]] = [c_v for c_v in zip(x[3::2], x[2::2])]
import heapq


def dijkstra():
    PQ = [(0, 0)]
    isVisited = [False] * n
    distance = [999900001] * n
    distance[0] = 0
    while PQ:
        uc = heapq.heappop(PQ)
        u = uc[1]
        if uc[0] > distance[u]:
            continue
        isVisited[u] = True
        for vc in adj[u]:
            v = vc[1]
            if isVisited[v] == True:
                continue
            t_cost = distance[u] + vc[0]
            if t_cost < distance[v]:
                distance[v] = t_cost
                heapq.heappush(PQ, (t_cost, v))
    for v, d in enumerate(distance):
        print((v, d))


dijkstra()

-adj = [ -    [(int(cost), int(v_n)) for v_n, cost in zip(x.split()[2::2], x.split()[3::2])] -    for x in f_i -] +adj = [[]] * n +for x in f_i: +    x = list(map(int, x.split())) +    adj[x[0]] = [c_v for c_v in zip(x[3::2], x[2::2])] +    isVisited = [False] * n +        if uc[0] > distance[u]: +            continue +        isVisited[u] = True +            if isVisited[v] == True: +                continue