import kotlin.math.*

tailrec fun gcd(x: Int, y: Int) : Int = if (y == 0) x else gcd(y, x % y)

data class Point(val x:Int, val y:Int) {
    operator fun minus(other: Point) = Point(x - other.x, y - other.y)
    operator fun times(other: Point) = x.toLong() * other.y - y.toLong() * other.x
    override fun hashCode() = x * 1234567891 + y
    fun norm() = gcd(abs(x), abs(y)).let { Point(x / it, y / it) }
}

data class Segment(val a:Point, val b:Point) {
    val dir get() = b - a

    fun on(p: Point) = (p - a) * (b - a) == 0L &&
            p.x in minOf(a.x, b.x)..maxOf(a.x, b.x) &&
            p.y in minOf(a.y, b.y)..maxOf(a.y, b.y) &&
            p != a && p != b

    fun chooseOn(a: Segment) = when {
        on(a.a) -> a.a to a.b
        on(a.b) -> a.b to a.a
        else -> null
    }
}

private fun solve() {
    val inputs = List(readInt()) {
        val (x, y, z, w) = readInts()
        val a = Point(x, y)
        val b = Point(z, w)
        Segment(a, b)
    }
    val ans = inputs.sumOf { a ->
        inputs.mapNotNull { b ->
            if (a.dir * b.dir == 0L) return@mapNotNull null
            a.chooseOn(b)
        }.groupBy({ it.first }, { it.second }).entries.sumOf { (start, ends) ->
            val lefts = ends.count { (it - start) * (a.b - start) > 0L }
            val rights = ends.size - lefts
            val all = lefts * (lefts - 1) / 2 + rights * (rights - 1) / 2
            val colinear = ends.groupingBy { (it - start).norm() }.eachCount().values.sumOf { it * (it - 1) / 2 }
            all - colinear
        }
    }
    println(ans)
}

fun main() {
    repeat(readInt()) {
        solve()
    }
}

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readLongs() = readStrings().map { it.toLong() }
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }