Given an undirected graph, find how many triangles it can have where a triangle is a cyclic path of length three which begins and end at the same vertex.
#### An undirected graph is a graph in which if you can go from a vertex, say, βAβ to βB,β you can come back to βAβ from βB.β
For example:

In this graph, we can visit from vertex 1 to 2, then we can also visit from vertex 2 to 1. This is true for all vertices.
The very first line contains an integer βTβ which denotes the number of test cases.
The first line of each test case contains a single integer βVβ denoting the number of vertices of the graph.
The following βVβ lines of each test case contain βVβ integers representing the edges.
If the integer is 1, then we say that thereβs an edge from its row Number to column Number. Here, 0-based indexing has been followed.
Output Format :
For every test case, print the number of triangles in the graph.
##### Note : You donβt need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= V <= 10^2
0 <= V[i][j] <= 1
Where βiβ and βjβs are the row number and column number, respectively, if V[i][j] = 1, it means thereβs an edge from βiβ to βjβs; otherwise, thereβs no edge.
Time Limit: 1 sec
Sample Input 1:
2
2
0 1
1 0
5
0 1 1 0 1
1 0 1 1 0
1 1 0 1 0
0 1 1 0 1
1 0 0 1 0
Sample Output 1:
0
2
Explanation for Sample Output 1 :
In the first test case, the edges are as follows :
0 --- 1
As we can see, there are no cycles with three vertices. Hence the output is 0.
In the second case, the edges are as follow :
The two cycles are :
0 - 1 - 2
1 - 2 - 3
Note: there are other cycles as well (0-1-2-3-4),(0-1-3-4) however we are considering only those cycles, where the number of vertices is 3
Sample Input 2 :
2
3
0 1 1
1 0 0
1 0 0
4
0 0 1 1
0 0 1 1
1 1 0 1
1 1 1 0
Sample Output 2 :
0
2
2
2
0 1
1 0
5
0 1 1 0 1
1 0 1 1 0
1 1 0 1 0
0 1 1 0 1
1 0 0 1 0
0
2
In the first test case, the edges are as follows :
0 --- 1
As we can see, there are no cycles with three vertices.
Hence the output is 0.
In the second case, the edges are as follow :

The two cycles are :
0 - 1 - 2
1 - 2 - 3
Note: there are other cycles as well (0-1-2-3-4),(0-1-3-4) however we are considering only those cycles, where the number of vertices is 3
can you think of finding three-pointers i,j,k, such that there is an edge from i to j and j to k and k to j?
We call a cycle triangle if its length is 3. So all we need to do is find three vertices such that they all share an edge with each other. In order to find that cycle, we can fix three-pointer βiβ , βjβ , βkβ.
If there is an Edge between (i, j), (j, k), and (k, i) then we will add this cycle to our answer.
Algorithm :
O(V^3) , Where βVβ is the number of vertices.
As there are three nested loop, and each loop is running approximately βVβ times; hence complexity is O(V^3)
O(1)
Matrix space take O(n^2) space