#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } template< typename T > inline T extgcd(T a, T b, T &x, T &y) { T d = a; if(b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } vector ve(3); inline void solve(){ cin>>ve; ll y;cin>>y; sort(ALL(ve)); ll a,b,c; a=ve[2],b=ve[1],c=ve[0]; ll res=0; for(ll i=0;i<=y;i+=a){ ll t=y-i; // t=j*b+k*cの解の個数 ll g=gcd(b,c); if(t%g) continue; ll j,k; t/=g; ll u=b/g,v=c/g; // t=j*u+k*vの解の個数 g=extgcd(u,v,j,k); ll w=t/g; // t=g*w // g=j*u+k*v; j*=w,k*=w; // j=j' + x * v // k=k' - x * u ll dw=ll(ceil((-j+0.0)/(v+0.0))); ll up=ll(floor((k+0.0)/(u+0.0))); // cout<=mod) res-=mod; } cout<>q; while(q--) solve(); return 0; }