import heapq



n = int(eval(input()))

edges = [None] * n

for _ in range(n):

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

    edges[l[0]] = set((c, j) for j, c in (l[i:i + 2] for i in range(2, l[1] * 2 + 2, 2)))



min_costs = [0] * n

visited = [False] * n

visited[0] = True

queue = list(edges[0])

heapq.heapify(queue)



while queue:

    total_cost, vertex = heapq.heappop(queue)

    if visited[vertex]:

        continue

    visited[vertex] = True

    min_costs[vertex] = total_cost

    for cost, vertex2 in edges[vertex]:

        if not visited[vertex2]:

            heapq.heappush(queue, (total_cost + cost, vertex2))



for r in enumerate(min_costs):

    print((*r))
import heapq



n = int(eval(input()))

edges = [None] * n

for _ in range(n):

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

    edges[l[0]] = set((c, j) for j, c in (l[i:i + 2] for i in range(2, l[1] * 2 + 2, 2)))



min_costs = [0] * n

visited = [False] * n

visited[0] = True

queue = list(edges[0])

heapq.heapify(queue)

remains = n - 1



while True:

    total_cost, vertex = heapq.heappop(queue)

    if visited[vertex]:

        continue

    visited[vertex] = True

    min_costs[vertex] = total_cost

    remains -= 1

    if not remains:

        break

    for cost, vertex2 in edges[vertex]:

        if not visited[vertex2]:

            heapq.heappush(queue, (total_cost + cost, vertex2))



for r in enumerate(min_costs):

    print((*r))
import heapq

n = int(eval(input()))
edges = [None] * n
for _ in range(n):
    l = list(map(int, input().split()))
    edges[l[0]] = set(
        (c, j) for j, c in (l[i : i + 2] for i in range(2, l[1] * 2 + 2, 2))
    )
min_costs = [0] * n
visited = [False] * n
visited[0] = True
queue = list(edges[0])
heapq.heapify(queue)
while queue:
    total_cost, vertex = heapq.heappop(queue)
    if visited[vertex]:
        continue
    visited[vertex] = True
    min_costs[vertex] = total_cost
    for cost, vertex2 in edges[vertex]:
        if not visited[vertex2]:
            heapq.heappush(queue, (total_cost + cost, vertex2))
for r in enumerate(min_costs):
    print((*r))

import heapq

n = int(eval(input()))
edges = [None] * n
for _ in range(n):
    l = list(map(int, input().split()))
    edges[l[0]] = set(
        (c, j) for j, c in (l[i : i + 2] for i in range(2, l[1] * 2 + 2, 2))
    )
min_costs = [0] * n
visited = [False] * n
visited[0] = True
queue = list(edges[0])
heapq.heapify(queue)
remains = n - 1
while True:
    total_cost, vertex = heapq.heappop(queue)
    if visited[vertex]:
        continue
    visited[vertex] = True
    min_costs[vertex] = total_cost
    remains -= 1
    if not remains:
        break
    for cost, vertex2 in edges[vertex]:
        if not visited[vertex2]:
            heapq.heappush(queue, (total_cost + cost, vertex2))
for r in enumerate(min_costs):
    print((*r))

-while queue: +remains = n - 1 +while True: +    remains -= 1 +    if not remains: +        break