This page is still under construction.

Parts of this page are still being built. What you see may change.

Parallelogram Counting

Interview

Time limit1sMemory limit128 MB

Summary
Given n points, count how many 4-point subsets form a parallelogram by pairing points that share a midpoint.
Level

Medium6 of 10

Topics
Hash map, Geometry, Combinatorics, Math
Solved
No attempts yet

Problem

You are given nn distinct points in the plane, each with integer coordinates. Count the number of parallelograms whose four vertices are all among these points.

Formally, count the 44-element subsets that can be labeled {A,B,C,D}\{A, B, C, D\} so that AB∥CDAB \parallel CD and BC∥ADBC \parallel AD. No four of the given points are collinear.

Input

The first line contains an integer tt (1≤t≤101 \le t \le 10), the number of test cases. The test cases follow.

For each test case, the first line contains an integer nn (1≤n≤10001 \le n \le 1000). Each of the next nn lines contains two space-separated integers xx and yy (∣x∣,∣y∣≤109|x|, |y| \le 10^9), the coordinates of one point.

Output

Print tt lines. The ii-th line contains the number of parallelograms for the ii-th test case.

Examples3

  1. Example 1

    Input
    2
    6
    0 0
    2 0
    4 0
    1 1
    3 1
    5 1
    7
    -2 -1
    8 9
    5 7
    1 1
    4 8
    2 0
    9 8
    
    Expected output
    5
    6
    
  2. Example 2

    Input
    1
    4
    0 0
    1 0
    1 1
    0 1
    
    Expected output
    1
    
  3. Example 3

    Input
    2
    5
    0 0
    2 0
    0 2
    2 2
    1 1
    4
    0 0
    3 1
    4 4
    1 3
    
    Expected output
    1
    1