#include<stdio.h>
#include<stdlib.h>
#include<math.h>
 
int main(){
  int t,i,j;
  scanf("%d",&t);
  long int a[t],b[t],c[t],d[t];
  int s[t];
  
  for(i=0;i<t;i++){
    scanf("%ld %ld %ld %ld",&a[i],&b[i],&c[i],&d[i]);
    s[i]=0;
  }
  
  for(i=0;i<t;i++){
    
    if(d[i]>b[i]){
      
      if( (b[i]-a[i]%b[i])%(d[i]-b[i])!=0  )
        j=(b[i]-a[i]%b[i])/(d[i]-b[i]);
      
      else if((b[i]-a[i]%b[i])%(d[i]-b[i])==0)
        j=(b[i]-a[i]%b[i])/(d[i]-b[i])-1;
      
      if(a[i]%b[i]+j*(d[i]-b[i])>c[i])
        s[i]=1;