#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
typedef long long lld;
typedef double lf;
typedef long double llf;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<lld, int> pli;
#define For(i,s,a) for(int i = (int)s; i < (int)a; ++i)
#define rpt(s, it) for(auto it = s.begin(); it != s.end(); ++it)
#define brpt(s, it) for(auto it = s.rend(); it != s.rbegin(); --it)
#define sz size()
#define pb push_back
#define eb emplace_back
#define ff first
#define dd second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ZAPS {int t; scanf("%i", &t); while(t--) solve();}
#define make_unique(x) (x).erase( unique(all(x)), (x).end())


template<typename Ta, typename Tb>
ostream & operator <<(ostream & os, pair<Ta, Tb> x){
	return os << x.ff << " " << x.dd;
}


const int N = 2e5 + 1;

vector<int>pr[N];

void sito(){
	For(i, 1, 200001)
		for(int j = i; j < 200001; j += i)
			pr[j].pb(i);
}

int ile[N];
int dp[N];

void solve(void){
	memset(ile, 0, sizeof(ile));
	memset(dp, 0, sizeof(dp));
	int n;
	scanf("%d", &n);
	For(i, 0, n){
		int g;
		scanf("%d", &g);
		++ile[g];
	}
	int maxn = 0;
	For(x, 1, 200001){
		if(ile[x] == 0)
			continue;
		for(auto s : pr[x])
			dp[x] = max(dp[x], dp[s]);
		dp[x] += ile[x];
		maxn = max(maxn, dp[x]);
	}
	printf("%d\n", n - maxn);
}

int32_t main(void){
	sito();
	ZAPS
}
