#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ud unsigned int
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x3f
#define MAX_INF_VAL 0x3f3f3f3f
#define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f
//#define pi 3.141592653589
#define eps 1e-9
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
//#define p 2173412051LL
//#define sz 2

using namespace std;

template< typename T > void read( T &x ) {
	x = 0;
	char ch = getchar();
	ll f = 1;
	while( !isdigit( ch ) ) {
		if( ch == '-' )
		f *= -1;
		ch = getchar();
	}
	while( isdigit( ch ) ) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	x *= f;
}

int num;
bool vis[ 200010 ];
int prime[ 200010 ];
int cnt[ 200010 ];
int f[ 200010 ];

void pre();

int main() {
	ios::sync_with_stdio( false );
	cin.tie( 0 ), cout.tie( 0 );
	int t;
	int n, x;
	pre();
	cin >> t;
	while( t-- ) {
		cin >> n;
		memset( cnt, 0, sizeof( cnt ) );
		memset( f, 0, sizeof( f ) );
		for( int i = 1; i <= n; ++i ) {
			cin >> x;
			++cnt[ x ];
		}
		int ans = 0;
		for( int i = 200000; i; --i ) {
			f[ i ] = cnt[ i ];
			for( int j = 0; 1LL * i * prime[ j ] <= 200000; ++j )
				f[ i ] = max( f[ i ], cnt[ i ] + f[ i * prime[ j ] ] );
			ans = max( ans, f[ i ] );
		}
		cout << n - ans << '\n';
	}
	return 0;
}

void pre() {
	memset( vis, false, sizeof( vis ) );
	vis[ 0 ] = vis[ 1 ] = true;
	for( int i = 2; i <= 200000; ++i ) {
		if( !vis[ i ] ) {
			prime[ num++ ] = i;
		}
		for( int j = 0; j < num; ++j ) {
			if( i * prime[ j ] > 200000 )
				break;
			vis[ i * prime[ j ] ] = true;
			if( !( i % prime[ j ] ) )
				break;
		}
	}
}