#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <array>
#include <memory>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <stdexcept>
#include <numeric>
#include <queue>

using std::string;
using std::vector;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// util
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

std::vector<std::string> split(const std::string& input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// user func
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void printList(const vector<int>& list) {
    // print
    for(int i = 0; i < list.size(); i++){
        printf("%d", list[i]);
        if ( i + 1 != list.size() ) {
            printf(" ");
        }
    }
    printf("\n");
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// logic
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

static int MAX = 1000000;

class Node{
public:
    Node(int id, int numEdge)
     : id(id)
     , edges(vector<int>(numEdge, MAX))
    {
        // constructer
    }
    
    void Edge(int id, int weight){
        this->edges[id] = weight;
    }

    vector<int> Edges() {
        return this->edges;
    }

    int id;
    bool done = false;
    vector<int> edges;
};

class List{
public:
    // constructer
    List(int numNode)
        : results(numNode)
    {
        for (int i = 0; i < numNode; i++) {
            this->nodes.push_back(Node(i, numNode));
            this->results[i] = MAX;
        }
    }

    void SetWeight(int from, int to, int weight)
    {
        this->nodes[from].Edge(to, weight);
    }
    
    vector<int> ShortedPath() {
        // this->Enqueue(0);
        this->results[0] = 0;
        this->queue.push(0);
        this->Traverse();
        return this->results;
    }

    void Traverse() {
        while(!this->queue.empty()) {
            int queueIndex = queue.front();
            queue.pop();
            vector<int> edges = this->nodes[queueIndex].Edges();
            for (int i = 0; i < edges.size(); i++) {
                // update result
                int myWeight = this->results[queueIndex];
                this->results[i] = std::min(this->results[i], myWeight + edges[i]);
            }
            // printList(this->results);
            // enqueue
            this->Enqueue(queueIndex);
            // done flag
            this->nodes[queueIndex].done = true;
        }
    }

    void Enqueue(int index) {
        // copy weights
        if (this->nodes[index].done) return;
        std::list<std::pair<int, int>> weights;
        for (int i = 0; i <  this->nodes[index].Edges().size(); i++) {
            weights.push_back(std::make_pair(i, this->nodes[index].Edges()[i]));
        }
        // sort
        weights.sort([](auto& lhs, auto& rhs){
            return lhs.second < rhs.second;
        });
        // enqueue
        for (auto weight : weights){
            queue.push(weight.first);
        }
    }
    
    

    void Print() {
        for (int i = 0; i < this->nodes.size(); i++) {
            printf("%d: ", i);
            for (int j = 0; j < this->nodes[i].Edges().size(); j++) {
                printf("%d (%d) ", j, this->nodes[i].Edges()[j]);
            }
            printf("\n");
        }
    }
private:
    std::queue<int> queue;
    std::vector<int> results;
    vector<Node> nodes;
};

void solve() {

    int n;
    scanf("%d", &n);
    List list(n);

    for (int i = 0; i < n; i++){
        int key;
        scanf("%d", &key);
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int dest;
            int weight;
            scanf("%d %d", &dest, &weight);
            list.SetWeight(key, dest, weight);
        }
    }
    // list.Print();
    auto result = list.ShortedPath();
    for(int i = 0; i < result.size(); i++) {
        printf("%d %d\n", i, result[i]);
    }
}

void test(){

}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// main
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    solve();
    // test();
    return 0;
}


Measured memory_bytes: 3252