#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; } inline long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a%b, y, x); y -= a/b * x; 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=(-j+v-1)/v; ll up=k/u; // cout<=mod) res-=mod; } cout<>q; while(q--) solve(); return 0; }