#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#define int long long
#define endl '\n'
typedef long long ll;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		const int N = 2e5+5;
		vector<int> cnts(N,0);
		for(int i = 0; i < n; ++i) {
			int val;
			cin >> val;
			++cnts[val];
		}
		int res = 0;
		for(int val = N-1; val >= 1; --val) {
			int tmp = cnts[val];
			cnts[val] = 0;
			for(int j = val+val; j < N; j += val) {
				cnts[val] = max(cnts[val], cnts[j]);
			}
			cnts[val] += tmp;
			res = max(res, cnts[val]);
		}
		cout << n-res << endl;
	}
}
