#include<iostream>
#include<vector>
using namespace std;
#define max 10000
#define infty 1<<21

int n;
int d[max];
int color[max];
vector<vector<int> > v(max);

void soya() {
	d[0] = 0;
	while (1) {
		int x = infty;
		for (int i = 0; i < n; i++) {
			if (x != infty) {
				if (d[i] < d[x] && color[i] != 2) {
					x = i;
				}
			}
			else {
				if (d[i] < x && color[i] != 2) {
					x = i;
				}
			}
		}

		if (x == infty) break;
		else {
			color[x] = 2;
			for (int i = 0; i < v[x].size() / 2; i++) {
				if (d[x] +v[x][(2 * i) + 1] < d[v[x][2 * i]]) {
					d[v[x][2 * i]] = d[x] + v[x][(2 * i) + 1];
				}
			}
		}
	}
}

int main() {
	for (int i = 0; i < max; i++) {
		color[i] = 0;
		d[i] = infty;
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		int id;
		int k;
		cin >> id >> k;
		for (int j = 0; j < k; j++) {
			int num1;
			int kyori;
			cin >> num1 >> kyori;
			v[id].push_back(num1);
			v[id].push_back(kyori);
		}
	}

	soya();

	for (int i = 0; i < n; i++) {
		cout << i << " " << d[i] << endl;
	}

	return 0;
}
