#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
	while(c>=48&&c<=57)x=x*10+c-48,c=getchar();
	return x*f;
}
inline void write(int x){
	char c[20],len=0;
	if(!x){putchar('0');return;}
	if(x<0)x=-x,putchar('-');
	while(x)c[len++]=x%10,x/=10;
	while(len)putchar(c[--len]+48);
}
#define space(x) write(x),putchar(' ')
#define enter(x) write(x),putchar('\n')

const int N=2e5+10;
int n,m=2e5,a[N],c[N],f[N],ans;
vector<int> e[N];
inline void adde(int x,int y){e[x].push_back(y);}
int solve(){
	n=read(),ans=0;
	memset(c,0,sizeof(c));
	memset(f,0,sizeof(f));
	for(int i=1;i<=n;++i)++c[a[i]=read()];
	for(int i=1;i<=m;++i){
		ans=max(ans,f[i]+=c[i]);
		for(int j=i;j<=m;j+=i)
			f[j]=max(f[j],f[i]);
	}
	return n-ans;
}
int main(){
	int T=read();
	while(T--)enter(solve());
}