#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); // round +inf template inline INT div_p(INT x,INT y){ return (x<0?x/y:(x+y-1)/y); } // round -inf template inline INT div_n(INT x,INT y){ return (x>0?x/y:(x-y+1)/y); } 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; ll g=gcd(b,c); ll j,k; ll u=b/g,v=c/g; ll gg=extgcd(u,v,j,k); for(ll i=0;i<=y;i+=a){ ll t=y-i; if(t%g) continue; t/=g; ll w=t/gg; // t=g*w // g=j*u+k*v; ll jj=j*w,kk=k*w; // j=j' + x * v // k=k' - x * u jj*=-1; ll dw=div_p(jj,v); ll up=div_n(kk,u); // cout<=mod) res%=mod; } cout<>q; while(q--) solve(); return 0; }