#include <bits/stdc++.h>
using namespace std;
const int N=200010;
int f[N],sz[N];
int mp[N];
int main(void)
{
    int t;cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)scanf("%d",&sz[i]);
        sort(sz+1,sz+n+1);
        //for(int i=1;i<=n;i++)if(!mp[sz[i]])mp[sz[i]]=i;
        int res=0;
        for(int i=1;i<=n;i++)
        {
            f[i]=1;
            for(int j=1;j<=sz[i]/j;j++)
            {
                if(sz[i]%j==0)
                {
                    int p1=j,p2=sz[i]/j;
                        f[i]=max(f[i],f[mp[p1]]+1);
                        f[i]=max(f[i],f[mp[p2]]+1);
                }
            }
            res=max(res,f[i]);
            mp[sz[i]]=i;
        }
         printf("%d\n",n-res);
         for(int i=1;i<N;i++)f[i]=0,mp[i]=0;
    }

    return 0;
}