#include<bits/stdc++.h>
#define maxn 500010
#define ll long long
#define dss first
#define yyds second
using namespace std;

int n,cnt;
map<pair<ll,ll>,int> bq;
pair<int,int> m[maxn];
vector<pair<int,int> > ans;
int h[maxn],e[maxn*2],ne[maxn*2],w[maxn*2],idx;
bool v[maxn];

void add(int a,int b,int c){e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int lsh(ll a,ll b)
{
	ll d=gcd(a,b);
	a/=d,b/=d;
	if(!bq[{a,b}]) bq[{a,b}]=++cnt;
	return bq[{a,b}];
}

void dfs(int x)
{
	v[x]=1;
	for(int i=h[x];~i;i=ne[i])
	{
		int y=e[i],id=w[i];
		e[i]=e[i^1]=0;
		if(y)
		{
			if(!v[y]) dfs(y);
			if(m[y].dss) ans.push_back({id,m[y].yyds}),m[y]={0,0};
			else if(m[x].dss) ans.push_back({m[x].yyds,id}),m[x]={0,0};
			else m[x]={y,id};
		}
	}
}

int main()
{
	cin>>n;
	memset(h,-1,sizeof h);
	for(int i=1,a,b,c,d;i<=n;i++)
	{
		cin>>a>>b>>c>>d;
		int x=lsh(1ll*a*d,1ll*b*(c+d)),y=lsh(1ll*d*(a+b),1ll*b*c);
		add(x,y,i),add(y,x,i);
	}
	
	for(int i=1;i<=cnt;i++) if(!v[i]) dfs(i);
	
	printf("%d\n",ans.size());
	for(auto v:ans) printf("%d %d\n",v.dss,v.yyds);
	return 0;
}