#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long long LL_INF = 1ll * INF * INF;
const int MAX_N = 1000 + 7;
template <typename T>
inline void addmod(T& a, const long long& b, const int& MOD = INF) {
  a = (a + b) % MOD;
  if (a < 0) a += MOD;
}
class HopcroftKarp {
 public:
  static const int MAX_V = 1e3 + 7;
  static const int MAX_E = 1e6 + 7;
  static const int nil = -1;
  int num_x, num_y, edge_count;
  int adj[MAX_E], next[MAX_E];
  int last[MAX_V], ptr[MAX_V], level[MAX_V], match_x[MAX_V], match_y[MAX_V];
  int visited[2][MAX_V];
  void init(int num_x_, int num_y_) {
    num_x = num_x_;
    num_y = num_y_;
    edge_count = 0;
    fill_n(last, num_x, nil);
    fill_n(match_x, num_x, nil);
    fill_n(match_y, num_y, nil);
  }
  void add_edge(int u, int v) {
    adj[edge_count] = v;
    next[edge_count] = last[u];
    last[u] = edge_count++;
  }
  int bfs() {
    static int queue_[MAX_V];
    int q_size = 0;
    for (int x = 0; x < num_x; x++) {
      if (match_x[x] != nil) {
        level[x] = 0;
      } else {
        level[x] = 1;
        queue_[q_size++] = x;
      }
    }
    int res = 0;
    for (int j = 0; j < q_size; ++j) {
      int x = queue_[j];
      for (int e = last[x]; e != nil; e = next[e]) {
        int y = adj[e];
        int u = match_y[y];
        if (u == nil) {
          res = 1;
        } else if (level[u] == 0) {
          level[u] = level[x] + 1;
          queue_[q_size++] = u;
        }
      }
    }
    return res;
  }
  bool dfs(int x) {
    for (int& e = ptr[x]; e != nil; e = next[e]) {
      int y = adj[e];
      int u = match_y[y];
      if (u == nil || (level[u] == level[x] + 1 && dfs(u))) {
        match_x[x] = y;
        match_y[y] = x;
        return true;
      }
    }
    return false;
  }
  int maximum_matching() {
    int res = 0;
    while (bfs()) {
      copy(last, last + num_x, ptr);
      for (int x = 0; x < num_x; x++)
        if (match_x[x] == nil) {
          res += dfs(x);
        }
    }
    return res;
  }
  void dfs(int u, bool right) {
    visited[right][u] = 1;
    if (!right) {
      for (int e = last[u]; e != nil; e = next[e]) {
        int v = adj[e];
        if (!visited[!right][v]) {
          dfs(v, !right);
        }
      }
    } else {
      int v = match_y[u];
      if (v != nil && !visited[!right][v]) {
        dfs(v, !right);
      }
    }
  }
  vector<int> min_cover() {
    vector<int> res;
    fill_n(visited[0], num_x, 0);
    fill_n(visited[1], num_y, 0);
    for (int x = 0; x < num_x; x++)
      if (match_x[x] == nil && !visited[0][x]) {
        dfs(x, 0);
      }
    for (int x = 0; x < num_x; x++)
      if (!visited[0][x]) {
        res.push_back(x);
      }
    for (int y = 0; y < num_y; y++)
      if (match_y[y] != nil && visited[1][y]) {
        res.push_back(num_x + y);
      }
    return res;
  }
  vector<int> max_independent() {
    vector<int> cover_vertexes = min_cover();
    cover_vertexes.push_back(num_x + num_y);
    vector<int> ans;
    for (int x : cover_vertexes) {
      static int i = 0;
      while (i < x) ans.push_back(i++);
      assert(i == x);
      ++i;
    }
    return ans;
  }
};
HopcroftKarp matching;
vector<int> rep_x, rep_y;
void normalize(int x[], int n, vector<int>& rep) {
  vector<int> val(x, x + n);
  sort(val.begin(), val.end());
  val.resize(unique(val.begin(), val.end()) - val.begin());
  for (int i = 0; i < n; ++i)
    x[i] = (int)(lower_bound(val.begin(), val.end(), x[i]) - val.begin());
  rep = val;
}
int n;
int x[MAX_N];
int y[MAX_N];
struct Node {
  int u, v, i, j;
  void print() {
    cout << rep_x[u] << ' ' << rep_y[v] << ' ' << rep_x[i] << ' ' << rep_y[j]
         << '\n';
  }
};
vector<int> point_rows[MAX_N];
vector<int> point_cols[MAX_N];
struct Segment {
  int pos;
  int left, right;
  int id;
};
int vertical[MAX_N][MAX_N];
int horizontal[MAX_N][MAX_N];
void solve() {
  cin >> n;
  matching.init(n, n);
  for (int i = (0), _b = (n); i < _b; ++i) cin >> x[i] >> y[i];
  normalize(x, n, rep_x);
  normalize(y, n, rep_y);
  for (int i = 0; i < n; ++i) {
    int u = x[i], v = y[i];
    point_rows[u].push_back(v);
    point_cols[v].push_back(u);
    vertical[u][v] = 1;
    horizontal[u][v] = 1;
  }
  for (int i = 0; i < n; ++i) {
    sort(point_cols[i].begin(), point_cols[i].end());
  }
  vector<Segment> left_seg;
  vector<Segment> right_seg;
  auto add_segment = [](vector<int>& a, int pos, vector<Segment>& segs) {
    sort(a.begin(), a.end());
    for (int i = 1; i < a.size(); ++i)
      if (a[i - 1] + 1 < a[i]) {
        segs.push_back({pos, a[i - 1] + 1, a[i] - 1, (int)(segs).size()});
      }
  };
  for (int i = 0; i < n; ++i)
    if (point_rows[i].size() > 1) {
      add_segment(point_rows[i], i, left_seg);
    }
  for (int i = 0; i < n; ++i)
    if (point_cols[i].size() > 1) {
      add_segment(point_cols[i], i, right_seg);
    }
  matching.init((int)(left_seg).size(), (int)(right_seg).size());
  for (const auto& lhs : left_seg)
    for (const auto& rhs : right_seg) {
      if (lhs.left <= rhs.pos && rhs.pos <= lhs.right && rhs.left <= lhs.pos &&
          lhs.pos <= rhs.right) {
        matching.add_edge(lhs.id, rhs.id);
      }
    }
  cerr << "matching.maximum_matching()"
       << ": " << (matching.maximum_matching()) << '\n';
  ;
  for (int x : matching.max_independent()) {
    if (x < left_seg.size()) {
      auto cur = left_seg[x];
      for (int j = cur.left; j <= cur.right; ++j) horizontal[cur.pos][j] = 1;
    } else {
      auto cur = right_seg[x - (int)(left_seg).size()];
      for (int i = cur.left; i <= cur.right; ++i) {
        vertical[i][cur.pos] = 1;
      }
    }
  }
  vector<Node> ver;
  for (int j = 0; j < n; ++j) {
    for (int i = 0; i < n;) {
      if (!vertical[i][j]) {
        ++i;
        continue;
      };
      int k = i;
      while (vertical[k][j]) ++k;
      ver.push_back({i, j, k - 1, j});
      i = k;
    }
  }
  cout << ver.size() << '\n';
  for (auto v : ver) v.print();
  vector<Node> hor;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n;) {
      if (!horizontal[i][j]) {
        ++j;
        continue;
      };
      int k = j;
      while (horizontal[i][k]) ++k;
      hor.push_back({i, j, i, k - 1});
      j = k;
    }
  }
  cout << hor.size() << '\n';
  for (auto h : hor) h.print();
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  const bool multiple_test = false;
  int test = 1;
  if (multiple_test) cin >> test;
  for (int i = 0; i < test; ++i) {
    solve();
  }
}
