#include <iostream>
#include <queue>	
#include <utility>	
#include <list>		
#define N 10000	
#define INF (1<<31-1);
using namespace std;

typedef pair<int,int> pii;	
vector<pii> adj[N];	
bool color[N];	
int dist[N];	
int n;	
priority_queue<pii> pq; 

int dijkstra(int k){	
	for(int i=0;i<n;i++){
		color[i]=false; 
		dist[i]=INF;	
	}
	color[k]=true; 
	dist[k]=0;	
	for(int i=0;i<adj[k].size();i++){
		pq.push(adj[k][i]); 
	}
	while(!pq.empty()){	
		pii temp=pq.top();pq.pop();	
		temp.first=-temp.first;	
		if(color[temp.second])continue;	
		color[temp.second]=true; 
		dist[temp.second]=temp.first;	
		for(int i=0;i<adj[temp.second].size();i++){
			if(!color[adj[temp.second][i].second])pq.push(make_pair(-dist[temp.second]+adj[temp.second][i].first,adj[temp.second][i].second));
		}
	}

	for(int i=0;i<n;i++) cout<<i<<" "<<dist[i]<<endl;
	return 0;
}
int main(void){
	int v,c;	
	int u,k;	
	cin>>n; 
	for(int i=0;i<n;i++){ 
		cin>>u>>k;	
		for(int j=0;j<k;j++){
			cin>>v>>c;	
			adj[u].push_back(make_pair(-c,v));	
		}
	}
	dijkstra(0);	
	return 0;
}