read
M=1000000007
O=$[M-1]
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
		echo $a $b $f
	fi
done|sort -n|{
	ans=1
	pa="X"
	pb="X"
	x=1
	y=1
	while read a b f;do
		if [ $pa != $a -o $pb != $b ];then
			ans=$[ans*(x+y-1)%M]
			x=1
			y=1
			pa=$a
			pb=$b
		fi
		if [ $f -eq 0 ];then
			x=$[x*2%M]
		else
			y=$[y*2%M]
		fi
	done
	ans=$[ans*(x+y-1)%M]
	echo $[(ans+O)%M]
}
