(function(stdin) {
  var lines = stdin.trim().split('\n');
  var n = parseInt(lines.shift(), 10);
  var m = [];
  for (var i = 0; i < n; i++) {
    m[i] = [];
    for (var j = 0; j < n; j++) {
      m[i][j] = Infinity;
    }
  }
  lines.map(function(row) {
    var nums = row.trim().split(' ').map(Number);
    var u = nums.shift();
    var k = nums.shift();
    for (var i = 0; i < k; i++) {
      var v = nums.shift();
      var c = nums.shift();
      m[u][v] = c;
    }
  });
  var d = [], p = [], color = [];
  for (var i = 0; i < n; i++) {
    color[i] = 'WHITE';
    d[i] = Infinity;
  }
  d[0] = 0;
  p[0] = -1;
  var minv, u;
  while (1) {
    minv = Infinity;
    for (var i = 0; i < n; i++) {
      if (color[i] != 'BLACK' && d[i] < minv) {
        minv = d[i];
        u = i;
      }
    }
    if (minv == Infinity) {
      break;
    }
    color[u] = 'BLACK';
    for (var v = 0; v < n; v++) {
      if (color[v] != 'BLACK' && m[u][v] != Infinity) {
        if (d[u] + m[u][v] < d[v]) {
          d[v] = d[u] + m[u][v];
          p[v] = u;
          color[v] = 'GRAY';
        }
      }
    }
  }
  console.log(d.map(function(c, i) {return [i, c].join(' ');}).join('\n'));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));