from collections import deque

import sys

import heapq

n = int(eval(input()))

V = [[int(i) for i in input().split()] for _ in range(n)]

dis = [sys.maxsize for _ in range(n)]

dis[0] = 0

h = []

for i in range(n):

    heapq.heappush(h,(dis[i],i))

while(len(h)>0):

    node = heapq.heappop(h)

    tmp = node[1]

    for i in range(V[tmp][1]):

        ind = V[tmp][2*i+2]

        cos = V[tmp][2*i+3]

        if cos + dis[tmp] < dis[ind]:

            dis[ind] = cos + dis[tmp]

            heapq.heappush(h,(dis[ind],ind))

for i,j in enumerate(dis):

    print((i,j))

import sys

import heapq

n = int(eval(input()))

V = [[int(i) for i in input().split()] for _ in range(n)]

dis = [sys.maxsize for _ in range(n)]

dis[0] = 0

h = []

for i in range(n):

    heapq.heappush(h,(dis[i],i))

while(len(h)>0):

    node = heapq.heappop(h)

    tmp = node[1]

    for i in range(V[tmp][1]):

        ind = V[tmp][2*i+2]

        cos = V[tmp][2*i+3]

        if cos + dis[tmp] < dis[ind]:

            dis[ind] = cos + dis[tmp]

            heapq.heappush(h,(dis[ind],ind))

for i,j in enumerate(dis):

    print((i,j))

from collections import deque
import sys
import heapq

n = int(eval(input()))
V = [[int(i) for i in input().split()] for _ in range(n)]
dis = [sys.maxsize for _ in range(n)]
dis[0] = 0
h = []
for i in range(n):
    heapq.heappush(h, (dis[i], i))
while len(h) > 0:
    node = heapq.heappop(h)
    tmp = node[1]
    for i in range(V[tmp][1]):
        ind = V[tmp][2 * i + 2]
        cos = V[tmp][2 * i + 3]
        if cos + dis[tmp] < dis[ind]:
            dis[ind] = cos + dis[tmp]
            heapq.heappush(h, (dis[ind], ind))
for i, j in enumerate(dis):
    print((i, j))

import sys
import heapq

n = int(eval(input()))
V = [[int(i) for i in input().split()] for _ in range(n)]
dis = [sys.maxsize for _ in range(n)]
dis[0] = 0
h = []
for i in range(n):
    heapq.heappush(h, (dis[i], i))
while len(h) > 0:
    node = heapq.heappop(h)
    tmp = node[1]
    for i in range(V[tmp][1]):
        ind = V[tmp][2 * i + 2]
        cos = V[tmp][2 * i + 3]
        if cos + dis[tmp] < dis[ind]:
            dis[ind] = cos + dis[tmp]
            heapq.heappush(h, (dis[ind], ind))
for i, j in enumerate(dis):
    print((i, j))

-from collections import deque