#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int T; ll A[3]; ll Y; const ll mo=1000000007; ll ext_gcd(ll p,ll q,ll& x, ll& y) { // get px+qy=gcd(p,q) if(q==0) return x=1,y=0,p; ll g=ext_gcd(q,p%q,y,x); y-=p/q*x; return g; } void solve() { int i,j,k,l,r,x,y; string s; cin>>T; while(T--) { cin>>A[0]>>A[1]>>A[2]>>Y; sort(A,A+3); ll ret=0; for(i=0;A[2]*i<=Y;i++) { ll a=A[0]; ll b=A[1]; ll x,y; ll c=Y-i*A[2]; ll g=ext_gcd(a,b,x,y); if(c%g) continue; ll lca=a*b/g; ll c2=c%lca; x*=c2/g; y*=c2/g; if(x<0) { ll v=(-x+(b/g)-1)/(b/g); x+=v*(b/g); c2+=a*v*(b/g); } if(y<0) { ll v=(-y+(a/g)-1)/(a/g); y+=v*(a/g); c2+=b*v*(a/g); } c2-=(x/(b/g))*lca; c2-=(y/(a/g))*lca; if(c>=c2) { ret+=(c-c2)/lca+1; ret%=mo; } } cout<