#include<bits/stdc++.h>
using namespace std;
using ll = long long;

// #undef DEBUG
#define DEBUG
/// {{{ DEBUG --- ///
#ifdef DEBUG
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; return o; }
#ifdef USE_COUT
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#else
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#endif
template<class T> inline void dump2D(T &d, size_t sizey, size_t sizex) { ostream&o=
#ifdef USE_COUT
  cout;
#else
  cerr;
#endif
  for(size_t i = 0; i < sizey; i++) { for(size_t j = 0; j < sizex; j++) o << d[i][j] << " "; o << endl; }
}
#else
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); return o; }
#define dump(...) (42)
#define dump2D(...) (42)
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
template<class T, class U> ostream & operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; }
/// }}}--- ///

template<class T = int, class U = uint64_t>
struct RadixHeap {
private:
  std::vector< pair<U, T> > v[sizeof(U) * 8 + 1];
  std::size_t sz = 0;
  U last = 0;
  std::size_t logbinll(U x) {
    std::size_t h = 0;
    x = x & 0xFFFFFFFF00000000 ? (h += 32, x) & 0xFFFFFFFF00000000 : x;
    x = x & 0xFFFF0000FFFF0000 ? (h += 16, x) & 0xFFFF0000FFFF0000 : x;
    x = x & 0xFF00FF00FF00FF00 ? (h += 8, x) & 0xFF00FF00FF00FF00 : x;
    x = x & 0xF0F0F0F0F0F0F0F0 ? (h += 4, x) & 0xF0F0F0F0F0F0F0F0 : x;
    x = x & 0xCCCCCCCCCCCCCCCC ? (h += 2, x) & 0xCCCCCCCCCCCCCCCC : x;
    x = x & 0xAAAAAAAAAAAAAAAA ? (h += 1, x) & 0xAAAAAAAAAAAAAAAA : x;
    return h;
  }
public:
  void push(U x, T y) {
    // assert(last <= f(x));
    v[logbinll(x^last)].emplace_back(x, y);
    sz++;
  }
  pair<U, T> pop() {
    // assert(sz);
    if(!v[0].size()) {
      std::size_t i = 1;
      while(!v[i].size()) i++;
      last = min_element(begin(v[i]), end(v[i]))->first;
      for(const pair<U, T> & e : v[i])
        v[logbinll(e.first ^ last)].emplace_back(e);
      v[i].clear();
    }
    sz--;
    pair<U, T> res = v[0].back();
    v[0].pop_back();
    return res;
  }
  std::size_t size() { return sz; }
};

vector<pair<int, int>> g[100];
int n;
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n;
  for(int i = 0; i < n; i++) {
    int x, m;
    cin >> x >> m;
    while(m--) {
      int t, c;
      cin >> t >> c;
      g[x].emplace_back(t, c);
    }
  }
  // dijkstra {{{
  vector<ll> dist(n, 1e18);
  RadixHeap<int> rh;
  rh.push(0, 0);
  dist[0] = 0;
  while(rh.size()) {
    ll di; int i;
    tie(di, i) = rh.pop();
    if(dist[i] < di) continue;
    for(auto to : g[i]) {
      int j = to.first;
      ll ndi = di + to.second;
      if(dist[j] > ndi) {
        dist[j] = ndi;
        rh.push(ndi, j);
      }
    }
  }
  // }}}
  for(int i = 0; i < n; i++)cout << i << " "<< dist[i] << endl;
  return 0;
}




Measured memory_bytes: 3232