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
...
qth query

Each query consists of integer coordinates of the points p0, p1, p2, p3 in the following format:

xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3

Output

For each query, print "2", "1" or "0".

Constraints

1 ≤ q ≤ 1000

-10000 ≤ xpi, ypi ≤ 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 in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    // ab ??¨ cd ????????????
    static bool IsParallel(Vec2 a, Vec2 b, Vec2 c, Vec2 d) {
        var ab = b - a;
        var cd = d - c;
        return ab.Cross(cd) == 0;
    }

    // ab ??¨ cd ????????´???
    static bool IsOrthogonal(Vec2 a, Vec2 b, Vec2 c, Vec2 d) {
        var ab = b - a;
        var cd = d - c;
        return ab.Dot(cd) == 0;
    }

    static int Calc(Vec2 a, Vec2 b, Vec2 c, Vec2 d) {
        if (IsParallel(a, b, c, d)) return 2;
        if (IsOrthogonal(a, b, c, d)) return 1;
        return 0;
    }

    static void Main() {
        var n = ReadInt();
        for (int i = 0; i < n; i++) {
            var ps = ReadInts();
            var a = new Vec2(ps[0], ps[1]);
            var b = new Vec2(ps[2], ps[3]);
            var c = new Vec2(ps[4], ps[5]);
            var d = new Vec2(ps[6], ps[7]);

            Console.WriteLine(Calc(a, b, c, d));
        }
    }
}

struct Vec2 {
    public double X { get; private set; }
    public double Y { get; private set; }

    public Vec2(double x, double y) : this() {
        X = x;
        Y = y;
    }

    public override string ToString() {
        return string.Format("({0}, {1})", X, Y);
    }

    public static Vec2 operator+(Vec2 a, Vec2 b) {
        return new Vec2(a.X + b.X, a.Y + b.Y);
    }

    public static Vec2 operator-(Vec2 a, Vec2 b) {
        return new Vec2(a.X - b.X, a.Y - b.Y);
    }

    public static Vec2 operator*(Vec2 a, double t) {
        return new Vec2(a.X * t, a.Y * t);
    }

    public static Vec2 operator*(double t, Vec2 a) {
        return new Vec2(a.X * t, a.Y * t);
    }

    // a???b = |a||b|cos??
    public double Dot(Vec2 other) {
        return X * other.X + Y * other.Y;
    }

    public double Cross(Vec2 other) {
        return X * other.Y - Y * other.X;
    }

    public Vec2 Normalized() {
        var m = Magnitude();
        if (m != 0 && m != 1) {
            return new Vec2(X / m, Y / m);
        }
        return this;
    }

    public double Magnitude() {
        return Math.Sqrt(X * X + Y * Y);
    }

    public double SqrMagnitude() {
        return X * X + Y * Y;
    }

    public static double Distance(Vec2 a, Vec2 b) {
        return (a - b).Magnitude();
    }
}