//ANIK BARUA
//9.25.2023- 3:06 PM
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
int calc(int a, int b)
{
return (atan2(a, b) * 180) / PI;
}
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<pair<int, int>> vec;
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
vec.push_back(make_pair(a, b));
}
int count = 0;
for (int i = 0; i < n - 1; i++)
{
int x1 = vec[i].first;
int y1 = vec[i].second;
for (int j = i + 1; j < n; j++)
{
int x2 = vec[j].first;
int y2 = vec[j].second;
int angle = calc(x1 - x2, y1 - y2);
if (angle % 45 == 0)
{
count++;
}
}
}
cout << count*2 << endl;
}
return 0;
}
Ly9BTklLIEJBUlVBIAovLzkuMjUuMjAyMy0gIDM6MDYgUE0KI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgUEkgMy4xNDE1OTI2NQoKaW50IGNhbGMoaW50IGEsIGludCBiKQp7CiAgICAKICAgICAgICByZXR1cm4gKGF0YW4yKGEsIGIpICogMTgwKSAvIFBJOwogICAgCn0KaW50IG1haW4oKQp7CiAgICBpbnQgdDsKICAgIGNpbiA+PiB0OwogICAgd2hpbGUgKHQtLSkKICAgIHsKICAgICAgICBpbnQgbjsKICAgICAgICBjaW4gPj4gbjsKICAgICAgICB2ZWN0b3I8cGFpcjxpbnQsIGludD4+IHZlYzsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKICAgICAgICB7CiAgICAgICAgICAgIGludCBhLCBiOwogICAgICAgICAgICBjaW4gPj4gYSA+PiBiOwogICAgICAgICAgICB2ZWMucHVzaF9iYWNrKG1ha2VfcGFpcihhLCBiKSk7CiAgICAgICAgfQogICAgICAgIGludCBjb3VudCA9IDA7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuIC0gMTsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgaW50IHgxID0gdmVjW2ldLmZpcnN0OwogICAgICAgICAgICBpbnQgeTEgPSB2ZWNbaV0uc2Vjb25kOwoKICAgICAgICAgICAgZm9yIChpbnQgaiA9IGkgKyAxOyBqIDwgbjsgaisrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpbnQgeDIgPSB2ZWNbal0uZmlyc3Q7CiAgICAgICAgICAgICAgICBpbnQgeTIgPSB2ZWNbal0uc2Vjb25kOwogICAgICAgICAgICAgICAgaW50IGFuZ2xlID0gY2FsYyh4MSAtIHgyLCB5MSAtIHkyKTsKICAgICAgICAgICAgICAgIGlmIChhbmdsZSAlIDQ1ID09IDApCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgY291bnQrKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb3V0IDw8IGNvdW50KjIgPDwgZW5kbDsKICAgIH0KCiAgICByZXR1cm4gMDsKfQ==