gcd(){
	if [ $2 -eq 0 ];then
		echo $1
	else
		gcd $2 `expr $1 % $2`
	fi
}
read
M=1000000007
O=$[M-1]
declare -A keys
declare -A values
while read a b;do
	if [ $a -eq 0 -a $b -eq 0 ];then
		O=$[O+1]
	else
		ga=$a
		gb=$b
		while [ $gb -ne 0 ];do
			t=$ga
			ga=$gb
			gb=$[t%gb]
		done
		g=$ga
		a=$[a/g]
		b=$[b/g]
		if [ $a -lt 0 -o $a -eq 0 -a $b -gt 0 ];then
			a=$[-a]
			b=$[-b]
		fi
		f=0
		if [ $b -lt 0 ];then
			t=$a
			a=$[-b]
			b=$t
			f=1
		fi
		k="$a,$b"
		keys[$k]=
		values["$k,$f"]=$[values["$k,$f"]+1]
	fi
done
ans=1
for k in ${!keys[@]};do
	x=$[values["$k,0"]+0]
	y=$[values["$k,1"]+0]
	ans=`dc -e"2 $x $M|2 $y $M|+1-$ans*$M%p"`
done
echo $[(ans+O)%M]
