#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
typedef long long LL;
int lcm(int a, int b) {
return a / __gcd(a, b) * b;
}
void solve() {
int n, a ,b, c;
cin >> n >> a >> b >> c;
int res = n / a - n / lcm(a, b) + n / c - n / lcm(a, c);
int temp = lcm(lcm(a, b), c);
if (temp % a == 0 && temp % b == 0 && temp % c == 0) res += n / temp, assert(temp >= 0);
cout << res << '\n';
}
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int dt;
cin >> dt;
while (dt --)
solve();
return 0;
}