#include<bits/stdc++.h>
using namespace std;
#define int long long
int ans;
main() {
ios_base::sync_with_stdio(0),cin.tie(0);
int t;cin>>t;
while(t--){
vector<pair<int,int>>e;
int n,m;cin>>n>>m;
vector<int>dg(n);
vector<vector<int>>g(n);
for(int i=0;i<m;i++){
int a,b;cin>>a>>b;a--,b--;
e.push_back(make_pair(a,b));
dg[a]++;
dg[b]++;
g[a].push_back(b);
g[b].push_back(a);
}
for(int i=0;i<n;i++)sort(g[i].begin(),g[i].end());
ans=0;
for(int i=0;i<m;i++){
ans+=dg[e[i].first]+dg[e[i].second]-2;
}
ans/=2;
for(int i=0;i<n;i++){
for(auto j:g[i]){
if(j>i)break;
for(auto k:g[j]){
if(k>j)break;
if(binary_search(g[i].begin(),g[i].end(),k))ans-=3;
}
}
}
cout<<ans<<endl;
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBpbnQgbG9uZyBsb25nCgoKCmludCBhbnM7Cm1haW4oKSB7CiAgICAgICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKSxjaW4udGllKDApOwogICAgICAgIGludCB0O2Npbj4+dDsKICAgICAgICB3aGlsZSh0LS0pewogICAgICAgICAgICAgICAgdmVjdG9yPHBhaXI8aW50LGludD4+ZTsKICAgICAgICAgICAgICAgIGludCBuLG07Y2luPj5uPj5tOwogICAgICAgICAgICAgICAgdmVjdG9yPGludD5kZyhuKTsKICAgICAgICAgICAgICAgIHZlY3Rvcjx2ZWN0b3I8aW50Pj5nKG4pOwogICAgICAgICAgICAgICAgZm9yKGludCBpPTA7aTxtO2krKyl7CiAgICAgICAgICAgICAgICAgICAgICAgIGludCBhLGI7Y2luPj5hPj5iO2EtLSxiLS07CiAgICAgICAgICAgICAgICAgICAgICAgIGUucHVzaF9iYWNrKG1ha2VfcGFpcihhLGIpKTsKICAgICAgICAgICAgICAgICAgICAgICAgZGdbYV0rKzsKICAgICAgICAgICAgICAgICAgICAgICAgZGdbYl0rKzsKICAgICAgICAgICAgICAgICAgICAgICAgZ1thXS5wdXNoX2JhY2soYik7CiAgICAgICAgICAgICAgICAgICAgICAgIGdbYl0ucHVzaF9iYWNrKGEpOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIGZvcihpbnQgaT0wO2k8bjtpKyspc29ydChnW2ldLmJlZ2luKCksZ1tpXS5lbmQoKSk7CgogICAgICAgICAgICAgICAgYW5zPTA7CiAgICAgICAgICAgICAgICBmb3IoaW50IGk9MDtpPG07aSsrKXsKICAgICAgICAgICAgICAgICAgICAgICAgYW5zKz1kZ1tlW2ldLmZpcnN0XStkZ1tlW2ldLnNlY29uZF0tMjsKICAgICAgICAgICAgICAgIH0KCgogICAgICAgICAgICAgICAgYW5zLz0yOwoKICAgICAgICAgICAgICAgIGZvcihpbnQgaT0wO2k8bjtpKyspewogICAgICAgICAgICAgICAgICAgICAgICBmb3IoYXV0byBqOmdbaV0pewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmKGo+aSlicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3IoYXV0byBrOmdbal0pewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYoaz5qKWJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYoYmluYXJ5X3NlYXJjaChnW2ldLmJlZ2luKCksZ1tpXS5lbmQoKSxrKSlhbnMtPTM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CgoKICAgICAgICAgICAgICAgIGNvdXQ8PGFuczw8ZW5kbDsKICAgICAgICB9Cn0=