#include #include using namespace atcoder; using namespace std; using ll = long long; using mint = modint1000000007; 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; } int main(){ int t = 1; cin >> t; while(t--){ ll N,K,H,Y; cin >> N >> K >> H >> Y; vector A={N,K,H}; sort(A.begin(),A.end(),greater<>()); ll x,y; mint ans = 0; for(ll i = 0;i*A[0]<=Y;i++){ if(i*A[0]==Y){ans++;continue;} ll gcd = extGCD(A[1],A[2],x,y); if((Y-i*A[0])%gcd!=0)continue; x *= (Y-i*A[0])/gcd;y *= (Y-i*A[0])/gcd; //X = x + A2 * t; //Y = y - A1 * t; ll A1 = A[1]/gcd,A2 = A[2]/gcd; ll X = -x/A2,Y = y/A1; //while(x+A2*X<0)X++; ll l = INT_MIN,r= INT_MAX; while(r-l>1){ ll m = (l+r)/2; if(y-A1*m<0)r = m; else l = m; } //cout<