#include <iostream>
#include <cmath>
#include <complex>
#include <vector>

using namespace std;

typedef complex<int> P;


double len(P p1, P p2) {
	double dx = p1.real() - p2.real();
	double dy = p1.imag() - p2.imag();
	return sqrt(dx * dx + dy * dy);
}

double S(P p1, P p2, P p3) {
	double a = len(p1, p2);
	double b = len(p2, p3);
	double c = len(p3, p1);
	double z = (a + b + c) / 2;
	return sqrt( z * (z-a) * (z-b) * (z-c) );
}

int main() {
	int N;
	while (cin >> N, N) {
		for (int n = 0; n < N; ++n) {
			int M; cin >> M;
			vector< vector<P> > p( 4, vector<P>() );
			for (int i = 0; i < M; ++i)
				for (int j = 0; j < 4; ++j) {
					int x, y; cin >> x >> y;
					p[j].push_back( P(x, y) );
				}

			vector<int> par;
			for (int i = 0; i < M; ++i)
				par.push_back(i);

			vector<double> s;
			for (int i = 0; i < M; ++i)
				s.push_back( S(p[0][i], p[1][i], p[2][i]) + S(p[1][i], p[2][i], p[3][i]) );

			for (int i = 0; i < M; ++i)
				for (int j = 0; j < M; ++j)
					for (int k = 0; k < 4; ++k) {
						double sum = 0;
						for (int l = 0; l < 4; ++l)
							sum += S(p[k][j], p[l][i], p[(l+1)%4][i]);

						if ( abs(sum - s[i]) < 0.000000001 ) par[j] = par[i];
					}

			int ans = 0;
			vector<bool> pars(M, false);
			for (int i = 0; i < M; ++i)
				if (!pars[par[i]]) {
					pars[par[i]] = true;
					++ans;
				}

			cout << ans << endl;
		}
	}
}