#!/usr/bin/env python



from sys import stdin, maxint





def main():

    num = int(stdin.readline())



    L = []

    for _ in range(num):

        L.append([int(s) for s in stdin.readline().split()])



    weight = [maxint] * num

    weight[0] = 0

    V = set(range(1, num))

    index = 0



    while V:

        Li = L[index]

        for i in range(Li[1]):

            v = Li[i*2+2]

            if v not in V:

                continue

            c = Li[i*2+3]

            weight[v] = min(weight[v], c + weight[index])



        index = min(V, key=lambda i: weight[i])

        V.remove(index)



    for i, d in enumerate(weight):

        print(i, d)





main()
#!/usr/bin/env python



from sys import stdin, maxint





def main():

    num = int(stdin.readline())



    L = []

    for _ in range(num):

        it = iter(int(s) for s in stdin.readline().split()[1:])

        L.append([(next(it), next(it)) for _ in range(next(it))])



    weight = [maxint] * num

    weight[0] = 0

    V = set(range(1, num))

    index = 0



    while V:

        for v, cost in L[index]:

            if v not in V:

                continue

            weight[v] = min(weight[v], cost + weight[index])



        index = min(V, key=lambda i: weight[i])

        V.remove(index)



    for i, d in enumerate(weight):

        print(i, d)





main()
#!/usr/bin/env python
from sys import stdin, maxint


def main():
    num = int(stdin.readline())
    L = []
    for _ in range(num):
        L.append([int(s) for s in stdin.readline().split()])
    weight = [maxint] * num
    weight[0] = 0
    V = set(range(1, num))
    index = 0
    while V:
        Li = L[index]
        for i in range(Li[1]):
            v = Li[i * 2 + 2]
            if v not in V:
                continue
            c = Li[i * 2 + 3]
            weight[v] = min(weight[v], c + weight[index])
        index = min(V, key=lambda i: weight[i])
        V.remove(index)
    for i, d in enumerate(weight):
        print(i, d)


main()

#!/usr/bin/env python
from sys import stdin, maxint


def main():
    num = int(stdin.readline())
    L = []
    for _ in range(num):
        it = iter(int(s) for s in stdin.readline().split()[1:])
        L.append([(next(it), next(it)) for _ in range(next(it))])
    weight = [maxint] * num
    weight[0] = 0
    V = set(range(1, num))
    index = 0
    while V:
        for v, cost in L[index]:
            if v not in V:
                continue
            weight[v] = min(weight[v], cost + weight[index])
        index = min(V, key=lambda i: weight[i])
        V.remove(index)
    for i, d in enumerate(weight):
        print(i, d)


main()

-        L.append([int(s) for s in stdin.readline().split()]) +        it = iter(int(s) for s in stdin.readline().split()[1:]) +        L.append([(next(it), next(it)) for _ in range(next(it))]) -        Li = L[index] -        for i in range(Li[1]): -            v = Li[i * 2 + 2] +        for v, cost in L[index]: -            c = Li[i * 2 + 3] -            weight[v] = min(weight[v], c + weight[index]) +            weight[v] = min(weight[v], cost + weight[index])