#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;

int main(){
	
	int n,aaa;
	cin>>n;
	vector<vector<int>> v(n),c(n);
	vector<int> k(n),ans(n),d(n);
	rep(i,n){
		cin>>aaa>>k[i];
		v[i].resize(k[i]);
		c[i].resize(k[i]);
		rep(j,k[i]){
			cin>>v[i][j]>>c[i][j];
		}
		ans[i]=-1;
		d[i]=INF;
	}
	d[0]=0;
	int m=INF,mi;
	rep(aaaa,n){
		m=INF;
		rep(i,n){
			if(ans[i]==-1 && d[i]<m){
				m=d[i];
				mi=i;
			}
		}
		ans[mi]=m;
		rep(j,k[mi]){
			d[v[mi][j]]=min(ans[mi]+c[mi][j],d[v[mi][j]]);
		}
	}



	rep(i,n){
		cout<<i<<" "<<ans[i]<<endl;
	}
	
}