#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
// #define debug

using namespace std;

struct Edge {
    int to, nxt, idx;
};

const int MAX_N = 2e5 + 7;
Edge e[MAX_N << 1];
map<pii, int> mp;
vector<pii> ans;
int head[MAX_N << 1], dfn[MAX_N << 1];
bool vis[MAX_N];
int n, tot, cnt, ord;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

void add(int u, int v, int idx) {
    e[++cnt].to = v; e[cnt].nxt = head[u]; head[u] = cnt; e[cnt].idx = idx;
}

int dfs(int u, int fa) {
    dfn[u] = ++ord;
    for (int i = head[u]; i; i = e[i].nxt) {
        int v = e[i].to;
        if (!dfn[v]) {
            int res = dfs(v, u);
            if (res) {
                ans.push_back(pii(res, e[i].idx));
                vis[res] = vis[e[i].idx] = true;
            }
        }
    }
    int lst = 0;
    for (int i = head[u]; i; i = e[i].nxt) {
        if (vis[e[i].idx] || e[i].to == fa) continue;
        if (lst) {ans.push_back(pii(lst, e[i].idx));vis[lst] = vis[e[i].idx] = true;lst = 0;}
        else lst = e[i].idx;
    }
    return lst;
}

signed main() {
#ifndef debug
    scanf("%lld", &n);
    for (int i = 1; i <= n; ++i) {
        int a, b, c, d;
        scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
        int up = c * b, dn = d * (a + b);
        int _gcd = gcd(up, dn);
        pii u1(up / _gcd, dn / _gcd);
        up = (c + d) * b, dn = a * d;
        _gcd = gcd(up, dn);
        pii u2(up / _gcd, dn / _gcd);
        if (!mp.count(u1)) {
            ++tot;
            mp[u1] = tot;
        }
        if (!mp.count(u2)) {
            ++tot;
            mp[u2] = tot;
        }
        int u = mp[u1], v = mp[u2];
        add(u, v, i), add(v, u, i); 
    }
#endif
#ifdef debug
    int m;
    scanf("%lld%lld", &tot, &m);
    for (int i = 1; i <= m; ++i) {
        int u, v, id;
        scanf("%lld%lld%lld", &u, &v, &id);
        add(u, v, id), add(v, u, id);
    }
#endif
    for (int i = 1; i <= tot; ++i) {
        if (!dfn[i]) dfs(i, 0);
    }
#ifdef debug
    // dfs(1, 0);
    for (int i = 1; i <= tot; ++i) {
        printf("%lld: %lld\n", i, dfn[i]);
    }
#endif
    printf("%lld\n", ans.size());
    for (auto p : ans) {
        printf("%lld %lld\n", p.first, p.second);
    }
    return 0;
}