import kotlin.math.*

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
}

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)
    }
    var ans = 0
    for (a in inputs) {
        for ((bId, b) in inputs.withIndex()) {
            if (a.dir * b.dir == 0L) continue
            for (cId in bId + 1 until inputs.size) {
                val c = inputs[cId]
                if (a.dir * c.dir == 0L || b.dir * c.dir == 0L) continue
                val (onB, nonB) = a.chooseOn(b) ?: continue
                val (onC, nonC) = a.chooseOn(c) ?: continue
                if (onB != onC) continue
                if (((nonB - onB) * (a.b - onB)).sign != ((nonC - onC) * (a.b - onC)).sign) continue
                ans += 1
            }
        }
    }
    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() }