import sys

readline = sys.stdin.readline

from heapq import heapify, heappush, heappop

INF = float("inf")

def MAIN():

    n = int(eval(input()))

    G = [[i, INF] for i in range(n)]

    G[0][1] = 0

    m = {}

    for _ in range(n):

        A = list(map(int, readline().split()))

        m[A[0]] = {}

        for i in range(2, len(A), 2):

            m[A[0]][A[i]] = A[i + 1]

    dp = [(0, 0)]

    while dp:

        cost, u = heappop(dp)

        for v, c in list(m[u].items()):

            if G[v][1] > G[u][1] + c:

                G[v][1] = G[u][1] + c

                heappush(dp, (G[v][1], v))

    print(("\n".join(" ".join(map(str, a)) for a in G)))

MAIN()



import heapq

import sys

readline = sys.stdin.readline

def dijkstra(n):

    inf = 10 ** 6 + 1

    dist = [0] + [inf] * (n - 1)

    q = [(0, 0)]

    while q:

        u = heapq.heappop(q)[1]

        for (v, c) in edge[u]:

            alt = dist[u] + c

            if dist[v] > alt:

                dist[v] = alt

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

    return dist

n = int(eval(input()))

edge = [[]] * n

for _ in range(n):

    l = list(map(int, readline().split()))

    edge[l[0]] = (e for e in zip(l[2::2], l[3::2]))

for i, c in enumerate(dijkstra(n)):

    print((i, c))

import sys

readline = sys.stdin.readline
from heapq import heapify, heappush, heappop

INF = float("inf")


def MAIN():
    n = int(eval(input()))
    G = [[i, INF] for i in range(n)]
    G[0][1] = 0
    m = {}
    for _ in range(n):
        A = list(map(int, readline().split()))
        m[A[0]] = {}
        for i in range(2, len(A), 2):
            m[A[0]][A[i]] = A[i + 1]
    dp = [(0, 0)]
    while dp:
        cost, u = heappop(dp)
        for v, c in list(m[u].items()):
            if G[v][1] > G[u][1] + c:
                G[v][1] = G[u][1] + c
                heappush(dp, (G[v][1], v))
    print(("\n".join(" ".join(map(str, a)) for a in G)))


MAIN()

import heapq
import sys

readline = sys.stdin.readline


def dijkstra(n):
    inf = 10**6 + 1
    dist = [0] + [inf] * (n - 1)
    q = [(0, 0)]
    while q:
        u = heapq.heappop(q)[1]
        for (v, c) in edge[u]:
            alt = dist[u] + c
            if dist[v] > alt:
                dist[v] = alt
                heapq.heappush(q, (alt, v))
    return dist


n = int(eval(input()))
edge = [[]] * n
for _ in range(n):
    l = list(map(int, readline().split()))
    edge[l[0]] = (e for e in zip(l[2::2], l[3::2]))
for i, c in enumerate(dijkstra(n)):
    print((i, c))

+import heapq -from heapq import heapify, heappush, heappop - -INF = float("inf") -def MAIN(): -    n = int(eval(input())) -    G = [[i, INF] for i in range(n)] -    G[0][1] = 0 -    m = {} -    for _ in range(n): -        A = list(map(int, readline().split())) -        m[A[0]] = {} -        for i in range(2, len(A), 2): -            m[A[0]][A[i]] = A[i + 1] -    dp = [(0, 0)] -    while dp: -        cost, u = heappop(dp) -        for v, c in list(m[u].items()): -            if G[v][1] > G[u][1] + c: -                G[v][1] = G[u][1] + c -                heappush(dp, (G[v][1], v)) -    print(("\n".join(" ".join(map(str, a)) for a in G))) +def dijkstra(n): +    inf = 10**6 + 1 +    dist = [0] + [inf] * (n - 1) +    q = [(0, 0)] +    while q: +        u = heapq.heappop(q)[1] +        for (v, c) in edge[u]: +            alt = dist[u] + c +            if dist[v] > alt: +                dist[v] = alt +                heapq.heappush(q, (alt, v)) +    return dist -MAIN() +n = int(eval(input())) +edge = [[]] * n +for _ in range(n): +    l = list(map(int, readline().split())) +    edge[l[0]] = (e for e in zip(l[2::2], l[3::2])) +for i, c in enumerate(dijkstra(n)): +    print((i, c))