#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e9 + 7;
long long n, par[100001], sz[100001];
vector<pair<pair<long long, long long>, long long> > point, edg;
long long dist(long long a, long long b, long long c, long long d) {
  return min(abs(a - c), abs(b - d));
}
long long anc(long long x) {
  if (par[x] == -1)
    return x;
  else
    return (par[x] = anc(par[x]));
}
bool issameset(long long x, long long y) { return (anc(x) == anc(y)); }
void uni(long long x, long long y) {
  x = anc(x);
  y = anc(y);
  if (sz[x] > sz[y]) {
    sz[x] += sz[y];
    par[y] = x;
  } else {
    sz[y] += sz[x];
    par[x] = y;
  }
}
bool cmp(pair<pair<long long, long long>, long long> a,
         pair<pair<long long, long long>, long long> b) {
  return a.second < b.second;
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    pair<pair<long long, long long>, long long> pt;
    cin >> pt.first.first >> pt.first.second;
    pt.second = i;
    point.push_back(pt);
  }
  point.push_back(make_pair(make_pair(-oo, -oo), 0));
  point.push_back(make_pair(make_pair(2 * oo, 2 * oo), 0));
  sort(point.begin(), point.end());
  for (long long i = 2; i <= n; i++) {
    edg.push_back(
        make_pair(make_pair(point[i].second, point[i - 1].second),
                  dist(point[i].first.first, point[i].first.second,
                       point[i - 1].first.first, point[i - 1].first.second)));
  }
  for (long long i = 1; i <= n; i++)
    swap(point[i].first.first, point[i].first.second);
  sort(point.begin(), point.end());
  for (long long i = 2; i <= n; i++) {
    edg.push_back(
        make_pair(make_pair(point[i].second, point[i - 1].second),
                  dist(point[i].first.first, point[i].first.second,
                       point[i - 1].first.first, point[i - 1].first.second)));
  }
  for (long long i = 1; i <= n; i++) par[i] = -1;
  sort(edg.begin(), edg.end(), cmp);
  long long ans = 0;
  for (long long i = 0; i < edg.size(); i++) {
    cout << edg[i].first.first << " " << edg[i].first.second << " "
         << edg[i].second << " ";
    if (!issameset(edg[i].first.first, edg[i].first.second)) {
      ans += edg[i].second;
      uni(edg[i].first.first, edg[i].first.second);
    }
    cout << endl;
  }
  cout << ans;
}
