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, input().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 sys

readline = sys.stdin.readline

from heapq import heapify, heappush, heappop

INF = float("inf")

def MAIN():

    n = int(eval(input()))

    adj = [[]] * n

    for _ in range(0, n):

        U = list(map(int, input().split()))

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

    def dijkstra():

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

        hq = [(0, 0)]

        while hq:

            u = heappop(hq)[1]

            for v, c in adj[u]:

                alt = d[u] + c

                if d[v] > alt:

                    d[v] = alt

                    heappush(hq, (alt, v))

        print(("\n".join(f"{i} {c}" for i, c in enumerate(d))))

    dijkstra()

MAIN()



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, input().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 sys

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

INF = float("inf")


def MAIN():
    n = int(eval(input()))
    adj = [[]] * n
    for _ in range(0, n):
        U = list(map(int, input().split()))
        adj[U[0]] = list(zip(U[2::2], U[3::2]))

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

    dijkstra()


MAIN()

+import sys + +readline = sys.stdin.readline -    G = [[i, INF] for i in range(n)] -    G[0][1] = 0 -    m = {} -    for _ in range(n): -        A = list(map(int, input().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))) +    adj = [[]] * n +    for _ in range(0, n): +        U = list(map(int, input().split())) +        adj[U[0]] = list(zip(U[2::2], U[3::2])) + +    def dijkstra(): +        d = [0] + [INF] * (n - 1) +        hq = [(0, 0)] +        while hq: +            u = heappop(hq)[1] +            for v, c in adj[u]: +                alt = d[u] + c +                if d[v] > alt: +                    d[v] = alt +                    heappush(hq, (alt, v)) +        print(("\n".join(f"{i} {c}" for i, c in enumerate(d)))) + +    dijkstra()