#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define fi first
#define se second
using namespace std;
const int N=2e5+10;
const int inf=0x3f3f3f3f3f3f3f3f;
int t,n,a,b,c;
int ans;
__int128 lcm(__int128 a,__int128 b)
{
return a/__gcd(a,b)*b;
}
signed main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin>>t;
while(t--)
{
ans=0;
cin>>n>>a>>b>>c;
ans-=n/lcm(a,b);
ans-=n/lcm(a,c);
ans+=n/a;
ans+=n/c;
ans+=n/lcm(lcm(a,b),c);
cout<<ans<<endl;
}
return 0;
}