#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
const int num = 10000, num1 = 500000, INF = 20000000;
int n, d[num], c[num];
vector<pair<int, int> > v[num];
priority_queue<pair<int, int> > q;
inline void mini() {
	q.push(make_pair(0, 0));
	while (!q.empty()) {
		pair<int, int> p = q.top(); q.pop();
		int a = p.second;
		c[a] = 1;
		for (int i = 0; i < v[a].size(); i++) {
			int b = v[a][i].first;
			if (c[b] == 0 && d[b] > d[a] + v[a][i].second) {
				d[b] = d[a] + v[a][i].second;
				q.push(make_pair(d[b] * -1, b));
			}
		}
	}
		
}
int main() {
	int u, k, s, t;
	cin >> n;
	for (int i = 1; i < n; i++) {
		d[i] = INF;
		c[i] = 0;
	}
	d[0] = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &u, &k);
		for (int j = 0; j < k; j++) {
			scanf("%d%d", &s, &t);
			v[u].push_back(make_pair(s, t));
		}
	}
	mini();
	for (int i = 0; i < n; i++) {
		printf("%d %d\n", i, d[i]);
	}
	return 0;
}