#include<bits/stdc++.h>
using namespace std;
#define Re register int
typedef double dl;

const int N = 400005;
const dl eps = 1e-12;
struct info
{
	double k;
	int d;
}a[N];
int n, res, m, cnt = 1, ans, g[N], hea[N], nxt[N], to[N], id[N], dep[N], ansl[N], ansr[N];
bool b[N], p[N];

inline int read()
{
	char c = getchar();
	int ans = 0;
	while (c < 48 || c > 57) c = getchar();
	while (c >= 48 && c <= 57) ans = (ans << 3) + (ans << 1) + (c ^ 48), c = getchar();
	return ans;
}

inline void write(int x)
{
	int num = 0;
	char sc[15];
	if (!x) sc[num = 1] = 48;
	while (x) sc[++num] = x % 10 + 48, x /= 10;
	while (num) putchar(sc[num--]);
}

inline dl slop(dl a, dl b, dl c, dl d)
{
	return b * c / a / d;
}

inline bool cmp(info x, info y)
{
	return x.k < y.k;
}

inline void add(int x, int y, int z)
{
	nxt[++cnt] = hea[x], to[cnt] = y, id[cnt] = z, hea[x] = cnt;
}

inline void dfs(int x, int y)
{
	b[x] = 1, g[x] = 0;
	for (Re i = hea[x]; i; i = nxt[i])
	{
		int u = to[i];
		if (b[u] && dep[u] < dep[x]) continue;
		if (!b[u])
		{
			dep[u] = dep[x] + 1;
			dfs(u, i);
		}
		if (!p[i])
			if (g[x]) ansl[++ans] = id[g[x]], ansr[ans] = id[i], p[g[x]] = p[g[x] ^ 1] = p[i] = p[i ^ 1] = 1, g[x] = 0;
			else g[x] = i;
	}
	if (g[x] && y) ansl[++ans] = id[g[x]], ansr[ans] = id[y], p[g[x]] = p[g[x] ^ 1] = p[y] = p[y ^ 1] = 1;
}

int main()
{
	n = read();
	for (Re i = 1; i <= n; ++i)
	{
		int aa = read(), bb = read(), cc = read(), dd = read();
		a[++res].k = slop(aa + bb, bb, cc, dd), a[res].d = i;
		a[++res].k = slop(aa, bb, cc + dd, dd), a[res].d = i;
	}
	sort(a + 1, a + res + 1, cmp);
	for (Re i = 1; i <= res; ++i)
	{
		if (a[i].k > a[i - 1].k + eps) ++m;
		if (!g[a[i].d]) g[a[i].d] = m;
		else add(g[a[i].d], m, a[i].d), add(m, g[a[i].d], a[i].d);
	}
	for (Re i = 1; i <= m; ++i)
		if (!b[i]) dfs(i, 0);
	write(ans), putchar('\n');
	while (ans) write(ansl[ans]), putchar(' '), write(ansr[ans--]), putchar('\n');
	return 0;
}
