#include <iostream>
using namespace std;
int main() {
int T, N, wood[101];
cin >> T;
while ( T-- ) {
cin >> N;
for ( int i = 0; i < N; ++i )
cin >> wood[i];
int ans = 0;
for ( int i = 0; i < N; ++i )
for ( int j = 0; j < N; ++j )
for ( int k = 0; k < N; ++k )
ans += ( wood[i] * wood[i] + wood[j] * wood[j] == wood[k] * wood[k] );
cout << ans / 2 << endl;
}
return 0;
}