#include <bits/stdc++.h>
#define T int t; cin >> t; while (t--)
using namespace std;
typedef long long ll;

const int max_a = 200000;

void solve() {
	int n; cin >> n;
	vector<int> cnt(max_a+1);
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		cnt[a]++;
	}
	int rem = 0;
	vector<int> dp(max_a+1);
	for (int i = 1; i <= max_a; i++) {
		if (!cnt[i]) continue;
		dp[i] += cnt[i];
		for (int j = i; j <= max_a; j+=i) {
			if (cnt[j]) {
				dp[j] = max(dp[j], dp[i]);
			}
		}
		rem = max(rem, dp[i]);
	}
	cout << n-rem << "\n";
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	T solve();
	return 0;
}