/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

void myAssert()
{
    int cnt = 0;
    while (1)
    {
        cnt += 1;
    }
}

bool go(int a, int n, int p, int h)
{
    if (h == 0) return false;
    if (a == 0) myAssert();
    if (a * 2 > p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return p - n * a <= h;
    if (a == 1) return true;
    int a1 = p % a;
    int T = n / (p / a) - 1;
    int n1 = ((T + 1) * (ll)a - 1) / (a + a1);
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        bool res = go(a % p, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

void myAssert()
{
    int cnt = 0;
    while (1)
    {
        cnt += 1;
    }
}

bool go(int a, int n, int p, int h)
{
    if (h == 0) return false;
    if (a == 0) myAssert();
    //if (a * 2 > p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return p - n * a <= h;
    if (a == 1) return true;
    int a1 = p % a;
    int T = n / (p / a) - 1;
    int n1 = ((T + 1) * (ll)a - 1) / (a + a1);
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        a = a % p;
        bool res;
        if (n < p / a) res = a <= h;
        else res = go(a % p, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

void myAssert()
{
    int cnt = 0;
    while (1)
    {
        cnt += 1;
    }
}

bool go(int a, int n, int p, int h)
{
    eprintf("go %d %d %d %d\n", a, n, p, h);
    if (h == 0) return false;
    if (a == 0) myAssert();
    if (a * 2 > p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return p - n * a <= h;
    if (a == 1) return true;
    int a1 = p % a;
    int n1 = ((n + 1) * (ll)a - p + a1 - 1) / p;
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        a = a % p;
        bool res;
        if (n < p / a) res = a <= h;
        else res = go(a % p, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

void myAssert()
{
    int cnt = 0;
    while (1)
    {
        cnt += 1;
    }
}

bool go(int a, int n, int p, int h)
{
    if (a == 0) myAssert();
    //if (a * 2 > p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return p - n * a <= h;
    int a1 = p % a;
    int T = n / (p / a) - 1;
    int n1 = ((T + 1) * (ll)a - 1) / (a + a1);
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        bool res = go(a, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

void myAssert()
{
    int cnt = 0;
    while (1)
    {
        cnt += 1;
    }
}

bool go(int a, int n, int p, int h)
{
    if (h == 0) return false;
    if (a == 0) myAssert();
    //if (a * 2 > p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return a <= h;
    if (a == 1) return true;
    int a1 = p % a;
    int T = n / (p / a) - 1;
    int n1 = ((T + 1) * (ll)a - 1) / (a + a1);
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        bool res = go(a % p, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

void myAssert()
{
    int cnt = 0;
    while (1)
    {
        cnt += 1;
    }
}

bool go(int a, int n, int p, int h)
{
    if (h == 0) return false;
    //if (a == 0) myAssert();
    if (a * 2 > p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return p - n * a <= h;
    int a1 = p % a;
    int T = n / (p / a) - 1;
    int n1 = ((T + 1) * (ll)a - 1) / (a + a1);
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        bool res = go(a, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

void myAssert()
{
    int cnt = 0;
    while (1)
    {
        cnt += 1;
    }
}

bool go(int a, int n, int p, int h)
{
    if (h == 0) return false;
    if (a == 0) myAssert();
    if (a * 2 > p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return p - n * a <= h;
    if (a == 1) return true;
    int a1 = p % a;
    int T = n / (p / a) - 1;
    int n1 = ((T + 1) * (ll)a - 1) / (a + a1);
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        bool res = go(a, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

void myAssert()
{
    int cnt = 0;
    while (1)
    {
        cnt += 1;
    }
}

bool go(int a, int n, int p, int h)
{
    if (h == 0) return false;
    //if (a == 0) myAssert();
    //if (a * 2 > p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return p - n * a <= h;
    int a1 = p % a;
    int T = n / (p / a) - 1;
    int n1 = ((T + 1) * (ll)a - 1) / (a + a1);
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        bool res = go(a, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

bool go(int a, int n, int p, int h)
{
    if (h == 0) return false;
    if (a * 2 < p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return p - n * a <= h;
    if (a == 1) return true;
    int a1 = p % a;
    int n1 = ((n + 1) * (ll)a - p + a1 - 1) / p;
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        a = a % p;
        bool res;
        if (n < p / a) res = a <= h;
        else res = go(a % p, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

bool go(int a, int n, int p, int h)
{
    //if (a * 2 > p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return p - n * a <= h;
    int a1 = p % a;
    int T = n / (p / a) - 1;
    int n1 = ((T + 1) * (ll)a - 1) / (a + a1);
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        bool res = go(a, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

void myAssert()
{
    int cnt = 0;
    while (1)
    {
        cnt += 1;
    }
}

bool go(int a, int n, int p, int h)
{
    if (h == 0) return false;
    if (a == 0) myAssert();
    //if (a * 2 > p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return p - n * a <= h;
    if (a == 1) return true;
    int a1 = p % a;
    int n1 = ((n + 1) * (ll)a - p + a1 - 1) / p;
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        a = a % p;
        bool res;
        if (n < p / a) res = a <= h;
        else res = go(a % p, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

void myAssert()
{
    int cnt = 0;
    while (1)
    {
        cnt += 1;
    }
}

bool go(int a, int n, int p, int h)
{
    if (h == 0) return false;
    if (a == 0) myAssert();
    if (a * 2 > p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return p - n * a <= h;
    if (a == 1) return true;
    int a1 = p % a;
    int n1 = ((n + 1) * (ll)a - p + a1 - 1) / p;
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        a = a % p;
        bool res;
        if (n < p / a) res = a <= h;
        else res = go(a % p, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


/**
 *    author:  enot.1.10, Vladimir Smykalov (enot.1.10@gmail.com)
 *    created: 24.07.2015 16:13:05
**/
#include <bits/stdc++.h>

#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)

using namespace std;

typedef long long ll;
typedef double dbl;

const int inf = (int)1.01e9;
const dbl eps = 1e-9;

/** --- main part --- **/

#define TASK "a"

bool go(int a, int n, int p, int h)
{
    if (h == 0) return false;
    if (a * 2 > p) return go(p - a, n, p, h);
    if (p <= h) return true;
    if (n < p / a) return p - n * a <= h;
    if (a == 1) return true;
    int a1 = p % a;
    int n1 = ((n + 1) * (ll)a - p + a1 - 1) / p;
    return go(a1, n1, a, h);
}

int main()
{
    #ifdef home
        assert(freopen(TASK".in", "r", stdin));
        assert(freopen(TASK".out", "w", stdout));
    #endif
    int tn;
    scanf("%d", &tn);
    forn(tt, tn)
    {
        int a, n, p, h;
        scanf("%d%d%d%d", &a, &n, &p, &h);
        a = a % p;
        bool res;
        if (n < p / a) res = a <= h;
        else res = go(a % p, n, p, h);
        if (res) printf("YES\n");
        else printf("NO\n");
    }
    #ifdef home
        eprintf("Time: %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
LL work(LL a,LL n,LL p){
	if(a*n<p) return max(a,p-a*n);
	LL cnt=a*n/p;
	if(a*n%p<a*(p/a-1)) cnt--;
	return work(min(p%a,a-p%a),cnt,a);
}
int main(){
	int T;
	cin>>T;
	LL a,n,p,h,ans;
	while(T--){
		cin>>a>>n>>p>>h;
		a%=p;
		if(a*n<p) ans=a;
		else ans=work(a,n,p);
		if(ans>h) printf("NO\n");
		else printf("YES\n");
	}
	return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#define pb push_back
#define rep(i,j,k) for(int i=(j);i<=(int)k;i++)
#define per(i,j,k) for(int i=(j);i>=(int)k;i--)
#define lowbit(x) ((x)&(-(x)))
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
typedef long long LL;
typedef double db;
typedef set<int>::iterator it;
bool flag=0;
int work(int a,int n,int p){
	int t=a*1ll*n/p;
	if(!t){
		if(!flag)return a;
		return max(a,p-a*n);
	}
	flag=1;
	int a1,n1,p1;a1=min(p%a,a-(p%a));
	n1=t;p1=a;
	if(a*1ll*n%p<a*1ll*(p/a-1))n1--;
	return work(a1,n1,p1);
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int a,n,p,h;scanf("%d%d%d%d",&a,&n,&p,&h);
		flag=0;
		if(work(a%p,n,p)<=h)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int64;

int64 t, a, n, p, h;

int64 get(int64 a, int64 n, int64 p) {
	if (a > p / 2)	a = p - a;
	if (a * n > p)	return get(p % a, (a * n + p % a) / p, a);
	else	return max(a, p - a * (n - 1));
}

int main() {
	scanf("%I64d", &t);
	while (t--) {
		scanf("%I64d%I64d%I64d%I64d", &a, &n, &p, &h);
		if ((a >= p && h) || ((a * n < p) ? a : get(a % p, n + 1, p)) <= h)	printf("YES\n");
		else	printf("NO\n");
	}
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int64;

int64 t, a, n, p, h;

int64 get(int64 a, int64 n, int64 p) {
	if (a * (n - 1) > p)	return get(p % a, (a * n + p % a) / p, a);
	else	return max(a, p - a * (n - 1));
}

int main() {
	scanf("%I64d", &t);
	while (t--) {
		scanf("%I64d%I64d%I64d%I64d", &a, &n, &p, &h);
		a %= p;
		if (((a * n < p) ? a : get(a % p, n + 1, p)) <= h)	printf("YES\n");
		else	printf("NO\n");
	}
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int64;

int64 t, a, n, p, h;

int64 get(int64 a, int64 n, int64 p) {
	// printf("%I64d %I64d %I64d\n", a, n, p);
	if (a * n > p)	return get(p % a, (a * n + p % a) / p, a);
	else	return max(a, p - a * n);
}

int main() {
	scanf("%I64d", &t);
	while (t--) {
		scanf("%I64d%I64d%I64d%I64d", &a, &n, &p, &h);
		a %= p;
		if (((a * n < p) ? a : get(a % p, n, p)) <= h)	printf("YES\n");
		else	printf("NO\n");
	}
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int64;

int64 t, a, n, p, h;

int64 get(int64 a, int64 n, int64 p) {
	if (a > p / 2)	a = p - a;
	if (a * n > p)	return get(p % a, (a * n + p % a) / p, a);
	else	return max(a, p - a * (n - 1));
}

int main() {
	scanf("%I64d", &t);
	while (t--) {
		scanf("%I64d%I64d%I64d%I64d", &a, &n, &p, &h);
		if (a >= p || ((a * n < p) ? a : get(a % p, n + 1, p)) <= h)	printf("YES\n");
		else	printf("NO\n");
	}
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int64;

int64 t, a, n, p, h;

int64 get(int64 a, int64 n, int64 p) {
	// if (a > p / 2)	a = p - a;
	if (a * n > p)	return get(p % a, (a * n + p % a) / p, a);
	else	return max(a, p - a * (n - 1));
}

int main() {
	scanf("%I64d", &t);
	while (t--) {
		scanf("%I64d%I64d%I64d%I64d", &a, &n, &p, &h);
		a %= p;
		if (((a * n < p) ? a : get(a % p, n + 1, p)) <= h)	printf("YES\n");
		else	printf("NO\n");
	}
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int64;

int64 t, a, n, p, h;

int64 get(int64 a, int64 n, int64 p) {
	if (a > p / 2)	a = p - a;
	if (a * n > p)	return get(p % a, (a * n + p % a) / p, a);
	else	return max(a, p - a * (n - 1));
}

int main() {
	scanf("%I64d", &t);
	while (t--) {
		scanf("%I64d%I64d%I64d%I64d", &a, &n, &p, &h);
		// a %= p;
		if (((a * n < p) ? a : get(a % p, n + 1, p)) <= h)	printf("YES\n");
		else	printf("NO\n");
	}
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int64;

int64 t, a, n, p, h;

int64 get(int64 a, int64 n, int64 p) {
	if (a > p / 2)	a = p - a;
	if (a * n > p)	return get(p % a, (a * n + p % a) / p, a);
	else	return max(a, p - a * (n - 1));
}

int main() {
	scanf("%I64d", &t);
	while (t--) {
		scanf("%I64d%I64d%I64d%I64d", &a, &n, &p, &h);
		a %= p;
		if (((a * n < p) ? a : get(a % p, n + 1, p)) <= h)	printf("YES\n");
		else	printf("NO\n");
	}
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long int64;

int64 t, a, n, p, h;

int64 get(int64 a, int64 n, int64 p) {
	if (a * n > p)	return get(p % a, (a * n + p % a) / p, a);
	else	return max(a, p - a * (n - 1));
}

int main() {
	scanf("%I64d", &t);
	while (t--) {
		scanf("%I64d%I64d%I64d%I64d", &a, &n, &p, &h);
		a %= p;
		if (((a * n < p) ? a : get(a % p, n, p)) <= h)	printf("YES\n");
		else	printf("NO\n");
	}
}


/*
	Time : 0203Z 20140923
	Task : Codeforces 346E
	Tags : Math
	Stat : Coding
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <cmath>

#define fi first
#define se second
#define fo(i,a,b) for (int i = a; i <= b; i ++)
#define fd(i,a,b) for (int i = a; i >= b; i --)
#define fe(i,x,y) for (int i = x, y = lnk[i]; i; i = nxt[i], y = lnk[i])
#define mkp make_pair
#define pb push_back
#define Fill(x,y) memset(x,y,sizeof(x))
#define Cpy(x,y) memcpy(x,y,sizeof(x))
#define Bit(x,y) ((((x) >> (y)) & 1))
#define mit map<int,SI>::iterator
#define sit SI::iterator

using namespace std;

typedef long long LL;
typedef long double DB;
typedef pair <DB, DB> PD;
typedef pair <LL, LL> PLI;
typedef pair <PD, int> PDI;
typedef pair <int, int> PI;
typedef pair <int, PI> PII;
typedef pair <PI, PI> PIII;
typedef set <PI> SI;
typedef vector <int> VI;

int Read()
{
    char c; while (c = getchar(), (c != '-') && (c < '0' || c > '9'));
    bool neg = (c == '-'); int ret = (neg ? 0 : c - 48);
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + c - 48;
    return neg ? -ret : ret;
}

int T, A, N, P, H;

int F(int A, int N, int P)
{
	int T = (LL) A * N / P;
	if (!T) return max(A, P - A * N);
	return F(min(P % A, A - P % A), T - ((LL) A * N % P < (LL) A * (P / A - 1)), A);
}

int main()
{
	for (scanf("%d", &T); T --; )
	{
		scanf("%d%d%d%d", &A, &N, &P, &H), A %= P;
		int ans = (LL) A * N < P ? A : F(A, N, P);
		puts(ans > H ? "NO" : "YES");
	}
	return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
void read(ll&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

ll T,a,n,p,h;

ll get(ll a,ll n,ll p)
{
	if(a>(p/2))a=p-a;

	if(a*n<p)return max(a,p-a*n);

	//cout<< (a*(n+1)+p%a)/p-1<<' '<<a*n/p-1<<endl;
	return get(a-p%a,(a*n)/p,a);
}

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	for(read(T);T;T--)
	{
		read(a);read(n);read(p);read(h);
		a%=p;

		if(a*n<p)printf("%s",a<=h?"YES":"NO");
		else printf("%s",get(a,n,p)<=h?"YES":"NO");
		printf("\n");
	}

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
void read(ll&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

ll T,a,n,p,h;

ll get(ll a,ll n,ll p)
{
	if(a>(p/2))a=p-a;

	if(a*n<p)return max(a,p-a*n);

//	cout<< (a*(n+1)+p%a)/p-1<<' '<<a*n/p-1<<endl;
	return get(a-p%a,a*n/p-(a*n%p>0),a);
}

ll tt[1000];
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	for(read(T);T;T--)
	{
		read(a);read(n);read(p);read(h);
		a%=p;

		if(a*n<p)printf("%s",a<=h?"YES":"NO");
		else printf("%s",get(a,n,p)<=h?"YES":"NO");
		printf("\n");
	}

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
void read(ll&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

ll T,a,n,p,h;

ll get(ll a,ll n,ll p)
{
	if(a>(p/2))a=p-a;

	if(a*n<p)return max(a,p-a*n);

	ll t;
	if(a*(n+1)/p>a*n/p)t=a*(n+1)/p-1;
	else t=a*n/p-1;

	return get(a-p%a,t,a);
}

ll tt[1000];
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	for(read(T);T;T--)
	{
		read(a);read(n);read(p);read(h);
		a%=p;

		if(a*n<p)printf("%s",a<=h?"YES":"NO");
		else printf("%s",get(a,n,p)<=h?"YES":"NO");
		printf("\n");
	}

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
void read(ll&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

ll T,a,n,p,h;

ll get(ll a,ll n,ll p)
{
	if(a>(p/2))a=p-a;

	if(a*n<p)return max(a,p-a*n);

	ll t;
	if(a*(n+1)%p>p/a*a)t=a*(n+1)/p;
	else
	if((a*(n+1)/p>a*n/p)) t=a*(n+1)/p-1;
	else t=a*n/p-1;

	//cout<< (a*(n+1)+p%a)/p-1<<' '<<t<<endl;
	return get(a-p%a,t,a);
}

ll tt[1000];
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	for(read(T);T;T--)
	{
		read(a);read(n);read(p);read(h);
		a%=p;

		if(a*n<p)printf("%s",a<=h?"YES":"NO");
		else printf("%s",get(a,n,p)<=h?"YES":"NO");
		printf("\n");
	}

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
void read(ll&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

ll T,a,n,p,h;

ll get(ll a,ll n,ll p)
{
	if(a>(p/2))a=p-a;

	if(a*n<p)return max(a,p-a*n);

	//cout<< (a*(n+1)+p%a)/p-1<<' '<<a*n/p-1<<endl;
	return get(a-p%a,(a*(n+1)+p%a)/p-1,a);
}

ll tt[1000];
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	for(read(T);T;T--)
	{
		read(a);read(n);read(p);read(h);
		a%=p;

		if(a*n<p)printf("%s",a<=h?"YES":"NO");
		else printf("%s",get(a,n,p)<=h?"YES":"NO");
		printf("\n");
	}

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
void read(ll&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

ll T,a,n,p,h;

ll get(ll a,ll n,ll p)
{
	if(a>(p/2))a=p-a;

	if(a*n<p)return max(a,p-a*n);

	return get(a-p%a,(a*n+p%a)/p-1,a);
}

ll tt[1000];
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	for(read(T);T;T--)
	{
		read(a);read(n);read(p);read(h);
		a%=p;

		if(a*n<p)printf("%s",a<=h?"YES":"NO");
		else
		{
			cout<<get(a,n,p)<<endl;
			printf("%s",get(a,n,p)<=h?"YES":"NO");
		}
		printf("\n");
	}

    scanf("\n");
    return 0;
}


/*
    Problem:
    Algorithm:
    Note:
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<string>
#include<iomanip>
#include<iostream>
#include<cmath>
#include<queue>
using namespace std;

#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)

typedef long long ll;
typedef long double real;
void read(int&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
void read(ll&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

ll T,a,n,p,h;

ll get(ll a,ll n,ll p)
{
	if(a>(p/2))a=p-a;

	if(a*n<p)return max(a,p-a*n);

	return get(a-p%a,(a*n)/p,a);
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	for(read(T);T;T--)
	{
		read(a);read(n);read(p);read(h);
		a%=p;
		if(a*n<p)printf("%s",a<=h?"YES":"NO");
		else printf("%s",get(a,n,p)<=h?"YES":"NO");
		printf("\n");
	}

    scanf("\n");
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#define X first
#define Y second
#define pb push_back
#define fr(i,n) for(int i=1;i<=n;i++)
#define fo(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef long long ll;

const int mod=(int)1e9+7;

int T;

int exgcd(int x,int y,int &a,int &b){
	if(!y) return a=1,b=0,b;
	int g=exgcd(y,x%y,a,b);
	int t=b;
	b=a-x/y*b;
	a=t;
	return g;
}

int inv(int x,int p){
	int a,b;
	exgcd(x,p,a,b);
	return (a%p+p)%p;
}

int F(int a,int n,int p){
	if(a*n<p) return max(a,p-a*n);
	int e=(ll)a*n%p%a;
	int _a=a-p%a;
	int _p=a;
	int _n=(ll)inv(_a,_p)*e%_p;
	if((ll)a*n%p+a>=p/a*a) return F(_a,_n,_p);
	else return F(_a,_n-1,_p);
}

int main(){
	scanf("%d",&T);
	while(T--){
		int a,n,p,h;
		scanf("%d%d%d%d",&a,&n,&p,&h);
		if(a*n<p){
			if(h>=a) printf("YES\n");
			else printf("NO\n");
		}
		else printf(F(a,n,p)<=h?"YES\n":"NO\n");
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#define X first
#define Y second
#define pb push_back
#define fr(i,n) for(int i=1;i<=n;i++)
#define fo(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef long long ll;

const int mod=(int)1e9+7;

int T;

int exgcd(int x,int y,int &a,int &b){
	if(!y) return a=1,b=0,b;
	int g=exgcd(y,x%y,a,b);
	int t=b;
	b=a-x/y*b;
	a=t;
	return g;
}

int inv(int x,int p){
	int a,b;
	exgcd(x,p,a,b);
	return (a%p+p)%p;
}

int F(int a,int n,int p){
	if(a*n<p) return max(a,p-a*n);
	int e=(ll)a*n%p%a;
	int _a=a-p%a;
	int _p=a;
	int _n=(ll)inv(_a,_p)*e%_p;
	if((ll)a*n%p+a>=p/a*a) return F(_a,_n,_p);
	else return F(_a,_n-1,_p);
}

int main(){
	scanf("%d",&T);
	while(T--){
		int a,n,p,h;
		scanf("%d%d%d%d",&a,&n,&p,&h);
		a%=p;
		if(a*n<p){
			if(h>=a) printf("YES\n");
			else printf("NO\n");
		}
		else printf(F(a,n,p)<=h?"YES\n":"NO\n");
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#define X first
#define Y second
#define pb push_back
#define fr(i,n) for(int i=1;i<=n;i++)
#define fo(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef long long ll;

const int mod=(int)1e9+7;

int T;

int exgcd(int x,int y,int &a,int &b){
    if(!y) return a=1,b=0,b;
    int g=exgcd(y,x%y,a,b);
    int t=b;
    b=a-x/y*b;
    a=t;
    return g;
}

int inv(int x,int p){
    int a,b;
    exgcd(x,p,a,b);
    return (a%p+p)%p;
}

int F(int a,int n,int p){
    if((ll)a*n<p) return max(a,p-a*n);
    int e=(ll)a*n%p%a;
    int _a=a-p%a;
    int _p=a;
    int _n=(ll)inv(_a,_p)*e%_p;
    if((ll)a*n%p+a>=p/a*a) return F(_a,_n,_p);
    else return F(_a,_n-1,_p);
}

int main(){
    scanf("%d",&T);
    while(T--){
        int a,n,p,h;
        scanf("%d%d%d%d",&a,&n,&p,&h);
        a%=p;
        if((ll)a*n<p){
            if(h>=a) printf("YES\n");
            else printf("NO\n");
        }
        else printf(F(a,n,p)<=h?"YES\n":"NO\n");
    }
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
int T;
int exgcd(int x,int y,int &a,int &b){
    if(!y) return a=1,b=0,b;
    int g=exgcd(y,x%y,a,b);
    int t=b;b=a-x/y*b;a=t;
    return g;
}z
int inv(int x,int p){
    int a,b;
    exgcd(x,p,a,b);
    return (a%p+p)%p;
}
int F(int a,int n,int p){
    if((ll)a*n<p) return max(a,p-a*n);
    int e=(ll)a*n%p%a;
    int _a=a-p%a,_p=a;
    int _n=(ll)inv(_a,_p)*e%_p;
    if((ll)a*n%p+a>=p/a*a) return F(p%a,_n,_p);
    else return F(p%a,_n-1,_p);
}
int main(){
    scanf("%d",&T);
    while(T--){
        int a,n,p,h;
        scanf("%d%d%d%d",&a,&n,&p,&h);
        a%=p;
        if((ll)a*n<p){
            if(h>=a) printf("YES\n");
            else printf("NO\n");
        }
        else printf(F(a,n,p)<=h?"YES\n":"NO\n");
    }
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
int T;
int exgcd(int x,int y,int &a,int &b){
    if(!y) return a=1,b=0,b;
    int g=exgcd(y,x%y,a,b);
    int t=b;b=a-x/y*b;a=t;
    return g;
}
int inv(int x,int p){
    int a,b;
    exgcd(x,p,a,b);
    return (a%p+p)%p;
}
int F(int a,int n,int p){
    if((ll)a*n<p) return max(a,p-a*n);
    int e=(ll)a*n%p%a;
    int _a=a-p%a,_p=a;
    int _n=(ll)inv(_a,_p)*e%_p;
    if((ll)a*n%p+a>=p/a*a) return F(p%a,_n,_p);
    else return F(p%a,_n-1,_p);
}
int main(){
    scanf("%d",&T);
    while(T--){
        int a,n,p,h;
        scanf("%d%d%d%d",&a,&n,&p,&h);
        a%=p;
        if((ll)a*n<p){
            if(h>=a) printf("YES\n");
            else printf("NO\n");
        }
        else printf(F(a,n,p)<=h?"YES\n":"NO\n");
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;

LL max_dis(LL a, LL p, LL n) {
	LL m = p/a;
	LL n1 = a*n/p;
	if(n1 && a*n%p < (m-1)*a) n1--;
	if(!n1) return a*n/p ? a : max(a, p-a*n);
	return max_dis(min(p%a, p-p%a), a, n1);
}

bool gao(LL a, LL n, LL p, LL h) {
	return min(max_dis(a%p, p, n), a%p) <= h;
}

int main() {
	int T; scanf("%d", &T);
	while(T--) {
		int a, n, p, h;
		scanf("%d%d%d%d", &a, &n, &p, &h);
		puts(gao(a, n, p, h) ? "YES" : "NO");
	}
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;

LL max_dis(LL a, LL p, LL n) {
	LL m = a*n/p;
	if(!m) return a;
	if(a*n%p < (p/a-1)*a) --m;
	if(!m) return max(a, p-a*n);
	return max_dis(min(p%a, p-p%a), a, m);
}

int main() {
	int T; scanf("%d", &T);
	while(T--) {
		int a, n, p, h;
		scanf("%d%d%d%d", &a, &n, &p, &h);
		puts(min(max_dis(a%p, p, n), a%p) <= h ? "YES" : "NO");
	}
}


#include <cstdio>

int main() {
	int T; scanf("%d", &T);
	while(T--) {
		int a, n, p, h;
		scanf("%d%d%d%d", &a, &n, &p, &h);
		int q = p / (n+1) + !!(p % (n+1));
		puts(q <= h ? "YES" : "NO");
	}
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;

int max_dis(LL a, LL p, LL n) {
	LL m = a*n/p;
	if(!m) return a;
	if(a*n%p < (p/a-1)*a) --m;
	if(!m) return max(a, p-a*n);
	return max_dis(min(p%a, p-p%a), a, m);
}

int main() {
	int T; scanf("%d", &T);
	while(T--) {
		int a, n, p, h;
		scanf("%d%d%d%d", &a, &n, &p, &h);
		puts(min(max_dis(a%p, p, n), a%p) <= h ? "YES" : "NO");
	}
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;

int max_dis(LL a, LL p, LL n) {
	LL m = a*n/p;
	if(!m) return max(a, p-a*n);
	if(a*n%p < (p/a-1)*a) --m;
	return m ? max_dis(min(p%a, p-p%a), a, m) : a;
}

int main() {
	int T; scanf("%d", &T);
	while(T--) {
		int a, n, p, h;
		scanf("%d%d%d%d", &a, &n, &p, &h);
		puts(min(max_dis(a%p, p, n), a%p) <= h ? "YES" : "NO");
	}
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <climits>
#include <sstream>
#include <cstring>
#include <cassert>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#include <set>

#define INF (INT_MAX/3)

typedef long long lint;

using namespace std;

pair <lint, lint> egcd(lint a, lint b)
{
	if (a == 0) return make_pair(0, 1);
	pair <lint, lint> res = egcd(b%a, a);
	return make_pair(res.second - (b/a) * res.first, res.first);
}

lint inv(lint a, lint m)
{
	lint ret = (egcd(a, m).first%m+m)%m;
	return ret;
}

pair <lint, lint> solve2(lint inva, lint n, lint p)
{
	lint gs, nback;

	if (inva == 1 || n == p) {
		gs = nback = 0;
	} else if (inva <= n) {
		lint a = inv(inva, p);
		lint y, x, y2;

		x = n;
		y = a * x % p;

		gs = 1 + ((p-1-x)/inva);
		y2 = y + gs;

		if (y2 >= p) {
			if (n+1 < p) {
				x = n+1;
				y = a * x % p;
				gs = 1 + ((p-1-x)/inva);
				y2 = y + gs;
			} else {
				gs = 0;
			}
		}

		nback = 0;
	} else {
		lint q = p / inva, r = p % inva;
		pair <lint, lint> ret2 = solve2(inva - r, n, inva);

		lint gs2 = ret2.first, nback2 = ret2.second;

		gs = (gs2 + 1)*q - (nback2 + (gs2 != 0)) + gs2;
		nback = gs2;
	}

	return make_pair(gs, nback);
}

bool solve(int a, int n, int p, int h)
{
	return solve2(inv(a%p, p), n+1, p).first + 1 <= h;
}

int main(int argc, char ** argv)
{
	int ntest;

	scanf("%d", &ntest);

	for (int t = 0; t < ntest; t++) {
		int a, n, p, h;

		scanf("%d %d %d %d", &a, &n, &p, &h);

		printf(solve(a,n,p,h) ? "YES\n" : "NO\n");
	}

	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
using namespace std ;
typedef long long LL ;

LL T, N, A, P, H ;
LL ans ;

LL Work(LL a, LL p, LL n)
{
	a = a%p ;
	if(a*n-a < p) return max(a, p-a*n+a) ;
	return Work(min(p%a, a-p%a), a, a*n/p+(a*n%p+a >= p-p%a)) ;
}

int main()
{
	int i, j ;
	scanf("%I64d", &T) ;
	for(i = 1; i <= T; i ++)
	{
		scanf("%I64d %I64d %I64d %I64d", &A, &N, &P, &H) ;
		A %= P ;
		ans = (A*N < P ? A : Work(A, P, N)) ;
		printf("%s\n", ans<=H?"YES":"NO") ;
	}
	//system("pause") ;
	return 0 ;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
using namespace std ;
typedef long long LL ;

LL T, N, A, P, H ;
LL ans ;

LL Work(LL a, LL p, LL n)
{
	int i ;
	a = a%p ;
	if(a*n < p)
		return max(a, p-a*n) ;
	return Work(min(p%a, a-p%a), a, a*n/p+(a*n%p+a >= p-p%a)-1) ;
}

int main()
{
	int i, j ;
	scanf("%I64d", &T) ;
	for(i = 1; i <= T; i ++)
	{
		scanf("%I64d %I64d %I64d %I64d", &A, &N, &P, &H) ;
		A %= P, N ;
		ans = (A*N < P ? A : Work(A, P, N)) ;
		printf("%s\n", ans<=H?"YES":"NO") ;
	}
	//system("pause") ;
	return 0 ;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
using namespace std ;
typedef long long LL ;

LL T, N, A, P, H ;
LL ans ;

LL Work(LL a, LL p, LL n)
{
	a = a%p ;
	if(a*n-a < p) return max(a, p-a*n+a) ;
	return Work(min(p%a, a-p%a), a, a*n/p+(a*n%p+a >= p-p%a)) ;
}

int main()
{
	int i, j ;
	scanf("%I64d", &T) ;
	for(i = 1; i <= T; i ++)
	{
		scanf("%I64d %I64d %I64d %I64d", &A, &N, &P, &H) ;
		ans = (A*N < P ? A : Work(A, P, N)) ;
		printf("%s\n", ans<=H?"YES":"NO") ;
	}
	//system("pause") ;
	return 0 ;
}


#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
LL T,n,a,mod,x;
bool Get(LL a,LL n,LL mod)
{
	LL t=a*n/mod;
	if(!t)return max(a,mod-a*n);
	if(a*n%mod<a*(mod/a-1))
		t--;
	return Get(a-mod%a,t,a);
}
int main()
{
	for(scanf("%I64d",&T);T--;)
	{
		scanf("%I64d%I64d%I64d%I64d",&a,&n,&mod,&x);
		puts(Get(a%mod,n,mod)>x?"NO":"YES");
	}
}


#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
LL T,n,a,mod,x;
LL Get(LL a,LL n,LL mod)
{
	LL t=a*n/mod;
	if(!t)return max(a,mod-a*n);
	if(a*n%mod<a*(mod/a-1))
		t--;
	return Get(a-mod%a,t,a);
}
int main()
{
	for(scanf("%I64d",&T);T--;)
	{
		scanf("%I64d%I64d%I64d%I64d",&a,&n,&mod,&x);
		if(a*n>=mod)
			puts(Get(a%mod,n,mod)>x?"NO":"YES");
		else
			puts(a>x?"NO":"YES");
	}
}


#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
LL T,n,a,mod,x;
LL Get(LL a,LL n,LL mod)
{
	LL t=a*n/mod;
	if(!t)return max(a,mod-a*n);
	if(a*n%mod<a*(mod/a-1))
		t--;
	return Get(a-mod%a,t,a);
}
int main()
{
	for(scanf("%I64d",&T);T--;)
	{
		scanf("%I64d%I64d%I64d%I64d",&a,&n,&mod,&x);
		a%=mod;
		if(a*n>=mod)
			puts(Get(a%mod,n,mod)>x?"NO":"YES");
		else
			puts(a>x?"NO":"YES");
	}
}


#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
LL T,n,a,mod,x;
LL Get(LL a,LL n,LL mod)
{
	LL t=a*n/mod;
	if(!t)return max(a,mod-a*n);
	if(a*n%mod<a*(mod/a-1))
		t--;
	return Get(a-mod%a,t,a);
}
int main()
{
	for(scanf("%I64d",&T);T--;)
	{
		scanf("%I64d%I64d%I64d%I64d",&a,&n,&mod,&x);
		puts(Get(a%mod,n,mod)>x?"NO":"YES");
	}
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int T;
int a,n,p,h,ans;
int a1,n1,p1;
int main() {
    scanf("%d",&T);
    while (T--) {
        scanf("%d%d%d%d",&a,&n,&p,&h);
        a%=p;
        if ((ll)a*n<p) ans=a;
        else {
            while ((ll)a*n>(ll)p) {
                a1=min(p%a,a-p%a);
                p1=a;
                n1=(ll)a*n/p;
                if ((p/a-1)*a>(ll)a*n%p) n1--;
                a=a1;
                p=p1;
                n=n1;
            }
            ans=max(a,p-a*n);
        }
        if (h<ans) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int T;
int a,n,p,h,ans;
int a1,n1,p1;
int main() {
    scanf("%d",&T);
    while (T--) {
        scanf("%d%d%d%d",&a,&n,&p,&h);
        if ((ll)a*n<p) ans=a;
        else {
            while ((ll)a*n>(ll)p) {
                a1=min(p%a,a-p%a);
                p1=a;
                n1=(ll)a*n/p;
                a=a1;
                p=p1;
                n=n1;
            }
            ans=max(a,p-a*n);
        }
        if (h<ans) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int T;
int a,n,p,h,ans;
int a1,n1,p1;
int main() {
    scanf("%d",&T);
    while (T--) {
        scanf("%d%d%d%d",&a,&n,&p,&h);
        a%=p;
        if ((ll)a*n<p) ans=a;
        else {
            while ((ll)a*n>(ll)p) {
                a1=min(p%a,a-p%a);
                p1=a;
                n1=(ll)a*n/p;
                a=a1;
                p=p1;
                n=n1;
            }
            ans=max(a,p-a*n);
        }
        if (h<ans) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int T;
int a,n,p,h,ans;
int a1,n1,p1;
int main() {
    scanf("%d",&T);
    while (T--) {
        scanf("%d%d%d%d",&a,&n,&p,&h);
        while ((ll)a*n>(ll)p) {
            a1=min(p%a,a-p%a);
            p1=a;
            n1=(ll)a*n/p;
            a=a1;
            p=p1;
            n=n1;
        }
        ans=max(a,p-a*n);
        if (h<ans) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int T;
int a,n,p,h,ans;
int a1,n1,p1;
int main() {
    scanf("%d",&T);
    while (T--) {
        scanf("%d%d%d%d",&a,&n,&p,&h);
        if ((ll)a*n<p) ans=a;
        else {
            while ((ll)a*n>(ll)p) {
                a1=min(p%a,a-p%a);
                p1=a;
                n1=(ll)a*n/p;
                if ((p/a-1)*a>(ll)a*n%p) n1--;
                a=a1;
                p=p1;
                n=n1;
            }
            ans=max(a,p-a*n);
        }
        if (h<ans) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
int T,N,A,P,H;
int F(long long a,int n,int p)
{
	int t=a*n/p;
	if (!t) return a>p-a*n?a:p-a*n;
	if (a*n%p<a*(p/a-1)) t--;
	return F(std::min(a-p%a,p%a),t,a);
}
int main()
{
	for (scanf("%d",&T); T; T--) scanf("%d%d%d%d",&A,&N,&P,&H),A%=P,puts((1ll*A*N<P?A:F(A,N,P))>H?"NO":"YES");
}


#include<iostream>
#include<cstdio>
using namespace std;
long long t,a,n,p,h;
long long calc(long long a,long long n,long long p)
{
	if(a*n<=p)return max(a,p-a*(n));
	int t=a*n/p;
	if(a*n%p+a<p) t--;
	return calc(p%a,t,a);
}
int main()
{
	cin>>t;
	while(t--)
	{
		scanf("%I64d%I64d%I64d%I64d",&a,&n,&p,&h);
		a%=p;
		if(((a*n<p)?a:calc(a,n,p))<=h)puts("YES");
		else puts("NO");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
long long t,a,n,p,h;
long long calc(long long a,long long n,long long p)
{
	if(a*n<=p)return max(a,p-a*(n));
	return calc(p%a,(a*n)/p,a);
}
int main()
{
	cin>>t;
	while(t--)
	{
		scanf("%I64d%I64d%I64d%I64d",&a,&n,&p,&h);
		a%=p;
		if(((a*n<p)?a:calc(a,n+1,p))<=h)puts("YES");
		else puts("NO");
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int T,a,n,p,h,i,j,k,ans;

int cal(int x,int y,int z)
{
	if(!y)return z;
	if((long long)x*y<z)
	{
		if(z==p)return x;
		else return max(x,z-x*y);
	}
	int tmp=(long long)x*y/z+((long long)x*y%z!=0);
	if((long long)x*y%z+x<=z/x*x)--tmp;
	return cal(x-z%x,tmp-1,x);
}

int main()
{
	scanf("%d",&T);
	for(;T;--T)
	{
		scanf("%d%d%d%d",&a,&n,&p,&h);
		if(cal(a%p,n,p)<=h)printf("YES\n");
		else printf("NO\n");
	}
}


#include <cstdio>
#include <algorithm>

using namespace std;

int solve(int a, int n, int p)
{
	if (a * n < p) return max(a, p - a * n);
	int cnt = a * n / p;
	if (a * n % p < a * (p / a - 1) + 1)
		--cnt;
	return solve(p % a, cnt, a);
}
int main()
{
	int t, a, n, p, h;
	for (scanf("%d", &t); t--; )
	{
		scanf("%d %d %d %d", &a, &n, &p, &h);
		int mxd = 0;
		if (a * n < p)
			mxd = a;
		else
			mxd = solve(a, n, p);
		printf("%s\n", mxd > h? "NO": "YES");
	}
}


#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long s64;

s64 solve(s64 a, s64 n, s64 p)
{
	if (a * n < p) return max(a, p - a * n);
	s64 cnt = a * n / p;
	if (a * n % p < a * (p / a - 1))
		--cnt;
	return solve(a - p % a, cnt, a);
}
int main()
{
	s64 t, a, n, p, h;
	for (scanf("%I64d", &t); t--; )
	{
		scanf("%I64d %I64d %I64d %I64d", &a, &n, &p, &h), a %= p;
		s64 mxd = 0;
		if (a * n < p)
			mxd = a;
		else
			mxd = solve(a, n, p);
		printf("%s\n", mxd > h? "NO": "YES");
	}
}


#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long s64;

s64 solve(s64 a, s64 n, s64 p)
{
	if (a * n < p) return max(a, p - a * n);
	s64 cnt = a * n / p;
	if (a * n % p < a * (p / a - 1))
		--cnt;
	return solve(a - p % a, cnt, a);
}
int main()
{
	int t, a, n, p, h;
	for (scanf("%d", &t); t--; )
	{
		scanf("%d %d %d %d", &a, &n, &p, &h), a %= p;
		int mxd = 0;
		if (a * n < p)
			mxd = a;
		else
			mxd = solve(a, n, p);
		printf("%s\n", mxd > h? "NO": "YES");
	}
}


#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long s64;

s64 solve(s64 a, s64 n, s64 p)
{
	if (a * n < p) return max(a, p - a * n);
	s64 cnt = a * n / p;
	if (a * n % p < a * (p / a - 1))
		--cnt;
	return solve(min(a - p % a, p % a), cnt, a);
}
int main()
{
	s64 t, a, n, p, h;
	for (scanf("%I64d", &t); t--; )
	{
		scanf("%I64d %I64d %I64d %I64d", &a, &n, &p, &h), a %= p;
		s64 mxd = 0;
		if (a * n < p)
			mxd = a;
		else
			mxd = solve(a, n, p);
		printf("%s\n", mxd > h? "NO": "YES");
	}
}


#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstring>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

#define SIZE(x) (int((x).size()))
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
#define repd(i,r,l) for (int i=(r); i>=(l); i--)
#define rept(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

#ifndef ONLINE_JUDGE
#define debug(x) { cerr<<#x<<" = "<<(x)<<endl; }
#else
#define debug(x) {}
#endif

int solve(int v, int n, int p, int del)
{
	if (LL(v)*(n-1)<p) return max(v,p-v*(n-1))<=del;
	if (v*2>p) v=p-v;
	return solve(v-p%v,(LL(v)*n+p%v)/p,v,del);
}

void lemon()
{
	int v,n,p,h; scanf("%d%d%d%d",&v,&n,&p,&h); v%=p;
	if (LL(v)*n<=p)
		if (v<=h) printf("YES\n"); else printf("NO\n");
	else  if (solve(v,n+1,p,h)) printf("YES\n"); else printf("NO\n");
}

int main()
{
	ios::sync_with_stdio(true);
	#ifndef ONLINE_JUDGE
		freopen("346E.in","r",stdin);
	#endif
	int tcase; scanf("%d",&tcase);
	while (tcase--) lemon();
	return 0;
}


#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstring>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

#define SIZE(x) (int((x).size()))
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
#define repd(i,r,l) for (int i=(r); i>=(l); i--)
#define rept(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

#ifndef ONLINE_JUDGE
#define debug(x) { cerr<<#x<<" = "<<(x)<<endl; }
#else
#define debug(x) {}
#endif

int solve(int v, int n, int p, int del)
{
	if (v*2>p) v=p-v;
	if (LL(v)*(n-1)<p) return max(v,p-v*(n-1))<=del;
	return solve(v-p%v,(LL(v)*n+p%v)/p,v,del);
}

void lemon()
{
	int v,n,p,h; scanf("%d%d%d%d",&v,&n,&p,&h); v%=p;
	if (LL(v)*n<=p)
		if (v<=h) printf("YES\n"); else printf("NO\n");
	else  if (solve(v,n+1,p,h)) printf("YES\n"); else printf("NO\n");
}

int main()
{
	ios::sync_with_stdio(true);
	#ifndef ONLINE_JUDGE
		freopen("346E.in","r",stdin);
	#endif
	int tcase; scanf("%d",&tcase);
	while (tcase--) lemon();
	return 0;
}


#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstring>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

#define SIZE(x) (int((x).size()))
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
#define repd(i,r,l) for (int i=(r); i>=(l); i--)
#define rept(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

#ifndef ONLINE_JUDGE
#define debug(x) { cerr<<#x<<" = "<<(x)<<endl; }
#else
#define debug(x) {}
#endif

int solve(int v, int n, int p, int del)
{
	if (LL(v)*n<p) return max(v,p-v*n)<=del;
	v%=p; int per=p/v+1;
	return solve(v-p%v,n/per,v,del);
}

void lemon()
{
	int v,n,p,h; scanf("%d%d%d%d",&v,&n,&p,&h);
	if (solve(v,n+1,p,h)) printf("YES\n"); else printf("NO\n");
}

int main()
{
	ios::sync_with_stdio(true);
	#ifndef ONLINE_JUDGE
		freopen("346E.in","r",stdin);
	#endif
	int tcase; scanf("%d",&tcase);
	while (tcase--) lemon();
	return 0;
}


#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int a,n,p,h;
int find(int a,int n,int p){
    if (1ll*a*n<p) return max(a,p-a*n);
    int k1=1ll*a*n/p;
    if (1ll*a*n/p+a<=p/a*a) k1--; find(min(p%a,a-p%a),k1,a);
}
int main(){
    int t; scanf("%d",&t);
    for (;t;t--){
        scanf("%d%d%d%d",&a,&n,&p,&h); a=a%p; int ans;
        if (1ll*a*n<p) ans=a; else ans=find(a,n,p);
        if (ans<=h) printf("YES\n"); else printf("NO\n");
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int a,n,p,h;
int find(int a,int n,int p){
    if (1ll*a*n<p) return max(a,p-a*n);
    int k1=1ll*a*n/p;
    if (1ll*a*n%p+a<=p/a*a) k1--; find(min(p%a,a-p%a),k1,a);
}
int main(){
    int t; scanf("%d",&t);
    for (;t;t--){
        scanf("%d%d%d%d",&a,&n,&p,&h); a=a%p; int ans;
        if (1ll*a*n<p) ans=a; else ans=find(a,n,p);
        if (ans<=h) printf("YES\n"); else printf("NO\n");
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int a,n,p,h;
int find(int a,int n,int p){
    if (1ll*a*n<p) return max(a,p-a*n);
    int k1=1ll*a*n/p;
    if (1ll*a*n/p+p<=p/a*a) k1--; find(min(p%a,a-p%a),k1,a);
}
int main(){
    int t; scanf("%d",&t);
    for (;t;t--){
        scanf("%d%d%d%d",&a,&n,&p,&h); a=a%p; int ans;
        if (1ll*a*n<p) ans=a; else ans=find(a,n,p);
        if (ans<=h) printf("YES\n"); else printf("NO\n");
    }
    return 0;
}


/*
Date: 2014/11/17 07:33:15 Monday
Author: xllend3
*/
/*
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
*/
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mp make_pair
#define ph push
#define pb push_back
#define REP(i,a,n) for(int _tmp=n,i=a;i<=_tmp;++i)
#define DEP(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define ALL(x,S) for(__typeof((S).end()) x=S.begin();x!=S.end();x++)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x20202020;
const int mod=1000000007;
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
template<class T> inline void read(T&x,T&y,T&z,T&q){read(x);read(y);read(z);read(q);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,a,p,h;
int calc(ll a,ll n,ll p){
    ll t=a*n/p;
    if(t<=0)return max(a,p-a*n);
    if(a*n%p+p/a<p)t--;
    return calc(a-p%a,t,a);
}
int main()
{
    //ios::sync_with_stdio(false);
#ifdef LOCAL
    freopen("CF346E.in","r",stdin);//freopen("CF346E.out","w",stdout);
#endif
    scanf("%d",&C);rep(_,1,C){
        scanf("%d%d%d%d",&a,&n,&p,&h);a%=p;
        int ans=calc(a,n,p);
        if(1ll*a*n<p)ans=a;
        puts(ans>h?"NO":"YES");
    }
    return 0;
}


/*
Date: 2014/11/17 07:33:15 Monday
Author: xllend3
*/
/*
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
*/
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mp make_pair
#define ph push
#define pb push_back
#define REP(i,a,n) for(int _tmp=n,i=a;i<=_tmp;++i)
#define DEP(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define ALL(x,S) for(__typeof((S).end()) x=S.begin();x!=S.end();x++)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x20202020;
const int mod=1000000007;
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
template<class T> inline void read(T&x,T&y,T&z,T&q){read(x);read(y);read(z);read(q);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,a,p,h;
int calc(ll a,ll n,ll p){
	ll t=a*n/p;
	if(t<=0)return max(a,p-a*n);
	if(a*n%p<a*(p/a-1))t--;
	return calc(a-p%a,t,a);
}
int main()
{
	//ios::sync_with_stdio(false);
#ifdef LOCAL
	freopen("CF346E.in","r",stdin);//freopen("CF346E.out","w",stdout);
#endif
	scanf("%d",&C);rep(_,1,C){
		scanf("%d%d%d%d",&a,&n,&p,&h);a%=p;
		int ans=calc(a,n,p);
		if(1ll*a*n<p)ans=a;
		puts(ans>h?"NO":"YES");
	}
	return 0;
}


/*
Date: 2014/11/17 07:33:15 Monday
Author: xllend3
*/
/*
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
*/
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mp make_pair
#define ph push
#define pb push_back
#define REP(i,a,n) for(int _tmp=n,i=a;i<=_tmp;++i)
#define DEP(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define ALL(x,S) for(__typeof((S).end()) x=S.begin();x!=S.end();x++)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x20202020;
const int mod=1000000007;
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
template<class T> inline void read(T&x,T&y,T&z,T&q){read(x);read(y);read(z);read(q);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,a,p,h;
int calc(ll a,ll n,ll p){
    ll t=a*n/p;
    //if(a*n%p+p/a<p)t--;
    if(t<=0)return max(a,p-a*n);
    return calc(a-p%a,t,a);
}
int main()
{
    //ios::sync_with_stdio(false);
#ifdef LOCAL
    freopen("CF346E.in","r",stdin);//freopen("CF346E.out","w",stdout);
#endif
    scanf("%d",&C);rep(_,1,C){
        scanf("%d%d%d%d",&a,&n,&p,&h);a%=p;
        int ans=calc(a,n,p);
        if(1ll*a*n<p)ans=a;
        puts(ans>h?"NO":"YES");
    }
    return 0;
}


#include <stdio.h>
#include <algorithm>
using namespace std;
int A, N, P, H, R;
int F(long long a, int n, int p){
    int t = a*n/p;
    if(!t)return a>p-a*n?a:p-a*n;
    if(a*n%p<a*(p/a-1))t--;
    return F(min(p%a, a-p%a), t, a);
}
int main(){
    ///freopen("E.in", "r", stdin);
    for(scanf("%d", &R); R--; ){
        scanf("%d%d%d%d", &A, &N, &P, &H);
        //printf("%d %d %d %d\n", A, N, P, H);
        int HH;
        A%=P;
        if(1LL*A*N<P)HH=A;
        else HH=F(A, N, P);
        puts(HH<=H ? "YES" : "NO");
    }
}


#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;

ll calc(ll a,ll n,ll p) {
    ll t=a*n/p;
    if(!t) return max(a,p-a*n);
    if(a*n%p<a*(p/a-1)) t--;
    return calc(min(a-p%a,p%a),t,a);
}

int main() {
//  freopen("e.in","r",stdin);
    ll a,n,p,h,x;
    int T;
    for(scanf("%d",&T);T--;) {
        scanf("%I64d %I64d %I64d %I64d",&a,&n,&p,&h);
        if(a*n<=p) x=a; else x=calc(a,n,p);
        if(x<=h) puts("YES"); else puts("NO");
    }
    return 0;
}


#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;

ll calc(ll a,ll n,ll p) {
    ll t=a*n/p;
    if(!t) return max(a,p-a*n);
    if(a*n%p<a*(p/a-1)) t--;
    return calc(min(a-p%a,p%a),t,a);
}

int main() {
//  freopen("e.in","r",stdin);
    ll a,n,p,h,x;
    int T;
    for(scanf("%d",&T);T--;) {
        scanf("%I64d %I64d %I64d %I64d",&a,&n,&p,&h);
        a%=p;
        if(a*n<=p) x=a; else x=calc(a,n,p);
        if(x<=h) puts("YES"); else puts("NO");
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
long long a,n,p,h;
int T;
long long f(long long a,long long n,long long p)
{
	long long t = a * n / p;
	if (a * n < p) return std::max(a,p - a * n);
	if (a * n % p < a * (p / a - 1)) --t;
	return f(p % a,t,a);
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("346E.in","r",stdin);
	freopen("346E.out","w",stdout);
	#endif
	scanf("%d",&T);
	while (T--) {
		scanf("%I64d%I64d%I64d%I64d",&a,&n,&p,&h);
		a %= p;
		if (a * n < p) puts(a > h ? "NO" : "YES");
		else puts(f(a,n,p) > h ? "NO" : "YES");
	}
}


#include <cstdio>
#include <algorithm>
long long a,n,p,h;
int T;
long long f(long long a,long long n,long long p)
{
	long long t = a * n / p;
	if (a * n < p) return std::max(a,p - a * n);
	if (a * n % p < a * (p / a - 1)) --t;
	return f(std::min(p - p % a,p % a),t,a);
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("346E.in","r",stdin);
	freopen("346E.out","w",stdout);
	#endif
	scanf("%d",&T);
	while (T--) {
		scanf("%I64d%I64d%I64d%I64d",&a,&n,&p,&h);
		a %= p;
		if (a * n < p) puts(a > h ? "NO" : "YES");
		else puts(f(a,n,p) > h ? "NO" : "YES");
	}
}


#include <cstdio>
#include <algorithm>
long long a,n,p,h;
int T;
long long f(long long a,long long n,long long p)
{
	long long t = a * n / p;
	if (a * n < p) return std::max(a,p - a * n);
	if (a * n % p < a * (p / a - 1)) --t;
	return f(p % a,t,a);
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("346E.in","r",stdin);
	freopen("346E.out","w",stdout);
	#endif
	scanf("%d",&T);
	while (T--) {
		scanf("%I64d%I64d%I64d%I64d",&a,&n,&p,&h);
		if (a * n < p) puts(a > h ? "NO" : "YES");
		else puts(f(a,n,p) > h ? "NO" : "YES");
	}
}


// Author: Ruchiose
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#define i64 long long
#define d64 long double
#define fortodo(i, f, t) for (i = f; i <= t; i++)
using namespace std;

int T;
i64 A, N, P, H;

void setResult(i64 x)
{
    if (x <= H)
        puts("YES");
    else
        puts("NO");
}

int main()
{
    for (scanf("%d", &T); T; T--)
        {
            cin >> A >> N >> P >> H;
            if (T==9959) printf("%I64d %I64d %I64d %I64d\n",A,N,P,H);
            A %= P;
            if (A * N < P)
                {
                    setResult(A);
                    continue;
                }
            else
                while (1)
                    {
                        i64 floorId = A * N / P;
                        i64 E = P / A * A;
                        i64 MO = A * N % P % A;
                        i64 EXPECTED = MO + (E - MO) / A * A;
                        i64 RECEIVED = A * N % P;
                        i64 a, n, p;
                        a = E + A - P;
                        n = floorId - ((EXPECTED == RECEIVED) ? 0 : 1);
                        p = A;
                        A = a;
                        N = n;
                        P = p;
                        if (A * N < P)
                            {
                                setResult(max(A, P - A * N));
                                break;
                            }
                    }
        }
}


/*Copyright © 2015 by Heartbreak_Kid
All rights reserved.This code or any portion thereof
may not be reproduced or used in any manner whatsoever
without the express written permission of the developer*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include<iostream>
#include<cmath>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include<map>
#include<iterator>
#define ll long long
#define pi   acos(-1.0)

using namespace std;
ll ar[1234567];
int main()

{
    ll n, d, count = 0;
    cin >> n >> d;
    cin >> ar[0];

    for (ll i = 1; i < n; i++)
    {
    ll ans=0;
        cin >> ar[i];
        if (ar[i] <= ar[i - 1])
        {
             ans= ((ar[i - 1] - ar[i]) / d + 1);
             ar[i] = ar[i] + (d*ans);
        }
        count += ans;
    }
    cout << count << "\n";

    //system("pause");
    return 0;
}


/*Copyright © 2015 by Heartbreak_Kid
All rights reserved.This code or any portion thereof
may not be reproduced or used in any manner whatsoever
without the express written permission of the developer*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include<iostream>
#include<cmath>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include<map>
#include<iterator>
#define ll long long
#define pi   acos(-1.0)

using namespace std;
ll ar[1234567];
int main()

{
    ll n, d, count = 0;
    cin >> n >> d;
    cin >> ar[0];
    ll ans=0;
    for (ll i = 1; i < n; i++)
    {
        cin >> ar[i];
        if (ar[i] <= ar[i - 1])
        {
             ans= ((ar[i - 1] - ar[i]) / d + 1);
             ar[i] = ar[i - 1] + (d*ans);
        }
        count += ans;
    }
    cout << count << "\n";

    //system("pause");
    return 0;
}


/*Copyright © 2015 by Heartbreak_Kid
All rights reserved.This code or any portion thereof
may not be reproduced or used in any manner whatsoever
without the express written permission of the developer*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include<iostream>
#include<cmath>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include<map>
#include<iterator>
#define ll long long
#define pi   acos(-1.0)

using namespace std;
ll ar[1234567];
int main()

{
    ll n, d, count = 0;
    cin >> n >> d;
    cin >> ar[0];
    ll ans=0;
    for (ll i = 1; i < n; i++)
    {
        cin >> ar[i];
        if (ar[i] <= ar[i - 1])
        {
             ans= ((ar[i - 1] - ar[i]) / d + 1);
             ar[i] = ar[i] + (d*ans);
        }
        count += ans;
    }
    cout << count << "\n";

    //system("pause");
    return 0;
}


// CF4_A.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int main()
{
	int n, d, a[2000], count_sh=0;
	cin>>n>>d;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int pred=a[0];
	for(int i=1;i<n;i++)
	{
		if(a[i]<pred)
		{
			count_sh+=(int)ceilf((float)(pred-a[i])/d);
			a[i]+=count_sh*d;
		}
		else if(a[i]==pred)
		{
			a[i]+=d;
			count_sh++;
		}
		/*while(a[i]<=pred)
		{
			a[i]+=d;
			count_sh++;
		}*/
		pred=a[i];
	}
	cout<<count_sh<<endl;
	return 0;
}


// CF4_A.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	int n, d, a[2000], count_sh=0;
	cin>>n>>d;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int pred=a[0];
	for(int i=1;i<n;i++)
	{
		while(a[i]<=pred)
		{
			a[i]+=d;
			count_sh++;
		}
		pred=a[i];
	}
	cout<<count_sh<<endl;
	return 0;
}


// CF4_A.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int main()
{
	int n, d, a[2000], count_sh=0;
	cin>>n>>d;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int pred=a[0];
	for(int i=1;i<n;i++)
	{
		if(a[i]<pred)
		{
			count_sh+=pred-a[i]/d+1;
			a[i]+=count_sh*d;
		}
		else if(a[i]==pred)
		{
			a[i]+=d;
			count_sh++;
		}
		/*while(a[i]<=pred)
		{
			a[i]+=d;
			count_sh++;
		}*/
		pred=a[i];
	}
	cout<<count_sh<<endl;
	return 0;
}


// CF4_A.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int main()
{
	int n, d, a[2000], count_sh=0;
	cin>>n>>d;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int pred=a[0];
	for(int i=1;i<n;i++)
	{
		if(a[i]<=pred)
		{
			count_sh+=(pred-a[i])/d+1;
			a[i]+=((pred-a[i])/d+1)*d;
		}
		/*while(a[i]<=pred)
		{
			a[i]+=d;
			count_sh++;
		}*/
		pred=a[i];
	}
	cout<<count_sh<<endl;
	return 0;
}


// CF4_A.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int n, count_el=0;
	cin>>n;
	for(int i=3;i<=n;i++)
	{
		int count_del=0;
		for(int j=2;j<=i/2;j++)
			if(i%j==0)
			{
				bool flag=true;
				for(int k=2;k<=j/2;k++)
					if(j%k==0)
					{
						flag=false;
						break;
					}
				if(flag) count_del++;
			}
		if(count_del==2)
			count_el++;
	}
	cout<<count_el<<endl;
	return 0;
}


// CF4_A.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int main()
{
	int n, d, a[2000], count_sh=0;
	cin>>n>>d;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int pred=a[0];
	for(int i=1;i<n;i++)
	{
		if(a[i]<pred)
		{
			count_sh+=(pred-a[i])/d+1;
			a[i]+=count_sh*d;
		}
		else if(a[i]==pred)
		{
			a[i]+=d;
			count_sh++;
		}
		/*while(a[i]<=pred)
		{
			a[i]+=d;
			count_sh++;
		}*/
		pred=a[i];
	}
	cout<<count_sh<<endl;
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
	int n, d, a[2001], i, m, sum = 0;
	cin >> n >> d;
	for(i = 0; i < n; i++)
	cin >> a[i];
	int len = a[0];
	for(i = 1; i < n; i++)
	{
		if(a[i] > len) len = a[i];
		else
		{
			m = a[i];
			while(m <= len)
			{
				m = m + d;
				sum++;
			}
			len = m;
		}
	}
	cout << sum << endl;
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
	int n, d, a[2001], i, m, x, sum = 0;
	cin >> n >> d;
	for(i = 0; i < n; i++)
	cin >> a[i];
	int len = a[0];
	for(i = 1; i < n; i++)
	{
		if(a[i] > len) len = a[i];
		else
		{
			m = len - a[i];
			x = (m / d + 1);
			sum += x;
			len = a[i] + x * d;
		}
	}
	cout << sum << endl;
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
	int n, d, a[2001], i, m, sum = 0;
	cin >> n >> d;
	for(i = 0; i < n; i++)
	cin >> a[i];
	int len = a[0];
	for(i = 1; i < n; i++)
	{
		if(a[i] > len) len = a[i];
		else
		{
			m = len - a[i];
			sum += (m / d + 1);
			len = a[i] + sum * d;
		}
	}
	cout << sum << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <sstream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <ctime>

using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;
    int f, l;
    int count = 0;
    cin >> l;
    int div = 1;
    int sub = 0;
    for (int i = 1; i < n; ++i)
    {
        f = l;
        cin >> l;
        if (f >= l) {
            sub = f - l;
            div = sub / d;
            ++div;
            l += (d * div);
            count += div;
        }

    }

    cout << count;
    cin >> n;
    return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <sstream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <ctime>

using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;
    int f, l;
    int count = 0;
    cin >> l;
    for (int i = 1; i < n; ++i)
    {
        f = l;
        cin >> l;
        while (f >= l) {
            l += d;
            ++count;
        }
    }

    cout << count;
    cin >> n;
    return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <sstream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <ctime>

using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;
    vector<int> arr(n);

    for (int i = 0; i < n; ++i)
        cin >> arr[i];

    int count = 0;
    for (int i = 1; i < n; ++i)
    {
        while (arr[i-1] >= arr[i]) {
            arr[i] += d;
            count++;
        }
    }

    cout << count;
    cin >> n;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <stack>
#include <deque>
#define sf scanf
#define pf printf
#define ve vector
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define FOR1(i,n) for(int i = 1; i <= (n); i++)
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x)*(x)
using namespace std;
int main()
{
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int n,d;
	sf("%d %d",&n,&d);

	int a[2001] = {0};
	FOR(i,n)
	{
		sf("%d",&a[i]);
	}
	int r = 0;
	FOR(i,n - 1)
	{
		int del = a[i] - a[i + 1];
		if(del == 0)
		{
			a[i + 1] += d;
			r++;
		}
		else if(del > 0)
		{
			r += del/d;
			if(del % d != 0) r++;
		}
	}
	pf("%d",r);
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <stack>
#include <deque>
#define sf scanf
#define pf printf
#define ve vector
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define FOR1(i,n) for(int i = 1; i <= (n); i++)
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x)*(x)
using namespace std;
int main()
{
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int n,d;
	sf("%d %d",&n,&d);

	int a[2001] = {0};
	FOR(i,n)
	{
		sf("%d",&a[i]);
	}
	int r = 0;
	FOR(i,n - 1)
	{
		int del = a[i] - a[i + 1];
		if(del == 0)
		{
			a[i + 1] += d;
			r++;
		}
		else if(del > 0)
		{
			r += del/d + 1;
		//	if(del % d == 0) r++;
		}
	}
	pf("%d",r);
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <stack>
#include <deque>
#define sf scanf
#define pf printf
#define ve vector
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define FOR1(i,n) for(int i = 1; i <= (n); i++)
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x)*(x)
using namespace std;
int main()
{
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int n,d;
	sf("%d %d",&n,&d);

	int a[2001] = {0};
	FOR(i,n)
	{
		sf("%d",&a[i]);
	}
	int r = 0;
	FOR(i,n - 1)
	{
		int del = a[i] - a[i + 1];
		if(del == 0)
		{
			a[i + 1] += d;
			r++;
		}
		else if(del > 0)
		{
			r += del/d + 1;
			a[i + 1] += d*(del/d + 1);
		//	if(del % d == 0) r++;
		}
	}
	pf("%d",r);
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <stack>
#include <deque>
#define sf scanf
#define pf printf
#define ve vector
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define FOR1(i,n) for(int i = 1; i <= (n); i++)
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x)*(x)
using namespace std;
int main()
{
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int n,d;
	sf("%d %d",&n,&d);

	int a[2001] = {0};
	FOR(i,n)
	{
		sf("%d",&a[i]);
	}
	int r = 0;
	FOR(i,n - 1)
	{
		while(a[i + 1] <= a[i])
		{
			a[i + 1] += d;
			r++;
		}
	}
	pf("%d",r);
	return 0;
}


#include <stdio.h>
#include <vector>
using namespace std;
int n,d;
vector <long long int> b(0);
long long int a;
int g(0);
int main()
{
    scanf("%d%d",&n,&d);
    for (int i=0;i<n;i++)
    {
        scanf("%lld",&a);
        b.push_back(a);
    }
    for (int i=1;i<n;i++) if (b[i]<=b[i-1])
    {
        g+=(b[i-1]+d-b[i])/d;
        b[i]+=(b[i-1]+d-b[i])/d*d;
    }
    printf("%d",g);
    return 0;
}


#include <stdio.h>
#include <vector>
using namespace std;
int n,d;
vector <long long int> b(0);
long long int a;
int g(0);
int main()
{
    scanf("%d%d",&n,&d);
    for (int i=0;i<n;i++)
    {
        scanf("%lld",&a);
        b.push_back(a);
    }
    for (int i=1;i<n;i++) if (b[i]<=b[i-1])
    {
        g+=(b[i-1]+d-1-b[i])/d;
        b[i]+=(b[i-1]+d-1-b[i])/d*d;
    }
    printf("%d",g);
    return 0;
}


#include <stdio.h>
#include <vector>
using namespace std;
int n,d;
vector <long long int> b(0);
long long int a;
int g(0);
int main()
{
    scanf("%d%d",&n,&d);
    for (int i=0;i<n;i++)
    {
        scanf("%lld",&a);
        b.push_back(a);
    }
    for (int i=1;i<n;i++) while (b[i]<=b[i-1])
    {
        g++;
        b[i]+=d;
    }
    printf("%d",g);
    return 0;
}


#include<iostream>
using namespace std;
void main()
{
    int n,d,temp,min,m=1,counter=0,y,x;
    int a[2001];
    bool flag=true;
    cin>>n>>d;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]+=d;
    }

    for(int i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[j]<=a[i])
            {     x=a[i]-a[j];
                y=x/d+1;
                    counter+=y;
                    a[j]=a[j]+(y*d);
            }
        }
    }
    cout<<counter;

}


#include<iostream>
using namespace std;
void main()
{
    int n,d,temp,min,m=1,counter=0;
    int a[200];
    bool flag=true;
    cin>>n>>d;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]+=d;
    }

    for(int i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[i]>=a[j])
            {     counter++;
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    cout<<counter;

}


#include<iostream>
using namespace std;
void main()
{
    int n,d,temp,min,m=1,counter=0,y,x;
    int a[200];
    bool flag=true;
    cin>>n>>d;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]+=d;
    }

    for(int i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[j]<=a[i])
            {     x=a[i]-a[j];
                y=x/d+1;
                    counter+=y;
                    a[j]=a[j]+(y*d);
            }
        }
    }
    cout<<counter;

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <cmath>
#include <sstream>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
long long m[4000]={0};
int n,g,t=0;
cin>>n>>g;
for(int j=0;j<n;j++)cin>>m[j];

for(int j=0;j<n-1;j++){
if(m[j]<m[j+1]){
continue;
}
else {
while(m[j]>=m[j+1]){
m[j+1]+=g;
t++;
}
}
}
cout<<t;
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <cmath>
#include <sstream>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>

using namespace std;

const int NMAX = 110000;

int m[NMAX];

int main()
{
	int a, b, t = 0;
	cin >> a >> b;
	for (int j = 0; j < a; j++)cin >> m[j];

	for (int j = 0; j < a-1; j++){

		if (m[j] >= m[j + 1]){
			while (m[j] >= m[j + 1]){

				m[j + 1] += b;
				t++;
			}

		}

	}
	cout << t;
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <cmath>
#include <sstream>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <algorithm>

using namespace std;

int main()
{

ios_base::sync_with_stdio(false);
long long m[4000]={0};
int n,g,t=0;
cin>>n>>g;
for(int j=0;j<n;j++)cin>>m[j];

for(int j=0;j<n-1;j++){
if(m[j]<m[j+1]){
continue;
}
else {
while(m[j]>=m[j+1]){
m[j+1]+=g;
t++;
}
}
}
cout<<t;
return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

__int64 a[3000];

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    int n, d;
    cin >> n >> d;

    for (int i = 0; i < n; i++)
        cin >> a[i];

    int res = 0;
    for (int i = 1; i < n; i++) {
        if (a[i-1] >= a[i]) {
            int h = ((a[i-1]-a[i])/d == 0) + (a[i-1]-a[i])/d + ((a[i-1]-a[i])%d != 0);

            a[i] += h*d;
            res += h;
        }
    }

    cout << res;

    return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

__int64 a[3000];

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    int n, d;
    cin >> n >> d;

    for (int i = 0; i < n; i++)
        cin >> a[i];

    int res = 0;
    for (int i = 1; i < n; i++) {
        if (a[i-1] >= a[i]) {
            int h = (a[i-1]-a[i])/d + 1;

            a[i] += h*d;
            res += h;
        }
    }

    cout << res;

    return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

__int64 a[3000];

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    int n, d;
    cin >> n >> d;

    for (int i = 0; i < n; i++)
        cin >> a[i];

    int res = 0;
    for (int i = 1; i < n; i++) {
        if (a[i-1] >= a[i]) {
            int h = (a[i-1]-a[i])/d + (a[i-1]-a[i]%d != 0);

            a[i] += h*d;
            res += h;
        }
    }

    cout << res;

    return 0;
}


#include <stdio.h>

int main()
{
    int b = 0, n = 0, count = 0;
    long int k = 0, d = 0, Posl[2001];

    for (int a = 0; a <= 2000; a++)
        Posl[a] = 0;

    scanf("%d %d", &n, &d);

    for (int i = 0; i < n; i++)
        scanf("%d", &Posl[i]);

    do
    {
        if (Posl[b + 1] <= Posl[b])
        {
            k = (Posl[b] - Posl[b + 1]) / d;
            Posl[b + 1] += k*d + d;
            count += k + 1;
        }
        else b++;
    }
    while ((Posl[b + 1] != 0) && (b != 2000));

    printf("%d", count);
    return 0;
}


#include <stdio.h>

int main()
{
    int b = 0, n = 0, count = 0;
    long int k = 0, d = 0, Posl[2001];

    for (int a = 0; a < 2000; a++)
        Posl[a] = 0;

    scanf("%d %d", &n, &d);

    for (int i = 0; i < n; i++)
        scanf("%d", &Posl[i]);

    do
    {
        if (Posl[b + 1] <= Posl[b])
        {
            k = (Posl[b] - Posl[b + 1]) / d;
            Posl[b + 1] += k*d + d;
            count += k + 1;
        }
        else b++;
    }
    while ((Posl[b + 1] != 0) && (b != 2000));

    printf("%d", count);
    return 0;
}


#include <stdio.h>

int main()
{
    int b = 0, n = 0, count = 0;
    long int d = 0, Posl[2001];

    scanf("%d %d", &n, &d);

    for (int i = 0; i < n; i++)
        scanf("%d", &Posl[i]);

    do
    {
        if (Posl[b + 1] <= Posl[b])
        {
            Posl[b + 1] += d;
            count++;
        }
        else b++;
    }
    while ((Posl[b + 1] > 0) && (b != 2000));

    printf("%d", count);
    return 0;
}


#include <stdio.h>

int main()
{
    int b = 0, n = 0, count = 0;
    long int d = 0, Posl[2001];

    scanf("%d %d", &n, &d);

    Posl[2000] = 0;

    for (int i = 0; i < n; i++)
        scanf("%d", &Posl[i]);

    do
    {
        if (Posl[b + 1] <= Posl[b])
        {
            Posl[b + 1] += d;
            count++;
        }
        else b++;
    }
    while ((Posl[b + 1] > 0) && (b != 2000));

    printf("%d", count);
    return 0;
}


#include <stdio.h>

int main()
{
    int b = 0, n = 0, count = 0;
    long int d = 0, Posl[2001];

    for (int a = 0; a < 2000; a++)
        Posl[a] = 0;

    scanf("%d %d", &n, &d);

    for (int i = 0; i < n; i++)
        scanf("%d", &Posl[i]);

    do
    {
        if (Posl[b + 1] <= Posl[b])
        {
            Posl[b + 1] += d;
            count++;
        }
        else b++;
    }
    while ((Posl[b + 1] != 0) && (b != 2000));

    printf("%d", count);
    return 0;
}


#include<iostream>
#include<vector>
using namespace std;

int main(){
	int n,d;
	cin>>n>>d;

	int pre = -1;
	int count = 0;

	int tmp;
	for(int i=0;i<n;i++){
		cin>>tmp;
		if(-1 != pre && pre >= tmp){
			while(pre >= tmp){
				tmp+=d;
				count++;
			}
		}
		pre = tmp;
	}

	cout<<count<<endl;
	return 0;
}


#include<iostream>
#include<vector>
using namespace std;

int main(){
	int n,d;
	cin>>n>>d;

	int pre = -1;
	int count = 0;

	int tmp,num;
	for(int i=0;i<n;i++){
		cin>>tmp;
		if(-1 != pre && pre >= tmp){
			num  = (pre-tmp)/2 + 1;
			count+= num;
			tmp+=num*d;
		}
		pre = tmp;
	}

	cout<<count<<endl;
	return 0;
}


#include<iostream>
#include<vector>
using namespace std;

int main(){
	int n,d;
	cin>>n>>d;

	int pre = -1;
	int count = 0;

	int tmp,num;
	for(int i=0;i<n;i++){
		cin>>tmp;
		if(-1 != pre && pre >= tmp){
			num  = (pre-tmp)/d + 1;
			count+= num;
			tmp+=num*d;
		}
		pre = tmp;
	}

	cout<<count<<endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<set>
#include<list>
#include<map>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<sstream>
#include<time.h>
#include<numeric>
#include<functional>
#include<assert.h>
#include<stdio.h>

using namespace std;
#define INF  ((1 << 31) - 1)
#define eps 1e-9
#define PI 3.14159265358979323846
#define sz(v) ((int)(v).size())
#define MP make_pair
#define PB push_back
#define all(v) (v).begin(), (v).end()
typedef long long ll;

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ll n, d, tmp, res = 0;
	cin >> n >> d;
	vector<ll> v;
	for (int i = 0; i < n; ++i){
		cin >> tmp;
		v.push_back(tmp);
	}
	for (int i = 1; i < n; ++i){
		ll t = (v[i - 1] - v[i] + d) / d;
		res += t;
		v[i] += t * d;
	}
	cout << res << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<set>
#include<list>
#include<map>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<sstream>
#include<time.h>
#include<numeric>
#include<functional>
#include<assert.h>
#include<stdio.h>

using namespace std;
#define INF  ((1 << 31) - 1)
#define eps 1e-9
#define PI 3.14159265358979323846
#define sz(v) ((int)(v).size())
#define MP make_pair
#define PB push_back
#define all(v) (v).begin(), (v).end()
typedef long long ll;

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ll n, d, res = 0;
	double tmp;
	cin >> n >> d;
	vector<double> v;
	for (int i = 0; i < n; ++i){
		cin >> tmp;
		v.push_back(tmp);
	}
	for (int i = 1; i < n; ++i){
		ll t = floor((v[i - 1] - v[i] + d) / d);
		res += t;
		v[i] += t * d;
	}
	cout << res << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<set>
#include<list>
#include<map>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<sstream>
#include<time.h>
#include<numeric>
#include<functional>
#include<assert.h>
#include<stdio.h>

using namespace std;
#define INF  ((1 << 31) - 1)
#define eps 1e-9
#define PI 3.14159265358979323846
#define sz(v) ((int)(v).size())
#define MP make_pair
#define PB push_back
#define all(v) (v).begin(), (v).end()
typedef long long ll;

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ll n, d, res = 0, tmp;
	cin >> n >> d;
	vector<ll> v;
	for (int i = 0; i < n; ++i){
		cin >> tmp;
		v.push_back(tmp);
	}
	for (int i = 1; i < n; ++i){
		ll t = max((v[i - 1] - v[i] + d) / d, 0LL);
		res += t;
		v[i] += t * d;
	}
	cout << res << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
vector<long long>v;
int main()
{
	long long n,m,i,p,d,co;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>p;
		v.push_back(p);
	}
	long long ma;
	co=0;
	for(i=1;i<v.size();i++)
	{
		ma=v[i-1];
		if(v[i]<=ma)
		{

			long long f=abs(v[i]-ma)+1;
			if(f%m!=0)
				f=f+1;
			co=co+(f/m);
			v[i]=v[i]+f;

		}
	}
	cout<<co<<"\n";

}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
vector<long long>v;
int main()
{
	long long n,m,i,p,d,co,j,u;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>p;
		v.push_back(p);
	}
	long long ma;
	co=0;
	for(i=1;i<v.size();i++)
	{
		ma=v[i-1];
		if(v[i]<=ma)
		{

			long long f=abs(v[i]-ma)+1;
			for(j=1; ;j++)
			{
				u=j*(j+1);
				u=u/2;
				if(m*u>=f)
				{
					u=u*m;
					break;
				}
			}
			co=co+j;
			v[i]=v[i]+u;

		}
	}
	cout<<co<<"\n";
}


#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
vector<long long>v;
int main()
{
	long long n,m,i,p;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>p;
		v.push_back(p);
	}
	int ch=0,co=0;
	while(1)
	{
		ch=0;
		for(i=0;i<v.size()-1;i++)
		{
			if(v[i+1]<=v[i])
			{
				co++;
				v[i+1]=v[i+1]+m;
				ch=1;
			}
		}
		if(ch==1)
		{

		}
		else
			break;
	}

	cout<<co<<"\n";

}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
vector<long long>v;
int main()
{
	long long n,m,i,p,d,co,j,u;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>p;
		v.push_back(p);
	}
	long long ma;
	co=0;
	for(i=1;i<v.size();i++)
	{
		ma=v[i-1];
		if(v[i]<=ma)
		{

			long long f=abs(v[i]-ma)+1;
			f=max(f,m);
			if(f%m!=0)
			{
				f=f+(f%m);
			}
			co=co+(f/m);
			v[i]=v[i]+f;

		}
	}
	cout<<co<<"\n";
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
vector<long long>v;
int main()
{
	long long n,m,i,p,d,co,j,u;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>p;
		v.push_back(p);
	}
	long long ma;
	co=0;
	for(i=1;i<v.size();i++)
	{
		ma=v[i-1];
		if(v[i]<=ma)
		{
			d=ma+m;
			long long diff=(d-v[i]);
			long long l=(diff/m);
			if(diff%m!=0)
				l=l+1;
			co=co+l;
			v[i]=v[i]+l*m;
			while(v[i]-m>ma){

				v[i]=v[i]-m;
				co--;
			}

		}
	}
	cout<<co<<"\n";
	/*for(i=0;i<v.size();i++)
	{
		cout<<v[i]<<" ";
	}*/
}


#include <iostream>

using namespace std;

int main()
{
    int n, *a, count=0, d, x;

    cin >> n >> d;

    a = new int [n];

    for(int i=0; i<n; i++)
        cin >> a[i];

    for(int i=0; i<n-1; i++)
        if(a[i+1]<=a[i])
            {
                x=((a[i]-a[i+1])/d)+1;
                count+=x;
                a[i+1]+=x*d;
            }

    cout << count;

}


#include <iostream>
using namespace std;
int main ()
{
    int n,d,*a,count=0;
    bool p=true;
cin>>n>>d;
a=new int [n];
for (int i=0;i<n;i++)
    cin>>a[i];

while (p)
{
    p=false;
for (int i=0;i<n;i++)
  { if (a[i]<=a[i-1])
    {p=true;a[i]+=d;count++;

}

  }
}
cout<<count;

return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n,d,*a,count=0,l=0;
    bool p=true;
cin>>n>>d;
a=new int [n];
for (int i=0;i<n;i++)
    cin>>a[i];

while (p)
{
    p=false;
for (int i=l;i<n;i++)
  { if (a[i]<=a[i-1])
    {p=true;a[i]+=d;count++;
if (count==1)
    l=i;
}

  }
}
cout<<count;

return 0;
}


#include <iostream>
using namespace std;
int main ()
{
long n,d,count=0;
cin>>n>>d;
int *a=new int [n];
for (int i=0;i<n;i++)
	cin>>a[i];
for (int i=1;i<n;i++)
{
	if (a[i]<=a[i-1])
	{a[i]+=d;count++;}
	if (a[i]<=a[i-1])
		i--;

}
cout<<count;
return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n,d,*a,count=0,l=0;
    bool p=true;
cin>>n>>d;
a=new int [n];
for (int i=0;i<n;i++)
    cin>>a[i];

while (p)
{
    p=false;
for (int i=l;i<n;i++)
  { if (a[i]<=a[i-1])
    {p=true;a[i]+=d;count++;l=i;}

  }
}
cout<<count;
return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n,d,*a,count=0;
    bool p=true;
cin>>n>>d;
a=new int [n];
for (int i=0;i<n;i++)
    cin>>a[i];

while (p)
{
    p=false;
for (int i=1;i<n;i++)
  { if (a[i]<=a[i-1])
    {p=true;a[i]+=d;count++;}

  }
}
cout<<count;
return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n,d,*a,count=0,l=0;
    bool p=true;
cin>>n>>d;
a=new int [n];
for (int i=0;i<n;i++)
    cin>>a[i];

while (p)
{
    p=false;
for (int i=l;i<n;i++)
  { if (a[i]<=a[i-1])
    {p=true;a[i]+=d;count++;
if (count==1)
    l=i+1;
}

  }
}
cout<<count;

return 0;
}


#include <iostream>
using namespace std;
int main ()
{
long n,d,count=0;
cin>>n>>d;
int *a=new int [n];
cin>>a[0];
for (int i=1;i<n;i++)
	{
		cin>>a[i];
	while(a[i]<=a[i-1])
	{a[i]+=d;count++;}
}
cout<<count;

return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n,d,*a,count=0;
    bool p=true;
cin>>n>>d;
a=new int [n];
for (int i=0;i<n;i++)
    cin>>a[i];

while (p)
{
    p=false;
for (int i=1;i<n;i++)
  { if (a[i]<=a[i-1])
    {p=true;a[i]+=d;count++;}

  }
}
cout<<count;

return 0;
}


#include <iostream>
using namespace std;
int main ()
{
    int n,d,*a,count=0;
    bool p=true;
cin>>n>>d;
a=new int [n];
for (int i=0;i<n;i++)
    cin>>a[i];

while (p)
{

    p=false;
for (int i=0;i<n;i++)
  { if (a[i]<=a[i-1])
    {p=true;a[i]+=d;count++;

}

  }
}
cout<<count;

return 0;
}


#include <iostream>
using namespace std;
int main ()
{
	int n,d,*a,count=0;
	bool p=true;
cin>>n>>d;
a=new int [n];
for (int i=0;i<n;i++)
	cin>>a[i];

while (p)
{
	p=false;
for (int i=0;i<n;i++)
  {	if (a[i]<=a[i-1])
	{p=true;a[i]+=d;count++;

}

  }
}
cout<<count;

return 0;
}


#include <iostream>
using namespace std;
int main ()
{
long n,d,count=0;
cin>>n>>d;
int *a=new int [n];
for (int i=0;i<n;i++)
	{
		cin>>a[i];
	while(a[i]<=a[i-1])
	{a[i]+=d;count++;}
}
cout<<count;
return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

void main()
{
    int c=0;
    int n,d;
    cin>>n;
    cin>>d;
    int * mas=new int[n+1];
    for (int h=0;h<n;h++)
    {
        cin>>mas[h];
    }
    mas[n+1]=mas[n]+1;
    int i=0;
    while(i<n-1)
    {
        if(mas[i+1]<=mas[i]){mas[i+1]=mas[i+1]+d;c++;i=i-1;}
        i++;
    }
    //for(int i=0;i<n;i++)
    //{
    //  cout<<mas[i]<<endl;
    //}
    cout<<c;

}