#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define io_o() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fst first
#define scd second
#define endl "\n"
#define mkpair make_pair
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define REP(i,n) for(int i = 0; i < n; i++)
#define int ll

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;

const int MAX = 2e5 + 5;
int dp[MAX], cnt[MAX];

int32_t main(){
    io_o(); 
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        
        fill(dp, dp + MAX, 0);
        fill(cnt, cnt + MAX, 0);

        REP(i, n) {int x; cin >> x; cnt[x]++, dp[x] ++;}
        int ans = 0;
        for(int i = 1; i < MAX; i++){
            if(!cnt[i]) continue;
            for(int j = 2 * i; j < MAX; j += i){
                if(!cnt[j]) continue;
                dp[j] = max(dp[j], dp[i] + cnt[j]);
            }
            ans = max(ans, dp[i]);
        }
        cout << n - ans << endl;

    }
    return 0;
}

