//#pragma GCC optimize(2,3,"Ofast","inline")
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pii pair<int,int>
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define sz(s) ((int)s.size())
#define lowbit(x) (x&-x)
#define endl "\n"
using namespace std;
void inline solve(int C);
signed main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
srand(time(0));
int T=1,C=0;
//cin >> C;
cin >> T;
while(T--) solve(C);
return 0;
}
int n,a,b,c;
__int128 gcd(__int128 x,__int128 y){
return __gcd(x,y);
}
__int128 lcm(__int128 x,__int128 y){
int z=gcd(x,y);
return x/z*y;
}
void inline solve(int C){
cin >> n >> a >> b >> c;
__int128 _n=n,_a=a,_b=b,_c=c;
int ans=_n/_a+_n/_c-_n/lcm(_a,_c)-(_n/lcm(_a,_b)-_n/lcm(_a,lcm(_b,_c)));
cout << ans << endl;
}