Problem:
Parallel/Orthogonal For given two lines s1 and s2 , print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise.  s1 crosses points p0 and p1 , and s2 crosses points p2 and p3 . Input The entire input looks like:  q (the number of queries)
1st query
2nd query
... q th query Each query consists of integer coordinates of the points p0 , p1 , p2 , p3 in the following format:  x p0  y p0  x p1  y p1  x p2  y p2  x p3  y p3  Output For each query, print "2", "1" or "0". Constraints  1 ≤ q ≤ 1000  -10000 ≤ x p i , y p i ≤ 10000   p0 ≠ p1 and p2 ≠ p3 .  Sample Input 1 3
0 0 3 0 0 2 3 2
0 0 3 0 1 1 1 4
0 0 3 0 1 1 2 2 Sample Output 1 2
1
0

Solution (Python):
EPS = 1e-4


def OuterProduct(one, two):
	tmp = one.conjugate() * two
	return tmp.imag


def InnerProduct(one, two):
	tmp = one.conjugate() * two
	return tmp.real

def solve(a, b, c, d):
	if abs(OuterProduct(b-a, d-c)) <= EPS:
		return 2
	elif abs(InnerProduct(b-a, d-c)) <= EPS:
		return 1
	else:
		return 0

n = int(input())
for _ in range(n):
	pp = list(map(int, input().split()))
	p = [complex(pp[i], pp[i+1]) for i in range(0, 8, 2)]
	print(solve(p[0], p[1], p[2], p[3]))

Solution (Python):
q=int(input())
for i in range(q):
    L=input().split( )
    x0=int(L[0])
    y0=int(L[1])
    x1=int(L[2])
    y1=int(L[3])
    x2=int(L[4])
    y2=int(L[5])
    x3=int(L[6])
    y3=int(L[7])
    vx1=x0-x1
    vy1=y0-y1
    vx2=x2-x3
    vy2=y2-y3
    if vx1*vy2-vx2*vy1==0:
        print(2)
    elif vx1*vx2+vy1*vy2==0:
        print(1)
    else:
        print(0)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())




def sgn(a):
    if a < -eps: return -1
    if a >  eps: return  1
    return 0

class Point:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        pass

    def tolist(self):
        return [self.x,self.y]

    def __add__(self,p):
        return Point(self.x+p.x, self.y+p.y)
    def __iadd__(self,p):
        return self + p

    def __sub__(self,p):
        return Point(self.x - p.x, self.y - p.y)
    def __isub__(self,p):
        return self - p

    def __truediv__(self,n):
        return Point(self.x/n, self.y/n)
    def __itruediv__(self,n):
        return self / n

    def __mul__(self,n):
        return Point(self.x*n, self.y*n)
    def __imul__(self,n):
        return self * n

    def __lt__(self,other):
        tmp = sgn(self.x - other.x)
        if tmp != 0:
            return tmp < 0
        else:
            return sgn(self.y - other.y) < 0

    def __eq__(self,other):
        return sgn(self.x - other.x) == 0 and sgn(self.y - other.y) == 0

    def abs(self):
        return math.sqrt(self.x**2+self.y**2)

    def dot(self,p):
        return self.x * p.x + self.y*p.y

    def det(self,p):
        return self.x * p.y - self.y*p.x

    def arg(self,p):
        return math.atan2(y,x)


def iSP(a,b,c):
    tmp = sgn((b-a).det(c-a))
    if tmp > 0:   return 1   
    elif tmp < 0: return -1  
    else: 
        if sgn((b-a).dot(c-a)) < 0: return -2 
        if sgn((a-b).dot(c-b)) < 0: return  2 
        return 0 


def isToleranceLine(a,b,c,d):
    if sgn((b-a).det(c-d)) != 0: return 1 
    else:
        if sgn((b-a).det(c-a)) != 0: return 0 
        else: return -1 


def isToleranceSegline(a,b,c,d):
    return sgn(iSP(a,b,c)*iSP(a,b,d))<=0 and sgn(iSP(c,d,a)*iSP(c,d,b)) <= 0


def Intersection(a,b,c,d):
    tmp1 = (b-a)*((c-a).det(d-c))
    tmp2 = (b-a).det(d-c)
    return a+(tmp1/tmp2)


def DistanceLineToPoint(a,b,c):
    return abs(((c-a).det(b-a))/((b-a).abs()))


def DistanceSeglineToPoint(a,b,c):
    if sgn((b-a).dot(c-a)) < 0: 
        return (c-a).abs()
    if sgn((a-b).dot(c-b)) < 0: 
        return (c-b).abs()
    return DistanceLineToPoint(a,b,c)


def Vfoot(a,b,c):
    d = c + Point((b-a).y,-(b-a).x)
    return Intersection(a,b,c,d)


def PolygonArea(Plist):
    Plist = ConvexHull(Plist)
    L = len(Plist)
    S = 0
    for i in range(L):
        tmpS = (Plist[i-1].det(Plist[i]))/2
        S += tmpS
    return S


def PolygonG(Plist):
    Plist = ConvexHull(Plist)
    L = len(Plist)
    S = 0
    G = Point(0,0)
    for i in range(L):
        tmpS = (Plist[i-1].det(Plist[i]))/2
        S += tmpS
        G += (Plist[i-1]+Plist[i])/3*tmpS
    return G/S


def ConvexHull(Plist):
    Plist.sort()
    L = len(Plist)
    qu = deque([])
    quL = 0
    for p in Plist:
        while quL >= 2 and iSP(qu[quL-2],qu[quL-1],p) == 1:
            qu.pop()
            quL -= 1
        qu.append(p)
        quL += 1

    qd = deque([])
    qdL = 0
    for p in Plist:
        while qdL >= 2 and iSP(qd[qdL-2],qd[qdL-1],p) == -1:
            qd.pop()
            qdL -= 1
        qd.append(p)
        qdL += 1

    qd.pop()
    qu.popleft()
    hidari = list(qd) + list(reversed(qu)) 
    return hidari

N = int(input())
for _ in range(N):
    x0,y0,x1,y1,x2,y2,x3,y3 = inpl()
    p0 = Point(x0,y0)
    p1 = Point(x1,y1)
    p2 = Point(x2,y2)
    p3 = Point(x3,y3)
    if isToleranceLine(p0,p1,p2,p3) <= 0:
        print(2)
    else:
        p3 = p2 + Point((p3-p2).y,-(p3-p2).x)
        if isToleranceLine(p0,p1,p2,p3) <= 0:
            print(1)
        else:
            print(0)

Solution (Python):
for i in range(int(input())):
    px0,py0,px1,py1,px2,py2,px3,py3 = map(lambda x:int(x),input().split(" "))  
    print(1 if (px1-px0)*(px3-px2) == -(py1-py0)*(py3-py2) else(2 if (px1-px0)*(py3-py2) == (py1-py0)*(px3-px2) else 0))

Solution (Python):
q = int(input())


def isParallel(u, v):
    if u[0] == 0 or v[0] == 0:
        if u[0] == 0 and v[0] == 0:
            return True
        else:
            return False
    else:
        if u[0]*v[1] == u[1]*v[0]:
            return True
        else:
            return False


def isOrthogonal(u, v):
    if u[0]*v[0] + u[1]*v[1] == 0:
        return True
    else:
        return False


for qi in range(q):
    x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3= [int(i) for i in input().split()]
    u = [x_p1-x_p0, y_p1-y_p0]
    v = [x_p3-x_p2, y_p3-y_p2]
    if isParallel(u, v):
        print(2)
    elif isOrthogonal(u, v):
        print(1)
    else:
        print(0)

Solution (Python):
n = int(input())

def cross(a, b):
    return a[0]*b[1]-a[1]*b[0]
    
def dot(a, b):
    n = len(a)
    if n != len(b):
        return None
    ans = 0
    for i, j in zip(a, b):
        ans += i*j
    return ans
    
for i in range(n):
    pp = list(map(int, input().split()))
    a = (pp[2]-pp[0], pp[3]-pp[1])
    b = (pp[6]-pp[4], pp[7]-pp[5])
    if cross(a, b) == 0:
        print(2)
    elif dot(a, b) == 0:
        print(1)
    else:
        print(0)

Solution (Python):
import math


class Point:
    EPS = 1 << 10

    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Point(self.x+other.x, self.y+other.y)

    def __sub__(self, other):
        return Point(self.x-other.x, self.y-other.y)

    def __mul__(self, other):
        return Point(self.x*other.x, self.y*other.y)

    def __floordiv__(self, other):
        return Point(self.x/other.x, self.y/other.y)

    def __abs__(self):
        return math.sqrt(self.norm())

    def norm(self):
        return self.x**2 + self.y**2

    def __eq__(self, other):
        EPS = self.__class__.EPS
        return abs(self.x-other.x) < EPS and abs(self.x-other.x) < EPS


class Vector(Point):
    def __init__(self, x, y):
        super().__init__(x, y)

    def dot(self, other):
        return self.x*other.x + self.y*other.y

    def cross(self, other):
        return self.x*other.y - self.y*other.x

    def isOrthogonal(self, a, b):
        return a.dot(b) == 0.0

    def isParallel(self, a, b):
        return a.cross(b) == 0.0

    def __add__(self, other):
        return Vector(self.x+other.x, self.y+other.y)

    def __sub__(self, other):
        return Vector(self.x-other.x, self.y-other.y)

    def __mul__(self, other):
        return Vector(self.x*other.x, self.y*other.y)

    def __floordiv__(self, other):
        return Vector(self.x/other.x, self.y/other.y)


class Segment:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2

    def isOrthogonal(s1, s2):
        return (s1.p2-s1.p1).dot(s2.p2-s2.p1) == 0.0

    def isParallel(s1, s2):
        return (s1.p2-s1.p1).cross(s2.p2-s2.p1) == 0.0


class Line(Segment):
    pass


class Circle:
    def __init__(self, c, r):
        self.c = c
        self.r = r


class Polygon:
    def __init__(self, *points):
        self.points = points


n = int(input())
for i in range(n):
    q = list(map(int, input().split()))
    s = []
    for j in range(2):
        p0 = Vector(*q[j*4:j*4+2])
        p1 = Vector(*q[j*4+2:j*4+4])
        s.append(Segment(p0, p1))
    if Segment.isOrthogonal(*s):
        print(1)
    elif Segment.isParallel(*s):
        print(2)
    else:
        print(0)

Solution (Python):


import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')


def dot(a, b):
    x1,y1=a
    x2,y2=b
    return x1*x2+y1*y2


def cross(a, b):
    x1,y1=a
    x2,y2=b
    return x1*y2-y1*x2

Q=INT()
for _ in range(Q):
    x1,y1,x2,y2,x3,y3,x4,y4=MAP()
    
    
    
    v1=(x1-x2, y1-y2)
    v2=(x3-x4, y3-y4)
    
    if dot(v1, v2)==0:
        print(1)
    
    elif cross(v1, v2)==0:
        print(2)
    else:
        print(0)

Solution (Python):
import math


class Vector2():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, v):
        return Vector2(self.x+v.x, self.y+v.y)

    def __sub__(self, v):
        return Vector2(self.x-v.x, self.y-v.y)

    def __mul__(self, v):
        return Vector2(self.x*v, self.y*v)

    def __truediv__(self, v):
        return Vector2(self.x/v, self.y/v)

    def __abs__(self):
        return math.sqrt(float(self.x*self.x+self.y*self.y))

    def dot(self, v):
        return self.x*v.x+self.y*v.y

    def cross(self, v):
        return self.x*v.y-self.y*v.x

    def norm(self):
        d = abs(self)
        return Vector2(self.x/d, self.y/d)


n = int(input())
for i in range(n):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(int, input().split())
    v1 = Vector2(x1-x0, y1-y0).norm()
    v2 = Vector2(x3-x2, y3-y2).norm()
    d = v1.dot(v2)
    c = v1.cross(v2)
    if math.isclose(d, 0.0):
        print("1")
    elif math.isclose(c, 0.0):
        print("2")
    else:
        print("0")

Solution (Python):
from sys import stdin

class Vector:
    def __init__(self, x=None, y=None):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Vector(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector(self.x - other.x, self.y - other.y)

    def __mul__(self, k):
        return Vector(self.x * k, self.y * k)

    def __gt__(self, other):
        return self.x > other.x and self.y > other.y

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    
    def cross(self, other):
        return self.x * other.y - self.y * other.x

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

class Segment:
    def __init__(self, p1=Vector(0, 0), p2=Vector(1, 1)):
        self.p1 = p1
        self.p2 = p2

def is_orthogonal(*args, **kwargs):
    
    if len(args) == 2:
        v1, v2 = args
        return v1.dot(v2) == 0
    
    elif len(args) == 4:
        a1, a2, b1, b2 = args
        return is_orthogonal(a1 - a2, b1 - b2)
    
    elif len(kwargs) == 2:
        v1 = kwargs['s1'].p1 - kwargs['s1'].p2
        v2 = kwargs['s2'].p1 - kwargs['s2'].p2
        return v1.dot(v2) == 0
    else:
        raise ArgsError

def is_parallel(*args, **kwargs):
    
    if len(args) == 2:
        v1, v2 = args
        return v1.cross(v2) == 0
    
    elif len(args) == 4:
        a1, a2, b1, b2 = args
        return is_parallel(a1 - a2, b1 - b2)
    
    elif len(kwargs) == 2:
        v1 = kwargs['s1'].p1 - kwargs['s1'].p2
        v2 = kwargs['s2'].p1 - kwargs['s2'].p2
        return v1.cross(v2) == 0
    else:
        raise ArgsError

from sys import stdin

def read_and_print_results(n):
    for _ in range(n):
        line = stdin.readline().strip().split()
        p0 = Vector(int(line[0]), int(line[1]))
        p1 = Vector(int(line[2]), int(line[3]))
        p2 = Vector(int(line[4]), int(line[5]))
        p3 = Vector(int(line[6]), int(line[7]))
        s1 = Segment(p0, p1)
        s2 = Segment(p2, p3)
        if is_parallel(s1=s1, s2=s2):
            print('2')
        elif is_orthogonal(s1=s1, s2=s2):
            print('1')
        else:
            print('0')

n = int(input())
read_and_print_results(n)

Solution (Python):
q=int(input())

for i in range(q):
    xp0,yp0,xp1,yp1,xp2,yp2,xp3,yp3=map(int,input().split())
    if xp0==xp1:
        if xp2==xp3:
            print(2)
        elif yp2==yp3:
            print(1)
        else:
            print(0)
    elif xp2==xp3:
        if xp1==xp0:
            print(2)
        elif yp0==yp1:
            print(1)
        else:
            print(0)
    else:
        a1=(yp1-yp0)/(xp1-xp0)
        a2=(yp3-yp2)/(xp3-xp2)
        
        
        if a2>=a1-0.0000001 and a2<=a1+0.0000001:
            print(2)
        elif a2*a1>=-1-0.0000001 and a2*a1<=-1+0.0000001:
            print(1)
        else:
            print(0)

Solution (Python):
q = int(input())
for _ in range(q):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(int, input().split())
    dot = (x1 - x0)*(x3 - x2) + (y1 - y0)*(y3 - y2)
    if dot == 0:
        print(1)
    elif ((x1 - x0)**2 + (y1 - y0)**2)*((x3 - x2)**2 + (y3 - y2)**2) == dot**2:
        print(2)
    else:
        print(0)

Solution (Python):


from typing import List
from math import sqrt

EPS = 1e-10


def float_equal(x: float, y: float) -> bool:
    return abs(x - y) < EPS


class Point:

    def __init__(self, x: float=0.0, y: float=0.0) -> None:
        self.x = x
        self.y = y

    def __repr__(self) -> str:
        return "Point({}, {})".format(self.x, self.y)

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Point):
            return NotImplemented
        return float_equal(self.x, other.x) and \
            float_equal(self.y, other.y)

    def __add__(self, other: 'Point') -> 'Point':
        return Point(self.x + other.x, self.y + other.y)

    def __sub__(self, other: 'Point') -> 'Point':
        return Point(self.x - other.x, self.y - other.y)

    def __mul__(self, k: float) -> 'Point':
        return Point(self.x * k, self.y * k)

    def __rmul__(self, k: float) -> 'Point':
        return self * k

    def __truediv__(self, k: float) -> 'Point':
        return Point(self.x / k, self.y / k)

    def __lt__(self, other: 'Point') -> bool:
        return self.y < other.y \
            if abs(self.x - other.x) < EPS \
            else self.x < other.x

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return sqrt(self.norm())

    def dot(self, other: 'Point') -> float:
        return self.x * other.x + self.y * other.y

    def cross(self, other: 'Point') -> float:
        return self.x * other.y - self.y * other.x

    def is_orthogonal(self, other: 'Point') -> bool:
        return float_equal(self.dot(other), 0.0)

    def is_parallel(self, other: 'Point') -> bool:
        return float_equal(self.cross(other), 0.0)


Vector = Point


class Segment:

    def __init__(self, p1: Point = None, p2: Point = None) -> None:
        self.p1: Point = Point() if p1 is None else p1
        self.p2: Point = Point() if p2 is None else p2

    def __repr__(self) -> str:
        return "Segment({}, {})".format(self.p1, self.p2)

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Segment):
            return NotImplemented
        return self.p1 == other.p1 and self.p2 == other.p2

    def vector(self):
        return self.p2 - self.p1

    def is_orthogonal(self, other: 'Segment') -> bool:
        return self.vector().is_orthogonal(other.vector())

    def is_parallel(self, other: 'Segment') -> bool:
        return self.vector().is_parallel(other.vector())


Line = Segment


class Circle:

    def __init__(self, c: Point=None, r: float=0.0) -> None:
        self.c: Point = Point() if c is None else c
        self.r: float = r

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Circle):
            return NotImplemented
        return self.c == other.c and self.r == other.r

    def __repr__(self) -> str:
        return "Circle({}, {})".format(self.c, self.r)


def classify(s1: Segment, s2: Segment) -> int:
    if s1.is_parallel(s2):
        return 2
    elif s1.is_orthogonal(s2):
        return 1
    else:
        return 0


def main() -> None:
    q = int(input())
    for _ in range(q):
        s1, s2 = Segment(), Segment()
        s1.p1.x, s1.p1.y, s1.p2.x, s1.p2.y, \
            s2.p1.x, s2.p1.y, s2.p2.x, s2.p2.y = \
            [int(x) for x in input().split()]
        print(classify(s1, s2))


if __name__ == "__main__":
    main()

Solution (Python):
class Point(object):
    __slots__ = ["x", "y"]

    def __init__(self, x, y):
        self.x = x
        self.y = y


class Vector(object):
    __slots__ = ["p1", "p2", "x", "y"]

    def __init__(self, p1: Point, p2: Point):
        self.p1 = p1
        self.p2 = p2
        self.x = p2.x - p1.x
        self.y = p2.y - p1.y

    def dot(self, other: "Vector"):
        return self.x * other.x + self.y * other.y

    def cross(self, other: "Vector"):
        return self.x * other.y - self.y * other.x


if __name__ == "__main__":
    import sys
    answer = []
    append = answer.append
    input()
    for x1, y1, x2, y2, x3, y3, x4, y4 in (map(int, l.split()) for l in sys.stdin):
        vector1 = Vector(Point(x1, y1), Point(x2, y2))
        vector2 = Vector(Point(x3, y3), Point(x4, y4))
        if vector1.dot(vector2) == 0:
            append(1)
        elif vector1.cross(vector2) == 0:
            append(2)
        else:
            append(0)

    print(*answer, sep="\n")

Solution (Python):
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]
def MI(): return map(int, input().split())



"""
x,y,s,t = map(float, input().split())
a = int(input())
s-=x
t-=y
while a:
    a -= 1
    p,q = map(float, input().split())
    p-=x
    q-=y
    ans_x = s*(q*t+p*s)/(t*t+s*s)
    ans_y = t*(q*t+p*s)/(t*t+s*s)
    print(x+ans_x, y+ans_y)
"""


"""
p1x,p1y,c,d = MI()
q = II()
if p1x == c:
    f = 0
elif p1y == d:
    f = 1
else:
    f = 2
    m = (d-p1y)/(c-p1x)
for _ in range(q):
    px,py = MI()
    if not f:
        a = 2*p1x-px
        b = py
    elif f == 1:
        a = px
        b = 2*p1y-py
    else:
        a = (2*py+(1/m-m)*px+2*m*p1x-2*p1y)/(m+1/m)
        b = -1/m*(a-px)+py
    print(a,b)
"""


"""
def inner_product(a,b):
    return a[0]*b[0]+a[1]*b[1]

def cross_product(a,b):
    return a[0]*b[1]-a[1]*b[0]
p,q,c,d = MI()
a = [c-p,d-q]
r = II()
for _ in range(r):
    c,d = MI()
    b = [c-p,d-q]
    co = inner_product(a,b)
    si = cross_product(a,b)
    if si == 0:
        if co >= 0:
            if a[0]**2+a[1]**2 >= b[0]**2+b[1]**2:
                print("ON_SEGMENT")
            else:
                print("ONLINE_FRONT")
        else:
            print("ONLINE_BACK")
    elif si > 0:
        print("COUNTER_CLOCKWISE")
    else:
        print("CLOCKWISE")
"""



def inner_product(a,b):
    return a[0]*b[0]+a[1]*b[1]

def cross_product(a,b):
    return a[0]*b[1]-a[1]*b[0]
q = II()
for i in range(q):
    s,t,a,b,x,y,c,d = MI()
    a = [a-s,b-t]
    b = [c-x,d-y]
    co = inner_product(a,b)
    si = cross_product(a,b)
    if not si:
        print(2)
    elif not co:
        print(1)
    else:
        print(0)

Solution (Python):





import sys
input = sys.stdin.readline

from math import cos,sin,radians,sqrt

def main():

    for i in range(int(input())):
        (x1,y1,x2,y2,x3,y3,x4,y4) = map(int,input().split())

        inner = (x2-x1) * (x4-x3) + (y2-y1) * (y4-y3)
        cross = (x2-x1) * (y4-y3) - (x4-x3) * (y2-y1)               
        if inner == 0:
            print("1")
        elif cross == 0:
            print ("2")
        else:
            print("0")

    
if __name__ == '__main__':
    main()

Solution (Python):
q = int(input())
eps = 1e-8
for _ in range(q):
    xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3 = map(int, input().split())
    v1 = complex(xp1 - xp0, yp1 - yp0)
    v2 = complex(xp3 - xp2, yp3 - yp2)
    temp = v1.conjugate() * v2
    dot = temp.real
    cross = temp.imag
    
    if  abs(dot) < eps:
        print("1")
    elif abs(cross) < eps:
        print("2")
    else:
        print("0")

Solution (Python):




def is_parallel(v1, v2):
    return dot(orthogonal(v1), v2) == 0


def is_orthogonal(v1, v2):
    return dot(v1, v2) == 0


def dot(v1, v2):
    x1, y1 = v1
    x2, y2 = v2
    return x1 * x2 + y1 * y2


def orthogonal(v):
    x, y = v
    return -y, x


def run():
    q = int(input())

    for _ in range(q):
        x0, y0, x1, y1, x2, y2, x3, y3 = [int(i) for i in input().split()]

        v1 = (x1-x0, y1-y0)
        v2 = (x3-x2, y3-y2)

        if is_parallel(v1, v2):
            print(2)
        elif is_orthogonal(v1, v2):
            print(1)
        else:
            print(0)


if __name__ == '__main__':
    run()

Solution (Python):
class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __sub__(self, other):
        return Point(self.x - other.x, self.y - other.y)

    def __repr__(self):
        return f"({self.x},{self.y})"


class Segment:
    def __init__(self, x: Point, y: Point):
        self.pt1 = x
        self.pt2 = y
        self.vector = self.pt2 - self.pt1

    def dot(self, other):
        return self.vector.x * other.vector.x + self.vector.y * other.vector.y

    def cross(self, other):
        return self.vector.x * other.vector.y - self.vector.y * other.vector.x

    def __repr__(self):
        return f"{self.pt1},{self.pt2},{self.vector}"


def main():
        n = int(input())
        for i in range(n):
            p0_x, p0_y, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y = map(int, input().split())
            seg_1 = Segment(Point(p0_x, p0_y), Point(p1_x, p1_y))
            seg_2 = Segment(Point(p2_x, p2_y), Point(p3_x, p3_y))

            if seg_1.dot(seg_2) == 0:
                print('1')
            elif seg_1.cross(seg_2) == 0:
                print('2')
            else:
                print('0')
        return

main()

Solution (Python):
import math

EPS = 1e-10

def equals(a, b):
    return abs(a - b) < EPS


class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

    def __add__(self, p):
        return Point(self.x + p.x, self.y + p.y)

    def __sub__(self, p):
        return Point(self.x - p.x, self.y - p.y)

    def __mul__(self, a):
        return Point(self.x * a, self.y * a)

    def __rmul__(self, a):
        return self * a

    def __truediv__(self, a):
        return Point(self.x / a, self.y / a)

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

    def __lt__(self, p):
        if self.x != p.x:
            return self. x < p.x
        else:
            return self.y < p.y

    def __eq__(self, p):
        return equals(self.x, p.x) and equals(self.y, p.y)


class Segment:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2


def dot(a, b):
    return a.x * b.x + a.y * b.y


def cross(a, b):
    return a.x * b.y - a.y * b.x


def isOrthogonal(s1, s2):
    return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0)


def isParallel(s1, s2):
    return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0)


if __name__ == '__main__':
    q = int(input())
    ans = []
    for i in range(q):
        x0, y0, x1, y1, x2, y2, x3, y3 = [int(v) for v in input().split()]
        s1 = Segment(Point(x0, y0), Point(x1, y1))
        s2 = Segment(Point(x2, y2), Point(x3, y3))
        if isParallel(s1, s2):
            ans.append(2)
        elif isOrthogonal(s1, s2):
            ans.append(1)
        else:
            ans.append(0)

    for v in ans:
        print(v)

Solution (Python):


import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

q = input()

for loop in range(q):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(int, raw_input().split())
    a1, b1 = [x1 - x0, y1 - y0]
    a2, b2 = [x3 - x2, y3 - y2]

    if a1 * b2 - b1 * a2 == 0:
        print 2
    elif a1 * a2 + b1 * b2 == 0:
        print 1
    else:
        print 0