#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

typedef complex<double> P;
typedef complex<double> Vec;

int N, M;
P p[100][4];
bool done[100];

double cross(Vec a, Vec b) {
	return a.real() * b.imag() - a.imag() * b.real();
}

P input() {
	double x, y;
	scanf("%lf %lf", &x, &y);
	return P(x, y);
}

bool collision(int u, int t) {
	REP(i, 4) { // t_i
		bool f = true;
		REP(j, 4) { // u_j,u_j+1
			if (cross(p[u][(j + 1) % 4] - p[u][j], p[t][i] - p[u][j]) > EPS) f = false;
		}
		if (!f) return false;
	}
	return true;
}

void dfs(int u) {
	done[u] = true;
	
	REP(i, M) if (!done[i]) {
		if (collision(u, i)) dfs(i);
	}
}

int main() {
	while (cin >> N, N) {
		REP(t, N) {
			cin >> M;
			REP(i, M) REP(j, 4) p[i][j] = input();
			
			memset(done, 0, sizeof(done));
			int ans = 0;
			REP(i, M) if (!done[i]) dfs(i), ans++;
			
			cout << ans << endl;
		}
	}
	return 0;
}