from sys import stdin

import heapq

INF = 1<<21

n = int(stdin.readline())

adj = [[]] * n

for u in range(0, n):

    U = list(map(int, stdin.readline().split()[2:]))

    adj[u] = (e for e in zip(U[0::2], U[1::2]))

def dijkstra():

    d = [0] + [INF] * (n - 1)

    hq = [(0, 0)]

    while hq:

        u = heapq.heappop(hq)[1]

        for v, c in adj[u]:

            alt = d[u] + c

            if d[v] > alt:

                d[v] = alt

                heapq.heappush(hq, (alt, v))

    for i, c in enumerate(d):

        print((i, c))

dijkstra()
from sys import stdin

import heapq

INF = 1<<21

n = int(stdin.readline())

adj = [[]] * n

for u in range(0, n):

    U = list(map(int, stdin.readline().split()[2:]))

    adj[u] = list(zip(U[0::2], U[1::2]))

def dijkstra():

    d = [0] + [INF] * (n - 1)

    hq = [(0, 0)]

    while hq:

        u = heapq.heappop(hq)[1]

        for v, c in adj[u]:

            alt = d[u] + c

            if d[v] > alt:

                d[v] = alt

                heapq.heappush(hq, (alt, v))

    for i, c in enumerate(d):

        print((i, c))

dijkstra()
from sys import stdin
import heapq

INF = 1 << 21
n = int(stdin.readline())
adj = [[]] * n
for u in range(0, n):
    U = list(map(int, stdin.readline().split()[2:]))
    adj[u] = (e for e in zip(U[0::2], U[1::2]))


def dijkstra():
    d = [0] + [INF] * (n - 1)
    hq = [(0, 0)]
    while hq:
        u = heapq.heappop(hq)[1]
        for v, c in adj[u]:
            alt = d[u] + c
            if d[v] > alt:
                d[v] = alt
                heapq.heappush(hq, (alt, v))
    for i, c in enumerate(d):
        print((i, c))


dijkstra()

from sys import stdin
import heapq

INF = 1 << 21
n = int(stdin.readline())
adj = [[]] * n
for u in range(0, n):
    U = list(map(int, stdin.readline().split()[2:]))
    adj[u] = list(zip(U[0::2], U[1::2]))


def dijkstra():
    d = [0] + [INF] * (n - 1)
    hq = [(0, 0)]
    while hq:
        u = heapq.heappop(hq)[1]
        for v, c in adj[u]:
            alt = d[u] + c
            if d[v] > alt:
                d[v] = alt
                heapq.heappush(hq, (alt, v))
    for i, c in enumerate(d):
        print((i, c))


dijkstra()

-    adj[u] = (e for e in zip(U[0::2], U[1::2])) +    adj[u] = list(zip(U[0::2], U[1::2]))