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: Time Limit Exceeded)

// ternary operation
#[allow(unused_macros)]
macro_rules! _if {
  ($_test:expr, $_then:expr, $_else:expr) => {
    if $_test { $_then } else { $_else }
  };
  ($_test:expr, $_pat:pat, $_then:expr, $_else:expr) => {
    match $_test {
      $_pat => $_then,
      _     => $_else
    }
  };
}

use std::io::{ stdin, BufReader };

fn agc026_a() {
  let stdin = stdin();
  let mut reader = my::ByteReader::with_capacity(8, BufReader::new(stdin.lock()));

  let t: usize = reader.read_uint_until_lf();
  let vec = reader.read_int_vec2::<i64>(t, 4);

  for x in vec {
    if x[0] < x[1] {
      println!("No");
      continue;
    }

    let mut n = x[0];
    let mut save = Vec::new();
    save.push(n);
    loop {
      n %= x[1];
      if n <= x[2] {
        n += x[3];
      }
      if n < x[1] {
        println!("No");
        break;
      }

      if save.contains(&n) {
        println!("Yes");
        break;
      }
      save.push(n);
    }
  }
}

fn main() {
  agc026_a();
}

//------------------------------------------------------------------------
mod my {
  #[allow(dead_code)]
  pub fn to_ascii_lowercase(mut b: u8) -> u8 {
    if b >= b'A' && b <= b'Z' {
      b += 0x20;
    }
    b
  }

  #[allow(dead_code)]
  pub fn to_ascii_uppercase(mut b: u8) -> u8 {
    if b >= b'a' && b <= b'z' {
      b -= 0x20;
    }
    b
  }

  #[allow(dead_code)]
  pub fn is_ascii_alphabetic(b: u8) -> bool {
    if b >= b'A' && b <= b'A' || b >= b'a' && b <= b'z' {
      return true;
    }
    false
  }

  //----------------------------------------------------------------------
  macro_rules! impl_Int2Byte_from_ty {
    (uint, $($name:ident => $_type:ty),*) => {$(
      #[allow(dead_code)]
      pub fn $name(&mut self, mut i: $_type) -> &[u8] {
        self.buf.clear();
        if i == 0 {
          self.buf.push(b'0');
          return self.buf.as_slice();
        }

        while i > 0 {
          self.buf.push((i % 10) as u8 + b'0');
          i /= 10;
        }
        self.buf.reverse();
        self.buf.as_slice()
      }
    )*};

    (int, $($name:ident => $_type:ty),*) => {$(
      #[allow(dead_code)]
      pub fn $name(&mut self, mut i: $_type) -> &[u8] {
        self.buf.clear();
        if i == 0 {
          self.buf.push(b'0');
          return self.buf.as_slice();
        }

        let mut negative = false;
        if i.is_negative() {
          negative = true;
          i = i.abs();
        }

        while i > 0 {
          self.buf.push((i % 10) as u8 + b'0');
          i /= 10;
        }
        if negative {
          self.buf.push(b'-');
        }
        self.buf.reverse();
        self.buf.as_slice()
      }
    )*};
  }

  #[derive(Debug)]
  pub struct Int2Byte {
    buf : Vec<u8>,
  }

  impl Int2Byte {
    #[allow(dead_code)]
    pub fn new() -> Self {
      Int2Byte {
        buf : Vec::new(),
      }
    }

    #[allow(dead_code)]
    pub fn with_capacity(capa: usize) -> Self {
      Int2Byte {
        buf : Vec::with_capacity(capa),
      }
    }

    impl_Int2Byte_from_ty!(
      uint,
      from_usize => usize,
      from_u8    => u8,
      from_u16   => u16,
      from_u32   => u32,
      from_u64   => u64
    );

    impl_Int2Byte_from_ty!(
      int,
      from_isize => isize,
      from_i8    => i8,
      from_i16   => i16,
      from_i32   => i32,
      from_i64   => i64
    );
  }

  //----------------------------------------------------------------------
  use std::io::{ BufRead, BufWriter, Write };
  use std::fmt::Debug;
  use std::ops::{ Add, Sub, Mul, Neg };
  use std::str::{ self, FromStr };

  pub trait WriteWithDelim {
    fn write_delim(&mut self, buf: &[u8], delim: &[u8]) -> usize;
    fn write_sp(&mut self, buf: &[u8]) -> usize;
    fn write_lf(&mut self, buf: &[u8]) -> usize;
  }

  impl<W> WriteWithDelim for BufWriter<W>
    where W: Write
  {
    #[allow(dead_code)]
    fn write_delim(&mut self, buf: &[u8], delim: &[u8]) -> usize
    {
      self.write(buf).unwrap() +
      self.write(delim).unwrap()
    }

    #[allow(dead_code)]
    fn write_sp(&mut self, buf: &[u8]) -> usize
    {
      self.write_delim(buf, b" ")
    }

    #[allow(dead_code)]
    fn write_lf(&mut self, buf: &[u8]) -> usize
    {
      self.write_delim(buf, b"\n")
    }
  }

  //----------------------------------------------------------------------
  const SP: u8 = b' ';
  const LF: u8 = b'\n';

  #[allow(dead_code)]
  #[derive(Debug)]
  pub enum Direction {
    Horizontal,
    Vertical
  }

  #[derive(Debug)]
  pub struct ByteReader<R> {
    reader : R,
    buf    : Vec<u8>,
  }

  impl<R> ByteReader<R>
    where R: BufRead
  {
    #[allow(dead_code)]
    pub fn new(reader: R) -> Self {
      ByteReader {
        reader : reader,
        buf    : Vec::new(),
      }
    }

    #[allow(dead_code)]
    pub fn with_capacity(capa: usize, reader: R) -> Self {
      ByteReader {
        reader : reader,
        buf    : Vec::with_capacity(capa),
      }
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    pub fn read_1byte(&mut self) -> Option<u8> {
      self.buf.resize(1, 0);
      _if!(self.reader.read(&mut self.buf).unwrap() != 0,
        Some(self.buf[0]),
        None)
    }

    //--------------------------------------------------------------------
    fn read_until(&mut self, delim: u8) -> usize {
      self.buf.clear();
      self.reader.read_until(delim, &mut self.buf).unwrap()
    }

    #[allow(dead_code)]
    pub fn read_until_lf(&mut self) -> &[u8] {
      self.read_until(LF);
      self.buf.as_slice()
    }

    #[allow(dead_code)]
    pub fn read_until_lf_clone(&mut self) -> Vec<u8> {
      self.read_until(LF);
      let len = self.buf.len() - 1;
      if self.buf[len] == LF {
        self.buf.truncate(len);
      }
      self.buf.clone()
    }

    #[allow(dead_code)]
    pub fn read_until_sp(&mut self) -> &[u8] {
      self.read_until(SP);
      self.buf.as_slice()
    }

    //--------------------------------------------------------------------
    fn parse_int<T>(&self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let len = self.buf.len();
      let mut i = 0;
      let mut n = T::default();
      let mut minus = false;

      if self.buf[i] == b'-' {
        minus = true;
        i += 1;
      } else if self.buf[i] == b'+' {
        i += 1;
      }

      while i < len && b'0' <= self.buf[i] && self.buf[i] <= b'9' {
        n = (n * T::from(10)) + T::from(self.buf[i] - b'0');
        i += 1;
      }

      _if!(minus,
        n.neg(),
        n)
    }

    fn parse_uint<T>(&self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let len = self.buf.len();
      let mut i = 0;
      let mut n = T::default();

      if self.buf[i] == b'+' {
        i += 1;
      }

      while i < len && b'0' <= self.buf[i] && self.buf[i] <= b'9' {
        n = (n * T::from(10)) + T::from(self.buf[i] - b'0');
        i += 1;
      }
      n
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    pub fn read_int_until_delim<T>(&mut self, delim: u8) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_until(delim);
      self.parse_int()
    }

    // s -> n
    #[allow(dead_code)]
    pub fn read_int_until_lf<T>(&mut self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_int_until_delim(LF)
    }

    // s -> n
    #[allow(dead_code)]
    pub fn read_int_until_sp<T>(&mut self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_int_until_delim(SP)
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    pub fn read_uint_until_delim<T>(&mut self, delim: u8) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_until(delim);
      self.parse_uint()
    }

    // s -> n
    #[allow(dead_code)]
    pub fn read_uint_until_lf<T>(&mut self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_uint_until_delim(LF)
    }

    // s -> n
    #[allow(dead_code)]
    pub fn read_uint_until_sp<T>(&mut self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_uint_until_delim(SP)
    }

    //--------------------------------------------------------------------

    fn from_utf8_unchecked(&mut self) -> &str {
      unsafe { str::from_utf8_unchecked(&self.buf) }
    }

    fn parse_tok<T>(&mut self) -> T
      where T: FromStr + Debug,
            <T as FromStr>::Err: Debug
    {
      self.from_utf8_unchecked()
        .trim()
        .parse()
        .unwrap()
    }

    // s -> n
    #[allow(dead_code)]
    pub fn parse_until_delim<T>(&mut self, delim: u8) -> T
      where T: FromStr + Debug,
            <T as FromStr>::Err: Debug
    {
      self.read_until(delim);
      self.parse_tok()
    }

    // s -> n
    #[allow(dead_code)]
    pub fn parse_until_lf<T>(&mut self) -> T
      where T: FromStr + Debug,
            <T as FromStr>::Err: Debug
    {
      self.parse_until_delim(LF)
    }

    // s -> n
    #[allow(dead_code)]
    pub fn parse_until_sp<T>(&mut self) -> T
      where T: FromStr + Debug,
            <T as FromStr>::Err: Debug
    {
      self.parse_until_delim(SP)
    }

    //--------------------------------------------------------------------
    #[allow(dead_code)]
    pub fn read_int_vec<T>(&mut self, n: usize, dir: Direction) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let delim = _if!(dir, Direction::Horizontal, SP, LF);
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n - 1 {
        vec.push(self.read_int_until_delim(delim));
      }
      vec.push(self.read_int_until_delim(LF));
      vec
    }

    #[allow(dead_code)]
    pub fn read_uint_vec<T>(&mut self, n: usize, dir: Direction) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let delim = _if!(dir, Direction::Horizontal, SP, LF);
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n - 1 {
        vec.push(self.read_uint_until_delim(delim));
      }
      vec.push(self.read_uint_until_delim(LF));
      vec
    }

    // horizontal
    //
    // N
    // s1 s2 s3, ..., sN -> [n1, n2, n3, ..., nN]
    #[allow(dead_code)]
    pub fn read_int_vec_h<T>(&mut self) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let n: usize = self.read_uint_until_lf();
      self.read_int_vec(n, Direction::Horizontal)
    }

    // horizontal
    //
    // N
    // s1 s2 s3, ..., sN -> [n1, n2, n3, ..., nN]
    #[allow(dead_code)]
    pub fn read_uint_vec_h<T>(&mut self) -> Vec<T>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let n: usize = self.read_uint_until_lf();
      self.read_uint_vec(n, Direction::Horizontal)
    }

    #[allow(dead_code)]
    pub fn read_uint_vec2<T>(&mut self, n: usize, m: usize) -> Vec<Vec<T>>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n {
        vec.push(self.read_uint_vec(m, Direction::Horizontal));
      }
      vec
    }

    #[allow(dead_code)]
    pub fn read_int_vec2<T>(&mut self, n: usize, m: usize) -> Vec<Vec<T>>
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let mut vec = Vec::with_capacity(n);
      for _ in 0..n {
        vec.push(self.read_int_vec(m, Direction::Horizontal));
      }
      vec
    }

  } // impl<R> ByteReader<R>

} // mod my