Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

C++: #include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>
#include <queue>
#include <cstdio>
#include <unordered_map>
#include <map>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

template<typename T=int>
class UnionFind {
 public:
  explicit UnionFind(unsigned long long n) : rank_(n, 0), p_(n, 0) {
    for (T i = 0; i < n; i++) {
      MakeSet(i);
    }
  }

  void MakeSet(T x) {
    p_[x] = x;
    rank_[x] = 0;
  }

  bool Same(T x, T y) {
    return FindSet(x) == FindSet(y);
  }

  void Link(T x, T y) {
    if (rank_[x] > rank_[y]) {
      p_[y] = x;
    } else {
      p_[x] = y;
      if (rank_[x] == rank_[y]) {
        rank_[y]++;
      }
    }
  }

  void Unite(T x, T y) {
    Link(FindSet(x), FindSet(y));
  }

  T FindSet(T x) {
    if (x != p_[x]) {
      p_[x] = FindSet(p_[x]);
    }
    return p_[x];
  }

 private:
  std::vector<T> rank_, p_;
};

template<typename NumT = ull, typename CostT = ull>
class Dijkstra {
 public:
  Dijkstra(unsigned long long num, CostT max_cost) :
      num_(num),
      max_cost_(max_cost),
      v_(num, std::vector<CostT>(num, max_cost)),
      c_(num, 0),
      d_(num, max_cost),
      p_(num, 0) {
  };

  void ComputeWithQ(NumT start) {
    d_[start] = 0;
    p_[start] = start;
    priority_queue<std::pair<CostT, NumT>> pq;
    pq.push(make_pair(0, start));
    while (!pq.empty()) {
      auto node = pq.top();
      pq.pop();
      auto ni = node.second;
      auto c = -node.first;
      c_[ni] = 1;
      if (d_[ni] < c) {
        continue;
      }
      d_[ni] = c;

      for (int i = 0; i < num_; i++) {
        if (v_[ni][i] == max_cost_) {
          continue;
        }
        if ((c_[i] != 1) && (d_[i] > (v_[ni][i] + d_[ni]))) {
          p_[i] = ni;
          d_[i] = v_[ni][i] + d_[ni];
          pq.push(make_pair(-d_[i], i));
        }
      }
    }
  }

  void Compute(int start) {
    d_[start] = 0;
    p_[start] = start;
    while (true) {
      int m = -1;
      int min_d = std::numeric_limits<int>::max();
      for (int i = 0; i < num_; i++) {
        if ((c_[i] == 0) && (min_d > d_[i])) {
          min_d = d_[i];
          m = i;
        }
      }
      if (m < 0) {
        break;
      }
      c_[m] = 1;
      for (int i = 0; i < num_; i++) {
        if ((c_[i] == 0) && (d_[i] > (d_[m] + v_[m][i]))) {
          d_[i] = d_[m] + v_[m][i];
          p_[i] = m;
        }
      }
    }
  }

  void Set(NumT s, NumT d, CostT c) {
    v_[s][d] = c;
  }

  CostT Distance(NumT d) {
    return d_[d];
  }

 public:
  NumT num_;
  CostT max_cost_;
  std::vector<std::vector<CostT>> v_;
  std::vector<int> c_;
  std::vector<int> d_;
  std::vector<NumT> p_;
};

int nibutan(int *ary, int ok, int ng) {
  bool is_valid;
  while (std::abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    // is_valid = check(mid);
    if (is_valid) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}

template<typename NumT = int, typename CostT = unsigned long long>
class DijkstraQ {
 public:
  DijkstraQ(unsigned long long num, CostT max_cost) :
      adj_(num, std::vector<std::pair<NumT, CostT>>()),
      c_(num, 0), d_(num, max_cost) {}

  void Compute(NumT start) {
    std::priority_queue<std::pair<CostT, NumT>> q;
    d_[start] = 0;
    q.push(std::make_pair(0, start));

    while (!q.empty()) {
      std::pair<CostT, NumT> node = q.top();
      q.pop();
      auto n = node.second;
      auto c = -node.first;
      c_[n] = 1;
      if (c > d_[n]) {
        continue;
      }
      d_[n] = c;

      for (NumT i = 0; i < adj_[n].size(); i++) {
        auto nn = adj_[n][i].first;
        auto nc = adj_[n][i].second;
        if (c_[nn] > 0) {
          continue;
        }
        if (d_[nn] > (c + nc)) {
          d_[nn] = c + nc;
          q.push(std::make_pair(-d_[nn], nn));
        }
      }
    }
  }

  void Set(NumT s, NumT d, CostT c) {
    adj_[s].push_back(std::make_pair(d, c));
  }

  CostT Distance(NumT d) {
    return d_[d];
  }

  std::vector<CostT> d_;
  std::vector<int> c_;
  std::vector<std::vector<std::pair<NumT, CostT>>> adj_;
};

// x >= y
template<typename T>
inline T gcd(T x, T y) { return y ? gcd(y, x % y) : x; }

template<typename T>
inline T lcm(T x, T y) { return (x / gcd(x, y)) * y; }

// return gcd(a, b)
// x, y satisfy ax + by = gcd(a, b)
ll xgcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll d = xgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

bool check(int *A, int i) {
  return A[i] < 39;
}

int N;
int A[110][110];
int C[110];
int D[110];

int main() {
  int N;
  cin >> N;
  rep(i, 0, N){
    D[i] = numeric_limits<int>::max()/2;
    rep(j, 0, N) {
      A[i][j] = numeric_limits<int>::max()/2;
    }
  }

  rep(i, 0, N) {
    int k, n;
    cin >> k >> n;
    rep(i, 0, n) {
      int x, y;
      cin >> x >> y;
      A[k][x] = y;
    }
  }

  D[0] = 0;
  priority_queue<pair<int, int>> q;
  q.push(make_pair(0, 0));

  while(!q.empty()) {
    auto t = q.top();
    q.pop();
    int c = -t.first;
    int ix = t.second;
    if (D[ix] < c) {
      continue;
    }

    C[ix] = 1;

    rep(i, 0, N) {
      if (C[i] > 0) {
        continue;
      }
      if (D[i] > D[ix] + A[ix][i]) {
        D[i] = D[ix] + A[ix][i];
        q.push(make_pair(-D[i], i));
      }
    }
  }
  rep(i, 0, N) {
    cout << i << " " << D[i] << endl;
  }
}