#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<vector<pair<int, int> > > v(n);
  for(int i = 0; i < n; i++){
    int u, k; cin >> u >> k;
    for(int j = 0; j < k; j++){
      int a, b; cin >> a >> b;
      v[u].push_back(make_pair(a, b));
    }
  }
  int d[n];
  bool c[n];
  for(int i = 0; i < n; i++){
    c[i] = 0;
    d[i] = 10000000;
  }
  priority_queue<pair<int, int > > pq;
  pq.push(make_pair(0, 0));
  d[0] = 0;
  while(pq.empty() == false){
    int x = pq.top().second;
    pq.pop();
    c[x] = 1;
    for(int i = 0; i < v[x].size(); i++){
      int y = v[x][i].first;
      if(c[y] == 0){
        if(d[y] > d[x] + v[x][i].second){
          d[y] = d[x] + v[x][i].second;
          pq.push(make_pair(d[y] * (-1), y));
        }
      }
    }
  }
  for(int i = 0; i < n; i++){
    cout << i << " " << d[i] << endl;
  }
  return;
}

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

