Problem:
Score : 600 points

Problem Statement

Ringo Mart, a convenience store, sells apple juice.

On the opening day of Ringo Mart, there were A cans of juice in stock in the morning.
Snuke buys B cans of juice here every day in the daytime.
Then, the manager checks the number of cans of juice remaining in stock every night.
If there are C or less cans, D new cans will be added to the stock by the next morning.

Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them.
Nobody besides Snuke buy juice at this store.

Note that each test case in this problem consists of T queries.

Constraints

1 \leq T \leq 300

1 \leq A, B, C, D \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T

In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.

Output

Print T lines. The i-th line should contain Yes if Snuke can buy apple juice indefinitely in the i-th query; No otherwise.

Sample Input 1

14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985

Sample Output 1

No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes

In the first query, the number of cans of juice in stock changes as follows: (D represents daytime and N represents night.)

9
→D 2
→N 11
→D 4
→N 13
→D 6
→N 6
→D x

In the second query, the number of cans of juice in stock changes as follows:

9
→D 2
→N 11
→D 4
→N 13
→D 6
→N 15
→D 8
→N 8
→D 1
→N 10
→D 3
→N 12
→D 5
→N 14
→D 7
→N 7
→D 0
→N 9
→D 2
→N 11
→D …

and so on, thus Snuke can buy juice indefinitely.

Sample Input 2

24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1

Sample Output 2

No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

fn solve<R: BufRead, W: Write>(_reader: R, _writer: &mut W) {
  let mut _scanner = Scanner::new(_reader);

  #[allow(unused_macros)]
  macro_rules! scan {
    ($t:ty) => {
      _scanner.next::<$t>().unwrap()
    };
    ($($t:ty),+) => {
      ($(scan!($t)),+)
    };
    ($t:ty; $n:expr $(; $m:expr)*) => {{
      let mut vec = Vec::with_capacity($n);
      for _ in 0..$n {
        vec.push(scan!($t $(; $m)*));
      }
      vec
    }};
    ($t_0:ty, $t_1:ty; $n:expr) => {
      scan!($t_0 = 0, $t_1 = 1; $n)
    };
    ($t_0:ty, $t_1:ty, $t_2:ty; $n:expr) => {
      scan!($t_0 = 0, $t_1 = 1, $t_2 = 2; $n)
    };
    ($($t:ty = $i:tt),+; $n:expr) => {{
      let mut vecs = ($(Vec::<$t>::with_capacity($n)),+);
      for _ in 0..$n {$(
        vecs.$i.push(scan!($t));
      )+}
      vecs
    }};
  }

  #[allow(unused_macros)]
  macro_rules! scan_iter {
    ($t:ty; $n:expr) => {
      _scanner.take::<$t>($n).map(|x| x.unwrap())
    };
  }

  #[allow(unused_macros)]
  macro_rules! print {
    ($fmt:expr) => {
      write!(_writer, $fmt).unwrap()
    };
    ($fmt:expr, $($arg:tt)*) => {
      write!(_writer, $fmt, $($arg)*).unwrap()
    };
  }

  #[allow(unused_macros)]
  macro_rules! println {
    () => {
      writeln!(_writer).unwrap()
    };
    ($fmt:expr) => {
      writeln!(_writer, $fmt).unwrap()
    };
    ($fmt:expr, $($arg:tt)*) => {
      writeln!(_writer, $fmt, $($arg)*).unwrap()
    };
  }

  #[allow(unused_macros)]
  macro_rules! eprint {
    ($fmt:expr) => {
      #[cfg(debug_assertions)]
      write!(::std::io::stderr(), $fmt).unwrap()
    };
    ($fmt:expr, $($arg:tt)*) => {
      #[cfg(debug_assertions)]
      write!(::std::io::stderr(), $fmt, $($arg)*).unwrap()
    };
  }

  #[allow(unused_macros)]
  macro_rules! eprintln {
    () => {
      #[cfg(debug_assertions)]
      writeln!(::std::io::stderr()).unwrap()
    };
    ($fmt:expr) => {
      #[cfg(debug_assertions)]
      writeln!(::std::io::stderr(), $fmt).unwrap()
    };
    ($fmt:expr, $($arg:tt)*) => {
      #[cfg(debug_assertions)]
      writeln!(::std::io::stderr(), $fmt, $($arg)*).unwrap()
    };
  }

  #[allow(unused_macros)]
  macro_rules! dump {
    ($($x:expr),+) => {
      eprint!("[{}:{}] ", file!(), line!());
      eprintln!(concat!($(stringify!($x), " = {:?}; "),+), $($x),+);
    };
  }

  use search::BinarySearch;
  use std::i64;

  macro_rules! no_if_not {
    ($cond:expr) => {
      if !$cond {
        println!("No");
        continue;
      }
    };
  }

  macro_rules! yes_if {
    ($cond:expr) => {
      if $cond {
        println!("Yes");
        continue;
      }
    };
  }

  let full_range = 0..i64::MAX / 2;

  let t = scan!(usize);
  for _ in 0..t {
    let (a, b, c, d) = scan!(i64, i64, i64, i64);
    dump!(a, b, c, d);
    no_if_not!(d >= b);

    let a = if a <= c {
      no_if_not!(a - b >= 0);
      yes_if!(d == b);
      let i = full_range.binary_search(|&i| a.saturating_add((d - b).saturating_mul(i)) > c).unwrap();
      a + (d - b) * i
    } else {
      let i = full_range.binary_search(|&i| a - b.saturating_mul(i) <= c).unwrap() - 1;
      a - b * i
    };
    let t = a - b;
    dump!(a, t);
    no_if_not!(t >= 0);

    yes_if!(d == b);
    let i = full_range.binary_search(|&i| t.saturating_add((d - b).saturating_mul(i)) > c).unwrap();
    let u = t + (d - b) * i;
    let j = full_range.binary_search(|&i| u - b.saturating_mul(i) <= c).unwrap() - 1;
    let u = u - b * j;
    dump!(u);
    yes_if!(u >= a);

    let i = full_range.binary_search(|&i| u + (u - a).saturating_mul(i) <= c).unwrap() - 1;
    let v = u + (u - a) * i;
    dump!(v);
    yes_if!(v - b >= 0);

    println!("No");
  }
}

const STACK_SIZE_MEBIBYTES: Option<usize> = None;

fn main() {
  fn run_solver() {
    let stdin = stdin();
    let stdout = stdout();
    #[cfg(debug_assertions)]
    let mut writer = stdout.lock();
    #[cfg(not(debug_assertions))]
    let mut writer = ::std::io::BufWriter::new(stdout.lock());
    solve(stdin.lock(), &mut writer);
    writer.flush().unwrap();
  }
  if let Some(size) = STACK_SIZE_MEBIBYTES {
    let builder = ::std::thread::Builder::new().stack_size(size * 1024 * 1024);
    builder.spawn(run_solver).unwrap().join().unwrap();
  } else {
    run_solver();
  }
}

use io::Scanner;
use std::io::{stdin, stdout, BufRead, Write};

pub mod io {
  pub use self::scanner::*;

  mod scanner {
    use std::io::BufRead;
    use std::marker::PhantomData;
    use std::str::{from_utf8, from_utf8_unchecked, FromStr};

    pub struct Scanner<R> {
      reader: R,
      buffer: Vec<u8>,
      position: usize,
    }

    impl<R: BufRead> Scanner<R> {
      pub fn new(reader: R) -> Self {
        Scanner { reader: reader, buffer: vec![], position: 0 }
      }

      pub fn next<T: Parse>(&mut self) -> Option<T> {
        Parse::parse(self.next_bytes().unwrap_or(&[]))
      }

      pub fn take<T: Parse>(&mut self, n: usize) -> Take<R, T> {
        Take { scanner: self, n: n, _marker: PhantomData }
      }

      pub fn next_bytes(&mut self) -> Option<&[u8]> {
        if self.buffer.is_empty() {
          self.read_line();
        }
        loop {
          match self.buffer.get(self.position) {
            Some(&b' ') => self.position += 1,
            Some(&b'\n') => self.read_line(),
            Some(_) => break,
            None => return None,
          }
        }
        let start = self.position;
        loop {
          match self.buffer.get(self.position) {
            Some(&b' ') | Some(&b'\n') | None => break,
            Some(_) => self.position += 1,
          }
        }
        Some(&self.buffer[start..self.position])
      }

      fn read_line(&mut self) {
        self.position = 0;
        self.buffer.clear();
        self.reader.read_until(b'\n', &mut self.buffer).unwrap();
      }
    }

    pub struct Take<'a, R: 'a, T> {
      scanner: &'a mut Scanner<R>,
      n: usize,
      _marker: PhantomData<fn() -> T>,
    }

    impl<'a, R: BufRead, T: Parse> Iterator for Take<'a, R, T> {
      type Item = Option<T>;

      fn next(&mut self) -> Option<Self::Item> {
        if self.n > 0 {
          self.n -= 1;
          Some(self.scanner.next())
        } else {
          None
        }
      }

      fn size_hint(&self) -> (usize, Option<usize>) {
        (self.n, Some(self.n))
      }
    }

    impl<'a, R: BufRead, T: Parse> ExactSizeIterator for Take<'a, R, T> {}

    pub trait Parse: Sized {
      fn parse(bytes: &[u8]) -> Option<Self>;
    }

    impl Parse for u8 {
      fn parse(bytes: &[u8]) -> Option<Self> {
        if bytes.len() == 1 {
          Some(*unsafe { bytes.get_unchecked(0) })
        } else {
          None
        }
      }
    }

    macro_rules! parse_impl {
      ($($t:ty)+) => {$(
        impl Parse for $t {
          fn parse(bytes: &[u8]) -> Option<Self> {
            let s = if cfg!(debug_assertions) { from_utf8(bytes).unwrap() } else { unsafe { from_utf8_unchecked(bytes) } };
            <$t>::from_str(s).ok()
          }
        }
      )+};
    }

    parse_impl! { i32 i64 isize u32 u64 usize f64 String }
  }
}

pub mod search {
  pub use self::binary_search::*;

  mod binary_search {
    use std::ops::Range;

    pub trait BinarySearch<T> {
      type Output;

      fn binary_search<F: FnMut(&T) -> bool>(&self, f: F) -> Option<Self::Output>;

      fn lower_bound(&self, x: &T) -> Option<Self::Output>
      where
        T: Ord,
      {
        self.binary_search(|t| t >= x)
      }

      fn upper_bound(&self, x: &T) -> Option<Self::Output>
      where
        T: Ord,
      {
        self.binary_search(|t| t > x)
      }
    }

    macro_rules! binary_search_impl {
      ($ok:expr, $ng:expr, $cond1:expr, $cond2:expr) => {{
        let mut ok_end = $ok;
        let mut ng_start = $ng;
        while ok_end - ng_start > 1 {
          let mid = ng_start + (ok_end - ng_start) / 2;
          if $cond1(mid) {
            ok_end = mid;
          } else {
            ng_start = mid;
          }
        }
        if $cond2(ok_end) {
          None
        } else {
          Some(ok_end as Self::Output)
        }
      }};
    }

    impl<T> BinarySearch<T> for [T] {
      type Output = usize;

      fn binary_search<F: FnMut(&T) -> bool>(&self, mut f: F) -> Option<Self::Output> {
        binary_search_impl!(self.len() as isize, -1isize, |mid| f(&self[mid as usize]), |ok_end| ok_end as usize == self.len())
      }
    }

    macro_rules! binary_search_impl_range {
      ($t:ty, $it:ty) => {
        impl BinarySearch<$t> for Range<$t> {
          type Output = $t;

          fn binary_search<F: FnMut(&$t) -> bool>(&self, mut f: F) -> Option<$t> {
            assert!(self.start <= self.end);
            binary_search_impl!(self.end as $it, self.start as $it - 1, |mid| f(&(mid as $t)), |ok_end| ok_end == self.end as $it)
          }
        }
      };
      ($($ut:ty, $it:ty);+) => {$(
        binary_search_impl_range! { $ut, $it }
        binary_search_impl_range! { $it, $it }
      )+};
    }

    binary_search_impl_range! { usize, isize; u32, i32; u64, i64 }
  }
}