#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#define fs(i,x,y) for(int i=(x),_=(y);i<=_;++i)
#define fn(i,x,y) for(int i=(x),_=(y);i>=_;--i)
#define tor(i,v,x) for(int i=head[x],v=to[i];i;i=nxt[i],v=to[i])
#define Li inline
#define R register int
#define ls(x) ch[x][0]
#define rs(x) ch[x][1]
#define mpi(x,y) make_pair(x,y)
#define pi pair<int,int>
#define int ll
using namespace std;
typedef long long ll;
template<typename T>
void read(T &x){
	x=0;char ch=getchar();bool f=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	x=f?-x:x;
}

const int N=2e5+7;
const int NN=2e5;
int n,m;
int a[N],cnt[N],dp[N];

signed main(){
	int T;read(T);while(T--){
		memset(cnt,0,sizeof(cnt));
		memset(dp,0,sizeof(dp));
		read(n);fs(i,1,n){
			int x;read(x);++cnt[x];
		}
		fs(i,1,NN){
			dp[i]+=cnt[i];
			for(int j=i<<1;j<=NN;j+=i)dp[j]=max(dp[j],dp[i]);
		}
		printf("%lld\n",n-*max_element(dp+1,dp+NN+1));
	}
	return 0;
}
