#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <complex>
#include <bitset>
#include <cmath>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<pii, int> piii;
typedef pair<pll, ll> plll;
typedef pair<pdd, double> pddd;
typedef complex<double> cpx;
#define mst(x,v) memset(x,v,sizeof(x))
#define rgs register
#define rp(k,x,v) for(rgs int k = x;k<v;++k)
#define rps(s) for(rgs int i = 0;s[i];++i)
#define RP(k,x,v) for(rgs int k = x;k<=v;++k)
#define lp(k,x,v) for(rgs int k = x;k>v;--k)
#define LP(k,x,v) for(rgs int k = x;k>=v;--k)
#define lowbit(x) (x&-x)
#define adde(u,v) edg[++ecnt]=Edge(u,v,g[u]),g[u]=ecnt
#define addew(u,v,w) edg[++ecnt]=Edge(u,v,g[u],w),g[u]=ecnt
#define addedg(u,v,w,cap) edg[++ecnt]=Edge(u,v,g[u],w,cap),g[u]=ecnt,edg[++ecnt]=Edge(v,u,g[v],-w,0),g[v]=ecnt
#define fson(x) for(rgs int i = g[x];~i;i=edg[i].next)
#define LB lower_bound
#define UB upper_bound
#define inp(n,a) RP(i,1,n) ru(a[i]);
#define mpt int mid = l+r>>1;
#define all(a) a.begin(),a.end()
#define inr (ql<=l && r<=qr)
#define upmax(a,b) a=max(a,b)
#define upmin(a,b) a=min(a,b)
const int INF = 1 << 29;
const ll LINF = 1LL << 60;
const double inf = 1e15;
ll mod = 1e9 + 7;
char READ_DATA;
int SIGNAL_INPUT;
template <typename Type>
inline Type ru(Type &v)
{
	SIGNAL_INPUT = 1;
	while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
		if (READ_DATA == '-')
			SIGNAL_INPUT = -1;
		else if (READ_DATA == EOF)
			return EOF;
	v = READ_DATA - '0';
	while ((READ_DATA = getchar()) >= '0' && READ_DATA <= '9')
		v = v * 10 + READ_DATA - '0';
	v *= SIGNAL_INPUT;
	return v;
}
inline ll modru(ll &v)
{
	ll p = 0;
	SIGNAL_INPUT = 1;
	while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
		if (READ_DATA == '-')
			SIGNAL_INPUT = -1;
		else if (READ_DATA == EOF)
			return EOF;
	p = v = READ_DATA - '0';
	while ((READ_DATA = getchar()) >= '0' && READ_DATA <= '9')
	{
		v = (v * 10 + READ_DATA - '0') % mod;
		p = (p * 10 + READ_DATA - '0') % (mod - 1);
	}
	v *= SIGNAL_INPUT;
	return p;
}
template<typename A, typename B > inline char ru(A&x, B&y) { if (ru(x) == EOF) return EOF; ru(y); return 2; }
template<typename A, typename B, typename C>inline char ru(A&x, B&y, C&z) { if (ru(x) == EOF) return EOF; ru(y); ru(z); return 3; }
template<typename A, typename B, typename C, typename D>inline char ru(A&x, B&y, C&z, D&w) { if (ru(x) == EOF) return EOF; ru(y); ru(z); ru(w); return 4; }

struct Edge
{
	int  u, v, next;
	ll w, cap, flow;
	Edge(int _u = 0, int _v = 0, int nxt = -1, ll _w = 1, ll _cap = 0)
	{
		u = _u;
		v = _v;
		w = _w;
		cap = _cap;
		flow = 0;
		next = nxt;
	}

	int operator<(const Edge &b) const
	{
		return w < b.w;
	}
};

const int maxn = 1e3 + 10, N = 2e6 + 1;
double eps = 1e-7, pi = acos(-1.0);
ull seed = 131, smod = (1LL << 32) - 267;

int a, b, n, y, minv, ans;
vector<int> x, tmp;

int main()
{
	ru(n);
	while (n--)
	{
		ru(y);
		x.push_back(y);
	}
	sort(all(x));
	unique(all(x));
	ru(a, b);
	while (a != b)
	{
		minv = a - 1;
		rp(i, 0, x.size())
		{
			y = a - a%x[i];
			if (y >= b)
			{
				upmin(minv, y);
				tmp.push_back(x[i]);
			}
		}
		a = minv;
		x.clear();
		rp(i, 0, tmp.size()) if(a-a%tmp[i]>=b)
			x.push_back(tmp[i]);
		tmp.clear();
		++ans;
	}
	cout << ans;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 1000100;

int x[N], pos[N];
struct segtree {
	int seg[4*N+1], n, k, r, a, b;
	segtree () { }
	segtree (int n) : n(n) {
		memset (seg, INF, sizeof seg);
	}
	int query (int r, int i, int j) {
		if (i > b or j < a) return INF;
		if (i >= a and j <= b) return seg[r] = min(seg[r], k);
		int mid = (i + j) / 2;
		int le = query(r*2, i, mid);
		int ri = query(r*2+1, mid+1, j);
		seg[r] = min(seg[r*2], seg[r*2+1]);
		return min(le, ri);
	}
	int query (int x, int y) {
		a = x; b = y; k = INF;
		return query(1, 0, n);
	}
	void update (int x, int y) {
		a = b = x; k = y;
		query(1, 0, n);
	}
} st;
int main (void) {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", x+i);
	int a, b; cin >> a >> b;
	swap (a, b);
	sort(x, x+n);
	for (int i = 0; i < n; i++) {
	    if (i and x[i] == x[i-1]) continue;
		int prev = (a/x[i]) * x[i];
		for (int at = prev; at <= b; at += x[i]) {
			if (at < a) continue;
			pos[at - a] = x[i];
		}
	}
	st = segtree (b-a+1);
	st.update(b-a, 0);
	for (int x = b-1; x >= a; x--) {
		if (!pos[x-a]) {
			st.update(x-a, st.query(x-a+1, x-a+1)+1);
			continue;
		}
		int r = min(b-a, x-a + pos[x-a] - 1);
		st.update(x-a, st.query(x-a+1, r)+1);
	}
	cout << st.query(0, 0) << endl;
	return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 1000100;

int x[N], pos[N];
int dp[N];
int main (void) {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", x+i);
	int a, b; cin >> a >> b;
	swap (a, b);
	sort(x, x+n);
	for (int i = 0; i < n; i++) {
		if (i and x[i] == x[i-1]) continue;
		int prev = (a/x[i]) * x[i];
		for (int at = prev; at <= b; at += x[i]) {
			if (at < a) continue;
			pos[at - a] = x[i];
		}
	}
	deque <pii> d;
	d.emplace_front(0, b);
	dp[b-a] = 0;
	for (int x = b-1; x >= a; x--) {
		if (!pos[x-a]) {
			dp[x-a] = dp[x-a+1] + 1;
			d.emplace_front(dp[x-a], x);
			continue;
		}
		int lo = 0, hi = d.size() - 1, ans = -1;
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (d[mid].se > x + pos[x-a] - 1) hi = mid-1;
			else {
				ans = mid;
				lo = mid+1;
			}
		}
		int ret = d[ans].fi;
		dp[x-a] = ret + 1;
		while (!d.empty() and d.front().fi >= dp[x-a]) d.pop_front();
		d.emplace_front(dp[x-a], x);
	}
	cout << dp[0] << endl;
	return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 100010;

int x[N], pos[N];
int dp[N];
int main (void) {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", x+i);
	int a, b; cin >> a >> b;
	swap (a, b);
	sort(x, x+n);
	for (int i = 0; i < n; i++) {
		int prev = (a/x[i]) * x[i];
		for (int at = prev; at <= b; at += x[i]) {
			if (at < a) continue;
			pos[at - a] = x[i];
		}
	}
	deque <pii> d;
	d.emplace_front(0, b);
	dp[b-a] = 0;
	for (int x = b-1; x >= a; x--) {
		if (!pos[x-a]) {
			dp[x-a] = dp[x-a+1] + 1;
			d.emplace_front(dp[x-a], x);
			continue;
		}
		int lo = 0, hi = d.size() - 1, ans = -1;
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (d[mid].se > x + pos[x-a] - 1) hi = mid-1;
			else {
				ans = mid;
				lo = mid+1;
			}
		}
		int ret = d[ans].fi;
		dp[x-a] = ret + 1;
		while (!d.empty() and d.front().fi >= dp[x-a]) d.pop_front();
		d.emplace_front(dp[x-a], x);
	}
	cout << dp[0] << endl;
	return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 1000100;

int x[N], pos[N];
struct segtree {
	int seg[4*N+1], n, k, r, a, b;
	segtree () { }
	segtree (int n) : n(n) {
		memset (seg, INF, sizeof seg);
	}
	int query (int r, int i, int j) {
		if (i > b or j < a) return INF;
		if (i >= a and j <= b) return seg[r] = min(seg[r], k);
		int mid = (i + j) / 2;
		int le = query(r*2, i, mid);
		int ri = query(r*2+1, mid+1, j);
		seg[r] = min(seg[r*2], seg[r*2+1]);
		return min(le, ri);
	}
	int query (int x, int y) {
		a = x; b = y; k = INF;
		return query(1, 0, n);
	}
	void update (int x, int y) {
		a = b = x; k = y;
		query(1, 0, n);
	}
} st;
int main (void) {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", x+i);
	int a, b; cin >> a >> b;
	swap (a, b);
	sort(x, x+n);
	for (int i = 0; i < n; i++) {
		int prev = (a/x[i]) * x[i];
		for (int at = prev; at <= b; at += x[i]) {
			if (at < a) continue;
			pos[at - a] = x[i];
		}
	}
	st = segtree (b-a+1);
	st.update(b-a, 0);
	for (int x = b-1; x >= a; x--) {
		if (!pos[x-a]) {
			st.update(x-a, st.query(x-a+1, x-a+1)+1);
			continue;
		}
		int r = min(b-a, x-a + pos[x-a] - 1);
		st.update(x-a, st.query(x-a+1, r)+1);
	}
	cout << st.query(0, 0) << endl;
	return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 100010;

int x[N], pos[N];
int dp[N];
int main (void) {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", x+i);
	int a, b; cin >> a >> b;
	swap (a, b);
	sort(x, x+n);
	for (int i = 0; i < n; i++) {
		int prev = (a/x[i]) * x[i];
		for (int at = prev; at <= b; at += x[i]) {
			if (at < a) continue;
			pos[at - a] = x[i];
		}
	}
	st = segtree (b-a+1);
	st.update(b-a, 0);
	deque <pii> d;
	d.emplace_front(0, b);
	dp[b-a] = 0;
	for (int x = b-1; x >= a; x--) {
		if (!pos[x-a]) {
			dp[x-a] = dp[x-a+1] + 1;
			d.emplace_front(dp[x-a], x);
			continue;
		}
		int lo = 0, hi = d.size() - 1, ans = -1;
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (d[mid].se > x + pos[x-a] - 1) hi = mid-1;
			else {
				ans = mid;
				lo = mid+1;
			}
		}
		int ret = d[ans].fi;
		dp[x-a] = ret + 1;
		while (!d.empty() and d.front().fi >= dp[x-a]) d.pop_front();
		d.emplace_front(dp[x-a], x);
	}
	cout << dp[0] << endl;
	return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 0x3f3f3f3f

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 1000100;

int x[N], pos[N];
int dp[N];
int main (void) {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", x+i);
	int a, b; cin >> a >> b;
	swap (a, b);
	sort(x, x+n);
	for (int i = 0; i < n; i++) {
		int prev = (a/x[i]) * x[i];
		for (int at = prev; at <= b; at += x[i]) {
			if (at < a) continue;
			pos[at - a] = x[i];
		}
	}
	deque <pii> d;
	d.emplace_front(0, b);
	dp[b-a] = 0;
	for (int x = b-1; x >= a; x--) {
		if (!pos[x-a]) {
			dp[x-a] = dp[x-a+1] + 1;
			d.emplace_front(dp[x-a], x);
			continue;
		}
		int lo = 0, hi = d.size() - 1, ans = -1;
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (d[mid].se > x + pos[x-a] - 1) hi = mid-1;
			else {
				ans = mid;
				lo = mid+1;
			}
		}
		int ret = d[ans].fi;
		dp[x-a] = ret + 1;
		while (!d.empty() and d.front().fi >= dp[x-a]) d.pop_front();
		d.emplace_front(dp[x-a], x);
	}
	cout << dp[0] << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 1000005
#define mins 1005
#define eps 1e-14
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound

int tree[4*maxs],arr[maxs];
ll vals[maxs];

void update(int node,int a,int b,int i,int val){
	if(a==b){
		tree[node]=val;
		return ;
	}
	int mid=(a+b)/2;
	if(i<=mid){
		update(node*2,a,(a+b)/2,i,val);
	}
	else{
		update(node*2+1,(a+b)/2+1,b,i,val);
	}
	tree[node]=min(tree[node*2],tree[node*2+1]);
}

int query(int node,int a,int b,int i,int j){
	if(a>b || a>j || b<i){
		return imax;
	}
	if(a>=i && b<=j){
		return tree[node];
	}
	int q1=query(node*2,a,(a+b)/2,i,j);
	int q2=query(node*2+1,(a+b)/2+1,b,i,j);
	return min(q1,q2);
}

set<int>st;
int main()
{
	int n,i,j,k,a,b;
	sc("%d",&n);
	for(i=0;i<n;i++){
		sc("%d",&arr[i]);
		st.insert(arr[i]);
	}
	int cn=0;
	for(siter it=st.begin();it!=st.end();it++){
		arr[cn++]=*it;
	}
	sc("%d %d",&a,&b);
	int rem=(a-b);
	for(i=0;i<=rem;i++){
		vals[i]=i+1;
	}
	for(i=0;i<cn;i++){
		int t1=b/arr[i];
		if((b%arr[i])!=0){
			t1++;
		}
		ll req=t1*arr[i];
		while(req<=(ll)a){
			vals[req-b]=max((ll)vals[req-b],req+arr[i]-1-b);
			req+=arr[i];
		}
	}
	int ans;
	update(1,0,rem,rem,0);
	for(i=rem-1;i>=0;i--){
		int val=query(1,0,rem,i+1,min((int)vals[i],rem));
		update(1,0,rem,i,val+1);
		ans=val+1;
	}
	pr("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 1000005
#define mins 1005
#define eps 1e-14
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound

int tree[4*maxs],arr[maxs];
ll vals[maxs];

void update(int node,int a,int b,int i,int val){
	if(a==b){
		tree[node]=val;
		return ;
	}
	int mid=(a+b)/2;
	if(i<=mid){
		update(node*2,a,(a+b)/2,i,val);
	}
	else{
		update(node*2+1,(a+b)/2+1,b,i,val);
	}
	tree[node]=min(tree[node*2],tree[node*2+1]);
}

int query(int node,int a,int b,int i,int j){
	if(a>b || a>j || b<i){
		return imax;
	}
	if(a>=i && b<=j){
		return tree[node];
	}
	int mid=(a+b)/2;
	if(j<=mid){
		return query(node*2,a,mid,i,j);
	}
	else if(i>=(mid+1)){
		return query(node*2+1,mid+1,b,i,j);
	}
	int q1=query(node*2,a,(a+b)/2,i,j);
	int q2=query(node*2+1,(a+b)/2+1,b,i,j);
	return min(q1,q2);
}

set<int>st;
int main()
{
	int n,i,j,k,a,b;
	sc("%d",&n);
	for(i=0;i<n;i++){
		sc("%d",&arr[i]);
	//	arr[i]=i+2;
		st.insert(arr[i]);
	}
	int cn=0;
	for(siter it=st.begin();it!=st.end();it++){
		arr[cn++]=*it;
	}
	sc("%d %d",&a,&b);
	int rem=(a-b);
	for(i=0;i<=rem;i++){
		vals[i]=1;
	}
	for(i=0;i<cn;i++){
		int t1=b/arr[i];
		if((b%arr[i])!=0){
			t1++;
		}
		ll req=t1*arr[i];
		int t2=arr[i]-1;
		while(req<=(ll)a){
			vals[req-b]=t2;
			req+=arr[i];
		}
	}
	int ans;
	update(1,0,rem,rem,0);
	for(i=rem-1;i>=0;i--){
		int val=query(1,0,rem,i+1,min((int)(vals[i]+i),rem));
		update(1,0,rem,i,val+1);
		ans=val+1;
	}
	pr("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 1000005
#define mins 1005
#define eps 1e-14
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound

int tree[4*maxs],arr[maxs],vals[maxs];

void update(int node,int a,int b,int i,int val){
	if(a==b){
		tree[node]=val;
		return ;
	}
	int mid=(a+b)/2;
	if(i<=mid){
		update(node*2,a,(a+b)/2,i,val);
	}
	else{
		update(node*2+1,(a+b)/2+1,b,i,val);
	}
	tree[node]=min(tree[node*2],tree[node*2+1]);
}

int query(int node,int a,int b,int i,int j){
	if(a>b || a>j || b<i){
		return imax;
	}
	if(a>=i && b<=j){
		return tree[node];
	}
	int q1=query(node*2,a,(a+b)/2,i,j);
	int q2=query(node*2+1,(a+b)/2+1,b,i,j);
	return min(q1,q2);
}

set<int>st;
int main()
{
	int n,i,j,k,a,b;
	sc("%d",&n);
	for(i=0;i<n;i++){
		sc("%d",&arr[i]);
		st.insert(arr[i]);
	}
	int cn=0;
	for(siter it=st.begin();it!=st.end();it++){
		arr[cn++]=*it;
	}
	sc("%d %d",&a,&b);
	int rem=(a-b);
	for(i=0;i<=rem;i++){
		vals[i]=i+1;
	}
	for(i=0;i<cn;i++){
		int t1=b/arr[i];
		if((b%arr[i])!=0){
			t1++;
		}
		int req=t1*arr[i];
		while(req<=a){
			vals[req-b]=max(vals[req-b],req+arr[i]-1-b);
			req+=arr[i];
		}
	}
	for(i=0;i<4*rem;i++){
		tree[i]=imax;
	}
	int ans;
	update(1,0,rem,rem,0);
	for(i=rem-1;i>=0;i--){
		int val=query(1,0,rem,i+1,min(vals[i],rem));
		update(1,0,rem,i,val+1);
		ans=val+1;
	}
	pr("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 1000005
#define mins 1005
#define eps 1e-14
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound

int tree[4*maxs],arr[maxs],vals[maxs];

void update(int node,int a,int b,int i,int val){
	if(a==b){
		tree[node]=val;
		return ;
	}
	int mid=(a+b)/2;
	if(i<=mid){
		update(node*2,a,(a+b)/2,i,val);
	}
	else{
		update(node*2+1,(a+b)/2+1,b,i,val);
	}
	tree[node]=min(tree[node*2],tree[node*2+1]);
}

int query(int node,int a,int b,int i,int j){
	if(a>b || a>j || b<i){
		return imax;
	}
	if(a>=i && b<=j){
		return tree[node];
	}
	int q1=query(node*2,a,(a+b)/2,i,j);
	int q2=query(node*2+1,(a+b)/2+1,b,i,j);
	return min(q1,q2);
}

int main()
{
	int n,i,j,k,a,b;
	sc("%d",&n);
	for(i=0;i<n;i++){
		sc("%d",&arr[i]);
	}
	sc("%d %d",&a,&b);
	int rem=(a-b);
	for(i=0;i<=rem;i++){
		vals[i]=i+1;
	}
	for(i=0;i<n;i++){
		int t1=b/arr[i];
		if((b%arr[i])!=0){
			t1++;
		}
		int req=t1*arr[i];
		while(req<=a){
			vals[req-b]=max(vals[req-b],req+arr[i]-1-b);
			req+=arr[i];
		}
	}
	for(i=0;i<4*rem;i++){
		tree[i]=imax;
	}
	int ans;
	update(1,0,rem,rem,0);
	for(i=rem-1;i>=0;i--){
		int val=query(1,0,rem,i+1,min(vals[i],rem));
		update(1,0,rem,i,val+1);
		ans=val+1;
	}
	pr("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Numeric Constants
#define N 1000000007
#define maxs 1000005
#define mins 1005
#define eps 1e-14
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound

int tree[4*maxs],arr[maxs];
int vals[maxs];

void update(int node,int a,int b,int i,int val){
	if(a==b){
		tree[node]=val;
		return ;
	}
	int mid=(a+b)/2;
	if(i<=mid){
		update(node*2,a,(a+b)/2,i,val);
	}
	else{
		update(node*2+1,(a+b)/2+1,b,i,val);
	}
	tree[node]=min(tree[node*2],tree[node*2+1]);
}

int query(int node,int a,int b,int i,int j){
	if(a>b || a>j || b<i){
		return imax;
	}
	if(a>=i && b<=j){
		return tree[node];
	}
	int mid=(a+b)/2;
	if(j<=mid){
		return query(node*2,a,mid,i,j);
	}
	else if(i>=(mid+1)){
		return query(node*2+1,mid+1,b,i,j);
	}
	int q1=query(node*2,a,mid,i,j);
	int q2=query(node*2+1,mid+1,b,i,j);
	return min(q1,q2);
}

set<int>st;
int main()
{
	int n,i,j,k,a,b;
	sc("%d",&n);
	for(i=0;i<n;i++){
		sc("%d",&arr[i]);
		st.insert(arr[i]);
	}
	int cn=0;
	for(siter it=st.begin();it!=st.end();it++){
		arr[cn++]=*it;
	}
	sc("%d %d",&a,&b);
	int rem=(a-b);
	for(i=0;i<=rem;i++){
		vals[i]=1;
	}
	for(i=0;i<cn;i++){
		int t1=b/arr[i];
		if((b%arr[i])!=0){
			t1++;
		}
		int req=t1*arr[i];
		int t2=arr[i]-1;
		while(req<=(ll)a){
			vals[req-b]=t2;
			req+=arr[i];
		}
	}
	int ans=0;
	update(1,0,rem,rem,0);
	for(i=rem-1;i>=0;i--){
		int val=query(1,0,rem,i+1,min((vals[i]+i),rem));
		update(1,0,rem,i,val+1);
		ans=val+1;
	}
	pr("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using std::cin;
using std::cout;

inline void up(int &x, int y) { x < y ? x = y : 0; }
inline void down(int &x, int y) { x > y ? x = y : 0; }
inline int max(const int x, const int y) { return x > y ? x : y; }
inline int min(const int x, const int y) { return x < y ? x : y; }

int n, x[100005], ret, A, B, ans;
int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> x[i];
    std::sort(x + 1, x + n + 1);
    n = std::unique(x + 1, x + n + 1) - x - 1;
    cin >> A >> B;
    while (A > B) {
    	++ans;
    	ret = A - 1;
    	for (int i = n; i; --i)
    		if (A - A % x[i] >= B) down(ret, A - A % x[i]);
		A = ret;
		if (n > 0) {
			for (int i = n; i; --i)
				if (A - A % x[i] < B) --n;
				else break;
		}

		if (n == 0) A = B, ans += A - B;
		if (A == B) break;

	}
	cout << ans << '\n';
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using std::cin;
using std::cout;

inline void up(int &x, int y) { x < y ? x = y : 0; }
inline void down(int &x, int y) { x > y ? x = y : 0; }
inline int max(const int x, const int y) { return x > y ? x : y; }
inline int min(const int x, const int y) { return x < y ? x : y; }

int n, x[100005], ret, A, B, ans;
int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> x[i];
    std::sort(x + 1, x + n + 1);
    n = std::unique(x + 1, x + n + 1) - x - 1;
    cin >> A >> B;
    while (A > B) {
    	++ans;
    	ret = A - 1;
    	for (int i = n; i; --i)
    		if (A - A % x[i] >= B) down(ret, A - A % x[i]);
		A = ret;
		if (n > 0) {
			for (int i = n; i; --i)
				if (A - A % x[i] < B) --n;
				else break;
		}

		if (n == 0) A = B, ans += A - B - 1;
		if (A == B) break;

	}
	cout << ans << '\n';
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using std::cin;
using std::cout;

inline void up(int &x, int y) { x < y ? x = y : 0; }
inline void down(int &x, int y) { x > y ? x = y : 0; }
inline int max(const int x, const int y) { return x > y ? x : y; }
inline int min(const int x, const int y) { return x < y ? x : y; }

int n, x[100005], ret, A, B, ans;
int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> x[i];
    std::sort(x + 1, x + n + 1);
    n = std::unique(x + 1, x + n + 1) - x - 1;
    cin >> A >> B;
    while (A > B) {
    	++ans;
    	ret = A - 1;
    	for (int i = n; i; --i)
    		if (A - A % x[i] >= B) down(ret, A - A % x[i]);
		A = ret;
		if (n > 0) {
			for (int i = n; i; --i)
				if (A - A % x[i] < B) --n;
				else break;
		}

		if (n == 0) ans += A - B, A = B;
		if (A == B) break;

	}
	cout << ans << '\n';
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<cmath>
#include<map>
#include<queue>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;++i)cin>>arr[i];
	int a,b;
	cin>>a>>b;
	multiset<int> poss;
	vector<vector<int> > divby(a-b+1);
	for(int i=0;i<n;++i)
	{
		for(int j=arr[i]*(b/arr[i]-2);j<=a;j+=arr[i])
		if(b<=j)
		{
			divby[j-b].push_back(arr[i]);
		}
	}
	vector<int> ans(a-b+1,0);
	poss.insert(1);
	for(int j=0;j<(int)divby[0].size();++j)
	{
		poss.insert(1);
	}
	for(int i=1;i+b <=a;++i)
	{
		for(int j=0;j<(int)divby[i].size();++j)
		if(i+b - divby[i][j] >=b)
		{
			poss.erase(poss.find(ans[i-divby[i][j]]+1));
		}
    		ans[i]=*(poss.begin());
		poss.erase(poss.find(ans[i-1]+1));
		poss.insert(ans[i]+1);
		for(int j=0;j<(int)divby[i].size();++j)
		{
			poss.insert(ans[i]+1);
		}
	}
	cout<<ans[a-b]<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<cmath>
#include<map>
#include<queue>
using namespace std;
int main()
{
	int n=100000;
	cin>>n;
	vector<int> arr(n);
	set<int> num;
	for(int i=0;i<n;++i)
	{
		arr[i]=i+2;
		cin>>arr[i];
		num.insert(arr[i]);
	}
	int a=1000000000,b=1000000000-1000000;
	cin>>a>>b;
	multiset<int> poss;
	sort(arr.begin(),arr.end());
	vector<vector<int> > divby(a-b+1);
	vector<vector<int> > tr(a-b+1);
	for(int i=0;i<n;i++)
		if(arr[i]<100000)
		{
			bool fnd=0;
			int mn=1000000003;
			for(int j=arr[i]+arr[i];j<=1000000;j+=arr[i])
				if(num.find(j)!=num.end())
				{
					fnd=1;
					int x=b;
					if(x%j !=0)x+=(j-x%j);
					mn=min(mn,x);
					break;
				}
			if(fnd)
			{
				num.erase(arr[i]);
				mn=min(mn,a);
				//cerr<<arr[i]<<" "<<mn<<endl;
				int last=-1;
				for(int j=arr[i]*(b/arr[i]-2);j<=mn;j+=arr[i])
					if(b<=j)
					{
						divby[j-b].push_back(arr[i]);
						last=j;
					}
				tr[last-b].push_back(arr[i]);
			}
		}
	vector<int> arr2;
	for(set<int>::iterator i=num.begin();i!=num.end();++i)arr2.push_back(*i);
	for(int i=0;i<(int)arr2.size();++i)
	{
		for(int j=arr2[i]*(b/arr2[i]-2);j<=a;j+=arr2[i])
			if(b<=j)
			{
				divby[j-b].push_back(arr2[i]);
			}
	}
	cerr<<"ha\n";
	vector<int> ans(a-b+1,0);
	poss.insert(1);
	for(int j=0;j<(int)divby[0].size();++j)
	{
		poss.insert(1);
	}
	for(int j=0;j<(int)tr[0].size();++j)
	{
		poss.erase(poss.find(ans[0]+1));
	}
	for(int i=1;i+b <=a;++i)
	{
		for(int j=0;j<(int)divby[i].size();++j)
			if(i+b - divby[i][j] >=b)
			{
				poss.erase(poss.find(ans[i-divby[i][j]]+1));
			}
		ans[i]=*(poss.begin());
		poss.erase(poss.find(ans[i-1]+1));
		poss.insert(ans[i]+1);
		for(int j=0;j<(int)divby[i].size();++j)
		{
			poss.insert(ans[i]+1);
		}
		for(int j=0;j<(int)tr[i].size();++j)
		{
				poss.erase(poss.find(ans[i]+1));
		}
	}
	cout<<ans[a-b]<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<cmath>
#include<map>
#include<queue>
using namespace std;
int main()
{
	int n=100000;
	cin>>n;
	vector<int> arr(n);
	set<int> num;
	for(int i=0;i<n;++i)
	{
		arr[i]=i+2;
		cin>>arr[i];
		num.insert(arr[i]);
	}
	int a=1000000000,b=1000000000-1000000;
	cin>>a>>b;
	int ans=0;
	int td[100004];
	while(a!=b)
	{
		//cerr<<a<<endl;
		int nd=0;
		ans++;
		int nxt=a-1;
		set<int>::iterator it=num.begin();
		while(it!=num.end())
		{
			int p=a-a%(*it);
			if(p<b)
			{
				td[nd]=*it;
				nd++;
			}
			else
			{
				nxt=min(nxt,p);
			}
			it++;
		}
		for(int i=0;i<nd;++i)num.erase(td[i]);
		a=nxt;
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<cmath>
#include<map>
#include<queue>
using namespace std;
int main()
{
	int n=100000;
	cin>>n;
	vector<int> arr(n);
	set<int> num;
	for(int i=0;i<n;++i)
	{
		arr[i]=i+2;
		cin>>arr[i];
		num.insert(arr[i]);
	}
	int a=1000000000,b=1000000000-1000000;
	cin>>a>>b;
	multiset<int> poss;
	sort(arr.begin(),arr.end());
	vector<vector<int> > divby(a-b+1);
	vector<vector<int> > tr(a-b+1);
	for(int i=0;i<n;i++)
		if(arr[i]<1000000)
		{
			bool fnd=0;
			int mn=1000000003;
			for(int j=arr[i]+arr[i];j<=1000000;j+=arr[i])
				if(num.find(j)!=num.end())
				{
					fnd=1;
					int x=b;
					if(x%j !=0)x+=(j-x%j);
					mn=min(mn,x);
				}
			if(fnd)
			{
				num.erase(arr[i]);
				mn=min(mn,a);
				//cerr<<arr[i]<<" "<<mn<<endl;
				int last=-1;
				for(int j=arr[i]*(b/arr[i]-2);j<=mn;j+=arr[i])
					if(b<=j)
					{
						divby[j-b].push_back(arr[i]);
						last=j;
					}
				tr[last-b].push_back(arr[i]);
			}
		}
	vector<int> arr2;
	for(set<int>::iterator i=num.begin();i!=num.end();++i)arr2.push_back(*i);
	for(int i=0;i<(int)arr2.size();++i)
	{
		for(int j=arr2[i]*(b/arr2[i]-2);j<=a;j+=arr2[i])
			if(b<=j)
			{
				divby[j-b].push_back(arr2[i]);
			}
	}
	vector<int> ans(a-b+1,0);
	poss.insert(1);
	for(int j=0;j<(int)divby[0].size();++j)
	{
		poss.insert(1);
	}
	for(int j=0;j<(int)tr[0].size();++j)
	{
		poss.erase(poss.find(ans[0]+1));
	}
	for(int i=1;i+b <=a;++i)
	{
		for(int j=0;j<(int)divby[i].size();++j)
			if(i+b - divby[i][j] >=b)
			{
				poss.erase(poss.find(ans[i-divby[i][j]]+1));
			}
		ans[i]=*(poss.begin());
		poss.erase(poss.find(ans[i-1]+1));
		poss.insert(ans[i]+1);
		for(int j=0;j<(int)divby[i].size();++j)
		{
			poss.insert(ans[i]+1);
		}
		for(int j=0;j<(int)tr[i].size();++j)
		{
				poss.erase(poss.find(ans[i]+1));
		}
	}
	cout<<ans[a-b]<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<cmath>
#include<map>
#include<queue>
using namespace std;
int main()
{
	int n=100000;
	//cin>>n;
	vector<int> arr(n);
	set<int> num;
	for(int i=0;i<n;++i)
	{
		arr[i]=i+2;
		//cin>>arr[i];
		num.insert(arr[i]);
	}
	int a=1000000000,b=1000000000-1000000;
	//cin>>a>>b;
	multiset<int> poss;
	sort(arr.begin(),arr.end());
	vector<vector<int> > divby(a-b+1);
	vector<vector<int> > tr(a-b+1);
	for(int i=0;i<n;i++)
		if(arr[i]<100000)
		{
			bool fnd=0;
			int mn=1000000003;
			for(int j=arr[i]+arr[i];j<=1000000;j+=arr[i])
				if(num.find(j)!=num.end())
				{
					fnd=1;
					int x=b;
					if(x%j !=0)x+=(j-x%j);
					mn=min(mn,x);
					break;
				}
			if(fnd)
			{
				num.erase(arr[i]);
				mn=min(mn,a);
				//cerr<<arr[i]<<" "<<mn<<endl;
				int last=-1;
				for(int j=arr[i]*(b/arr[i]-2);j<=mn;j+=arr[i])
					if(b<=j)
					{
						divby[j-b].push_back(arr[i]);
						last=j;
					}
				tr[last-b].push_back(arr[i]);
			}
		}
	vector<int> arr2;
	for(set<int>::iterator i=num.begin();i!=num.end();++i)arr2.push_back(*i);
	for(int i=0;i<(int)arr2.size();++i)
	{
		for(int j=arr2[i]*(b/arr2[i]-2);j<=a;j+=arr2[i])
			if(b<=j)
			{
				divby[j-b].push_back(arr2[i]);
			}
	}
	cerr<<"ha\n";
	vector<int> ans(a-b+1,0);
	poss.insert(1);
	for(int j=0;j<(int)divby[0].size();++j)
	{
		poss.insert(1);
	}
	for(int j=0;j<(int)tr[0].size();++j)
	{
		poss.erase(poss.find(ans[0]+1));
	}
	for(int i=1;i+b <=a;++i)
	{
		for(int j=0;j<(int)divby[i].size();++j)
			if(i+b - divby[i][j] >=b)
			{
				poss.erase(poss.find(ans[i-divby[i][j]]+1));
			}
		ans[i]=*(poss.begin());
		poss.erase(poss.find(ans[i-1]+1));
		poss.insert(ans[i]+1);
		for(int j=0;j<(int)divby[i].size();++j)
		{
			poss.insert(ans[i]+1);
		}
		for(int j=0;j<(int)tr[i].size();++j)
		{
				poss.erase(poss.find(ans[i]+1));
		}
	}
	cout<<ans[a-b]<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<cmath>
#include<map>
#include<queue>
using namespace std;
int main()
{
	int n=100000;
	cin>>n;
	vector<int> arr(n);
	set<int> num;
	for(int i=0;i<n;++i)
	{
		arr[i]=i+2;
		cin>>arr[i];
		num.insert(arr[i]);
	}
	int a=1000000000,b=1000000000-1000000;
	cin>>a>>b;
	multiset<int> poss;
	sort(arr.begin(),arr.end());
	vector<vector<int> > divby(a-b+1);
	vector<vector<int> > tr(a-b+1);
	for(int i=0;i<n;i++)
		if(arr[i]<1000)
		{
			bool fnd=0;
			int mn=1000000003;
			for(int j=arr[i]*arr[i];j<=1000000;j+=arr[i])
				if(num.find(j)!=num.end())
				{
					fnd=1;
					int x=b;
					if(x%j !=0)x+=(j-x%j);
					mn=min(mn,x);
				}
			if(fnd)
			{
				num.erase(arr[i]);
				mn=min(mn,a);
				int last=-1;
				for(int j=arr[i]*(b/arr[i]-2);j<=mn;j+=arr[i])
					if(b<=j)
					{
						divby[j-b].push_back(arr[i]);
						last=j;
					}
				tr[last-b].push_back(arr[i]);
			}
		}
	vector<int> arr2;
	for(set<int>::iterator i=num.begin();i!=num.end();++i)arr2.push_back(*i);
	for(int i=0;i<(int)arr2.size();++i)
	{
		for(int j=arr2[i]*(b/arr2[i]-2);j<=a;j+=arr2[i])
			if(b<=j)
			{
				divby[j-b].push_back(arr2[i]);
			}
	}
	cerr<<"ha\n";
	vector<int> ans(a-b+1,0);
	poss.insert(1);
	for(int j=0;j<(int)divby[0].size();++j)
	{
		poss.insert(1);
	}
	for(int j=0;j<(int)tr[0].size();++j)
	{
		poss.erase(poss.find(ans[0]+1));
	}
	for(int i=1;i+b <=a;++i)
	{
		for(int j=0;j<(int)divby[i].size();++j)
			if(i+b - divby[i][j] >=b)
			{
				poss.erase(poss.find(ans[i-divby[i][j]]+1));
			}
		ans[i]=*(poss.begin());
		poss.erase(poss.find(ans[i-1]+1));
		poss.insert(ans[i]+1);
		for(int j=0;j<(int)divby[i].size();++j)
		{
			poss.insert(ans[i]+1);
		}
		for(int j=0;j<(int)tr[i].size();++j)
		{
				poss.erase(poss.find(ans[i]+1));
		}
	}
	cout<<ans[a-b]<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<cmath>
#include<map>
#include<queue>
using namespace std;
int main()
{
	int n=100000;
	cin>>n;
	vector<int> arr(n);
	set<int> num;
	for(int i=0;i<n;++i)
	{
		arr[i]=i+2;
		cin>>arr[i];
		num.insert(arr[i]);
	}
	int a=1000000000,b=1000000000-1000000;
	cin>>a>>b;
	multiset<int> poss;
	sort(arr.begin(),arr.end());
	vector<vector<int> > divby(a-b+1);
	vector<vector<int> > tr(a-b+1);
	for(int i=0;i<n;i++)
		if(arr[i]<100000)
		{
			bool fnd=0;
			int mn=1000000003;
			for(int j=arr[i]+arr[i];j<=100000;j+=arr[i])
				if(num.find(j)!=num.end())
				{
					fnd=1;
					int x=b;
					if(x%j !=0)x+=(j-x%j);
					mn=min(mn,x);
				}
			if(fnd)
			{
				num.erase(arr[i]);
				mn=min(mn,a);
				//cerr<<arr[i]<<" "<<mn<<endl;
				int last=-1;
				for(int j=arr[i]*(b/arr[i]-2);j<=mn;j+=arr[i])
					if(b<=j)
					{
						divby[j-b].push_back(arr[i]);
						last=j;
					}
				tr[last-b].push_back(arr[i]);
			}
		}
	vector<int> arr2;
	for(set<int>::iterator i=num.begin();i!=num.end();++i)arr2.push_back(*i);
	for(int i=0;i<(int)arr2.size();++i)
	{
		for(int j=arr2[i]*(b/arr2[i]-2);j<=a;j+=arr2[i])
			if(b<=j)
			{
				divby[j-b].push_back(arr2[i]);
			}
	}
	vector<int> ans(a-b+1,0);
	poss.insert(1);
	for(int j=0;j<(int)divby[0].size();++j)
	{
		poss.insert(1);
	}
	for(int j=0;j<(int)tr[0].size();++j)
	{
		poss.erase(poss.find(ans[0]+1));
	}
	for(int i=1;i+b <=a;++i)
	{
		for(int j=0;j<(int)divby[i].size();++j)
			if(i+b - divby[i][j] >=b)
			{
				poss.erase(poss.find(ans[i-divby[i][j]]+1));
			}
		ans[i]=*(poss.begin());
		poss.erase(poss.find(ans[i-1]+1));
		poss.insert(ans[i]+1);
		for(int j=0;j<(int)divby[i].size();++j)
		{
			poss.insert(ans[i]+1);
		}
		for(int j=0;j<(int)tr[i].size();++j)
		{
				poss.erase(poss.find(ans[i]+1));
		}
	}
	cout<<ans[a-b]<<endl;
	return 0;
}


// TODO : Choose an Appropriate Name!!
// We're not here because we're free. We're here because we are not free.
//											   The Matrix Reloaded (2003)
#include <bits/stdc++.h>

using namespace std;

#define MohammadAmin main()
#define mpair make_pair
#define endl "\n"
#define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define pushb push_back
#define pushf push_front
#define popb pop_back
#define popf pop_front
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define X first
#define Y second
#define ashar(a) cout << fixed << setprecision((a))
#define reset(a,b) memset(a, b, sizeof(a))
#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)
#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int n_ = 1e5 + 1000;
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

int n, a, b, ans, mn, x[n_];
//vector<int> x;

int MohammadAmin {
	c_false;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> x[i];
	}
//	sort(all(x));
//	unique(all(x));
	sort(x, x+n);
	n = unique(x, x+n) - x;
	cin >> a >> b;
	while(a > b) {
		mn = a - 1;
		for(int i = 0; i < n; i++) {
			if (a - a%x[i] >= b) {
				mn = min(mn, a - a%x[i]);
			}else break;
		}
		a = mn;
		while(n && a - a%x[n-1] < b) {
			n--;
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}


// TODO : Choose an Appropriate Name!!
// We're not here because we're free. We're here because we are not free.
//											   The Matrix Reloaded (2003)
#include <bits/stdc++.h>

using namespace std;

#define MohammadAmin main()
#define mpair make_pair
#define endl "\n"
#define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define pushb push_back
#define pushf push_front
#define popb pop_back
#define popf pop_front
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define X first
#define Y second
#define ashar(a) cout << fixed << setprecision((a))
#define reset(a,b) memset(a, b, sizeof(a))
#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)
#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int n_ = 1e5 + 1000;
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

int n, a, b, ans, mn;
vector<int> x;

int MohammadAmin {
	c_false;
	cin >> n;
	x.resize(n);
	for(int i = 0; i < n; i++) {
		cin >> x[i];
	}
	sort(all(x));
	unique(all(x));
	cin >> a >> b;
	int xx = 0;
	while(a > b) {
//		cerr << ">> " << a << " " << b << " " << sz(x) << endl;
		mn = a - 1;
		for(int i = 0; i < sz(x); i++) {
			if (a - a%x[i] >= b) {
				mn = min(mn, a - a%x[i]);
			}
		}
		a = mn;
		while(sz(x) && a - a%x.back() < b) {
			x.popb();
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}


// TODO : Choose an Appropriate Name!!
// We're not here because we're free. We're here because we are not free.
//											   The Matrix Reloaded (2003)
#include <bits/stdc++.h>

using namespace std;

#define MohammadAmin main()
#define mpair make_pair
#define endl "\n"
#define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define pushb push_back
#define pushf push_front
#define popb pop_back
#define popf pop_front
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define X first
#define Y second
#define ashar(a) cout << fixed << setprecision((a))
#define reset(a,b) memset(a, b, sizeof(a))
#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)
#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int n_ = 1e5 + 1000;
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

int n, a, b, ans, mn, x[n_];
//vector<int> x;

int MohammadAmin {
	c_false;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> x[i];
	}
//	sort(all(x));
//	unique(all(x));
	sort(x, x+n);
	n = unique(x, x+n) - x;
	cin >> a >> b;
	while(a > b) {
		mn = a - 1;
		for(int i = 0; i < n; i++) {
			if (a - a%x[i] >= b) {
				mn = min(mn, a - a%x[i]);
			}
		}
		a = mn;
		while(n && a - a%x[n-1] < b) {
			n--;
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = (int)1e5 + 500, M = (int)1e6 + 500, INF = (int)1e9;

int n;
int num[N], nxt[2 * M];
int a,b;

int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &num[i]);
    scanf("%d%d", &a, &b);

    for(int i = 0; i < 2 * M; i++) nxt[i] = max(0, i-1);
    a -= b;
    sort(num, num+n);
    for(int i = 0; i < n; i++){
        if(i == 0 || num[i] != num[i-1]){
            for(int j = ((num[i] - 1 - b) % num[i] + num[i]) % num[i]; j <= a + num[i]; j += num[i]){
                if(j - (num[i] - 1) >= 0) nxt[j] = min(nxt[j],  j - (num[i] - 1));
            }
        }
    }
    for(int j = 2 * M - 2; j >= 0; j--) nxt[j] = min(nxt[j], nxt[j+1]);

    int cnt = 0;
    for(int j = a; j != 0; j = nxt[j]) cnt++;
    cout << cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;

const int N = (int)1e5 + 500, M = (int)1e6 + 500, INF = (int)1e9;

int n;
int num[N], nxt[2 * M];
int a,b;

int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &num[i]);
    scanf("%d%d", &a, &b);

    for(int i = 0; i < 2 * M; i++) nxt[i] = max(0, i-1);
    a -= b;
    sort(num, num+n);
    for(int i = 0; i < n; i++){
        if(i == 0 || num[i] != num[i-1]){
            for(int j = ((num[i] - 1 - b) % num[i] + num[i]) % num[i]; j <= a; j += num[i]){
                if(j - (num[i] - 1) >= 0) nxt[j] = min(nxt[j],  j - (num[i] - 1));
            }
            int nxt_a = a - (a + b) % num[i];
            if(nxt_a >= 0) nxt[a] = min(nxt[a], nxt_a);
        }
    }
    for(int j = 2 * M - 2; j >= 0; j--) nxt[j] = min(nxt[j], nxt[j+1]);

    int cnt = 0;
    for(int j = a; j != 0; j = nxt[j]) cnt++;
    cout << cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;

const int N = (int)1e5 + 500, M = (int)1e6 + 500, INF = (int)1e9;

int n;
int num[N], nxt[2 * M];
int a,b;

int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &num[i]);
    scanf("%d%d", &a, &b);

    for(int i = 0; i < 2 * M; i++) nxt[i] = max(0, i-1);
    a -= b;
    sort(num, num+n);
    for(int i = 0; i < n; i++){
        if(i == 0 || num[i] != num[i-1]){
            for(int j = ((num[i] - 1 - b) % num[i] + num[i]) % num[i]; j <= a; j += num[i]){
                if(j - (num[i] - 1) >= 0) nxt[j] = min(nxt[j],  j - (num[i] - 1));
            }
            int nxt_a = (a + b) % num[i] >= b ? (a + b) % num[i] : INF;
            nxt[a] = min(nxt[a], nxt_a);
        }
    }
    for(int j = 2 * M - 2; j >= 0; j--) nxt[j] = min(nxt[j], nxt[j+1]);

    int cnt = 0;
    for(int j = a; j != 0; j = nxt[j]) cnt++;
    cout << cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;

const int N = (int)1e5 + 500, M = (int)1e6 + 500, INF = (int)1e9;

int n;
int num[N], nxt[2 * M];
int a,b;

int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &num[i]);
    scanf("%d%d", &a, &b);

    for(int i = 0; i < 2 * M; i++) nxt[i] = max(0, i-1);
    a -= b;
    sort(num, num+n);
    for(int i = 0; i < n; i++){
        if(i == 0 || num[i] != num[i-1]){
            for(int j = ((num[i] - 1 - b) % num[i] + num[i]) % num[i]; j <= a; j += num[i]){
                if(j - (num[i] - 1) >= 0) nxt[j] = min(nxt[j],  j - (num[i] - 1));
            }
            int nxt_a = a - (a + b) % num[i];
            if(nxt_a >= b) nxt[a] = min(nxt[a], nxt_a);
        }
    }
    for(int j = 2 * M - 2; j >= 0; j--) nxt[j] = min(nxt[j], nxt[j+1]);

    int cnt = 0;
    for(int j = a; j != 0; j = nxt[j]) cnt++;
    cout << cnt << endl;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int>G[1000000+5];
int A[1000000+5];
int N;
int ans[1000000+5];
map<int,int>mp;
int main() {
	cin>>N;
	for(int i=1;i<=N;++i){
		scanf("%d",&A[i]);
	}
	int last = 0;
	sort(A+1,A+N+1);
	for(int i=1;i<=N;++i){
		if(A[last]!=A[i]){
			++last;
			A[last] = A[i];
		}
	}
	N = last;
	int a,b;
	cin>>a>>b;
	int cost = 0;
	swap(a,b);
	while(a<b){
		cost ++;
		int mx = 1;
		for(int i=1;i<=N;++i){
			if(b - b%A[i]>=a)
				mx = max(mx, b%A[i]);
		}
		b -= mx;
	}
	cout<<cost;
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int>G[1000000+5];
int A[1000000+5];
int N;
int ans[1000000+5];
map<int,int>mp;
int main() {
	cin>>N;
	for(int i=1;i<=N;++i){
		scanf("%d",&A[i]);
	}
	int last = 0;
	sort(A+1,A+N+1);
	for(int i=1;i<=N;++i){
		if(A[last]!=A[i]){
			++last;
			A[last] = A[i];
		}
	}
	N = last;
	int a,b;
	cin>>a>>b;
	int cost = 0;
	swap(a,b);
	while(a<b){
		cost ++;
		int mx = 1;
		for(int i=1;i<=N;++i){
			if(b - b%A[i]>=a)
				mx = max(mx, b%A[i]);
		}

		while(N>=1 and b - b%A[N]<a)
			N--;
		b -= mx;
	}
	cout<<cost;
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int>G[100000+5];
int A[100000+5];
int N;
int ans[100000+5];
map<int,int>mp;
int main() {
	cin>>N;
	for(int i=1;i<=N;++i){
		scanf("%d",&A[i]);
	}
	int a,b;
	cin>>a>>b;
	swap(a,b);
	sort(A+1,A+N+1);
	for(int i=1;i<=N;++i){
		if(A[i]==A[i-1])
			continue;
		int u = A[i];
		int j;
		if(a%u==0){
			j = a;
		}
		else{
			j = a - a%u + u;
		}
		for(;j<=b;j+=u){
			G[j-a].push_back(u);
		}
	}
	for(int i=0;i<=b-a;++i){
		for(int j=0;j<G[i].size();++j){
			int u = G[i][j];
			//cout<<i+a<<' '<<u<<endl;
			mp[i-u]--;
			if(mp[i-u]<=0){
				mp.erase(i-u);
			}
		}
		ans[i] = -1000000;
		if(mp.size())
			ans[i] = mp.begin()->first;

		if(G[i].size())
			mp[i] += G[i].size();
	//	cout<<i+a<<' '<<a+ans[i]<<endl;
	}
	int cost = 0;
	for(int i=b-a;i>0;cost++){
		if(ans[i]<0){
			i--;
		}
		else{
			i = ans[i];
		}
	}
	cout<<cost;
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int>G[1000000+5];
int A[1000000+5];
int N;
int ans[1000000+5];
map<int,int>mp;
int main() {
	cin>>N;
	for(int i=1;i<=N;++i){
		scanf("%d",&A[i]);
	}
	int a,b;
	cin>>a>>b;
	swap(a,b);
	sort(A+1,A+N+1);
	for(int i=1;i<=N;++i){
		if(A[i]==A[i-1])
			continue;
		int u = A[i];
		int j;
		if(a%u==0){
			j = a;
		}
		else{
			j = a - a%u + u;
		}
		for(;j<=b;j+=u){
			G[j-a].push_back(u);
		}
	}
	for(int i=0;i<=b-a;++i){
		for(int j=0;j<G[i].size();++j){
			int u = G[i][j];
			//cout<<i+a<<' '<<u<<endl;
			mp[i-u]--;
			if(mp[i-u]<=0){
				mp.erase(i-u);
			}
		}
		ans[i] = -1000000;
		if(mp.size())
			ans[i] = mp.begin()->first;

		if(G[i].size())
			mp[i] += G[i].size();
	//	cout<<i+a<<' '<<a+ans[i]<<endl;
	}
	int cost = 0;
	for(int i=b-a;i>0;cost++){
		if(ans[i]<0){
			i--;
		}
		else{
			i = ans[i];
		}
	}
	cout<<cost;
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
namespace IO
{
    const int sz=1<<15;
    char inbuf[sz],outbuf[sz];
    char *pinbuf=inbuf+sz;
    char *poutbuf=outbuf;
    inline char _getchar()
    {
        if (pinbuf==inbuf+sz)fread(inbuf,1,sz,stdin),pinbuf=inbuf;
        return *(pinbuf++);
    }
    inline void _putchar(char x)
    {
        if (poutbuf==outbuf+sz)fwrite(outbuf,1,sz,stdout),poutbuf=outbuf;
        *(poutbuf++)=x;
    }
    inline void flush()
    {
        if (poutbuf!=outbuf)fwrite(outbuf,1,poutbuf-outbuf,stdout),poutbuf=outbuf;
    }
}
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
int Solve(int a,int n,int p){
	a%=p;
	if (1ll*n*a<(LL)p) return a;
	int A=a-p%a,P=a,N=1ll*n*a/p;
	int tt=1ll*n*a%p;
	if (tt+a<n) N--;
	if (1ll*A*N<P){
		return max(A,P-A*N);
	}
	return Solve(A,N,P);
}
void mian(){
	int a,n,p,h;
	a=read();n=read();p=read();h=read();
	int x=Solve(a,n,p);
	if (x<=h){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while (t--){
		mian();
	}
}
/*
3
7 4 12 2
7 1 9 4
7 4 12 3
*/


#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
namespace IO
{
    const int sz=1<<15;
    char inbuf[sz],outbuf[sz];
    char *pinbuf=inbuf+sz;
    char *poutbuf=outbuf;
    inline char _getchar()
    {
        if (pinbuf==inbuf+sz)fread(inbuf,1,sz,stdin),pinbuf=inbuf;
        return *(pinbuf++);
    }
    inline void _putchar(char x)
    {
        if (poutbuf==outbuf+sz)fwrite(outbuf,1,sz,stdout),poutbuf=outbuf;
        *(poutbuf++)=x;
    }
    inline void flush()
    {
        if (poutbuf!=outbuf)fwrite(outbuf,1,poutbuf-outbuf,stdout),poutbuf=outbuf;
    }
}
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
int Solve(int a,int n,int p){
	a%=p;
	if (1ll*n*a<(LL)p) return max(a,p-a*n);
	int A=p%a,P=a,N=1ll*n*a/p;
	int tt=1ll*n*a%p;
	if (tt<(p/a-1)*a) N--;
	return Solve(A,N,P);
}
void mian(){
	int a,n,p,h;
	a=read();n=read();p=read();h=read();
	int x=Solve(a,n,p);
//	cout<<x<<endl;
	if (x<=h){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while (t--){
		mian();
	}
}
/*
1
79 31 58 3
*/


#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
namespace IO
{
    const int sz=1<<15;
    char inbuf[sz],outbuf[sz];
    char *pinbuf=inbuf+sz;
    char *poutbuf=outbuf;
    inline char _getchar()
    {
        if (pinbuf==inbuf+sz)fread(inbuf,1,sz,stdin),pinbuf=inbuf;
        return *(pinbuf++);
    }
    inline void _putchar(char x)
    {
        if (poutbuf==outbuf+sz)fwrite(outbuf,1,sz,stdout),poutbuf=outbuf;
        *(poutbuf++)=x;
    }
    inline void flush()
    {
        if (poutbuf!=outbuf)fwrite(outbuf,1,poutbuf-outbuf,stdout),poutbuf=outbuf;
    }
}
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
int Solve(int a,int n,int p){
	a%=p;
	if (1ll*n*a<(LL)p) return max(a,p-a*n);
	int A=a-p%a,P=a,N=1ll*n*a/p;
	int tt=1ll*n*a%p;
	if (tt<(p/a-1)*a) N--;
	return Solve(A,N,P);
}
void mian(){
	int a,n,p,h;
	a=read();n=read();p=read();h=read();
	int x=Solve(a,n,p);
//	cout<<x<<endl;
	if (x<=h){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while (t--){
		mian();
	}
}
/*
1
79 31 58 3
*/


#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
namespace IO
{
    const int sz=1<<15;
    char inbuf[sz],outbuf[sz];
    char *pinbuf=inbuf+sz;
    char *poutbuf=outbuf;
    inline char _getchar()
    {
        if (pinbuf==inbuf+sz)fread(inbuf,1,sz,stdin),pinbuf=inbuf;
        return *(pinbuf++);
    }
    inline void _putchar(char x)
    {
        if (poutbuf==outbuf+sz)fwrite(outbuf,1,sz,stdout),poutbuf=outbuf;
        *(poutbuf++)=x;
    }
    inline void flush()
    {
        if (poutbuf!=outbuf)fwrite(outbuf,1,poutbuf-outbuf,stdout),poutbuf=outbuf;
    }
}
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
int Solve(int a,int n,int p){
	a%=p;
	if (a+a>p) a=p-a;
	if (1ll*n*a<(LL)p) return a;
	int A=a-p%a,P=a,N=1ll*n*a/p;
	if (1ll*A*N<P){
		return max(A,P-A*N);
	}
	return Solve(A,N,P);
}
void mian(){
	int a,n,p,h;
	a=read();n=read();p=read();h=read();
	int x=Solve(a,n,p);
	if (x<=h){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while (t--){
		mian();
	}
}
/*
1
51 6 25 1
*/


#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
namespace IO
{
    const int sz=1<<15;
    char inbuf[sz],outbuf[sz];
    char *pinbuf=inbuf+sz;
    char *poutbuf=outbuf;
    inline char _getchar()
    {
        if (pinbuf==inbuf+sz)fread(inbuf,1,sz,stdin),pinbuf=inbuf;
        return *(pinbuf++);
    }
    inline void _putchar(char x)
    {
        if (poutbuf==outbuf+sz)fwrite(outbuf,1,sz,stdout),poutbuf=outbuf;
        *(poutbuf++)=x;
    }
    inline void flush()
    {
        if (poutbuf!=outbuf)fwrite(outbuf,1,poutbuf-outbuf,stdout),poutbuf=outbuf;
    }
}
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}

const int Maxn=100005;
vector<pair<int,int> > G[Maxn];
map<pair<int,int>,int> E;
int n,m;
int dep[Maxn],par[Maxn],onc[Maxn],bel[Maxn],br[Maxn];
int L[Maxn],R[Maxn];
int dL[Maxn],dR[Maxn],pL[Maxn],pR[Maxn],ans[Maxn],ld[Maxn],rd[Maxn],res[Maxn],ban[Maxn];
int P[Maxn][20],st[Maxn],ed[Maxn],kc;
vector<int> BB;
void Dfs(int x,int p){
	P[x][0]=p;
	st[x]=++kc;
	for (int i=0;i<G[x].size();i++){
		int v=G[x][i].first;
		if (v!=p){
			Dfs(v,x);
		}
	}
	ed[x]=kc;
}
bool ispar(int u,int v){
	return (u==-1)||(st[u]<=st[v] && ed[v]<=ed[u]);
}
int lca(int u,int v){
	if (ispar(u,v)) return u;
	for (int i=19;i>=0;i--){
		if (!ispar(P[u][i],v)) u=P[u][i];
	}
	return P[u][0];
}
void dfs(int x,int p){
	par[x]=p;
	for (int i=0;i<G[x].size();i++){
		int v=G[x][i].first;
		if (v!=p){
			dep[v]=dep[x]+G[x][i].second;
			dfs(v,x);
		}
	}
}
int Mxd=0;
vector<pair<int,int> > S[Maxn];
void dfs2(int x,int p,int D,int rt,int rt2){
	dep[x]=D;S[rt].pb(mp(x,rt2));
	br[x]=rt2;
	if (ban[x]) Mxd=max(Mxd,D);
	bel[x]=rt;
	for (int i=0;i<G[x].size();i++){
		int v=G[x][i].first;
		if (v!=p && !onc[v]){
			dfs2(v,x,D+G[x][i].second,rt,rt2);
		}
	}
}
void Ins(int u,int v){
	int l=lca(u,v);
	//cout<<"INS"<<" "<<u<<' '<<v<<" "<<l<<endl;
	res[u]++;res[v]++;
	res[l]--;
	if (P[l][0]!=-1) res[P[l][0]]--;
}
void dfs3(int x,int p){
	for (int i=0;i<G[x].size();i++){
		int v=G[x][i].first;
		if (v!=p){
			dfs3(v,x);
			res[x]+=res[v];
		}
	}
}
int main(){
	n=read();m=read();
	for (int i=0;i<m;i++){
		int x=read();
		BB.pb(x);
		ban[x]=1;
	}
	for (int i=0;i<n-1;i++){
		int u,v,w;
		u=read();v=read();w=read();
		E[mp(u,v)]=w;
		E[mp(v,u)]=w;
		G[u].pb(mp(v,w));
		G[v].pb(mp(u,w));
	}
	Dfs(1,-1);
	for (int i=1;i<20;i++){
		for (int j=1;j<=n;j++){
			if (P[j][i-1]==-1) P[j][i]=-1;
			else P[j][i]=P[P[j][i-1]][i-1];
		}
	}

	dfs(1,-1);
	int A=1;
	for (int i=1;i<=n;i++){
		if (ban[i] && dep[i]>dep[A]) A=i;
	}
	dfs(A,-1);
	int B=A;
	for (int i=1;i<=n;i++){
		if (ban[i] && dep[i]>dep[B]) B=i;
	}
//	cout<<"Dia"<<" "<<A<<" "<<B<<endl;
	vector<int> C;
	int cur=B;
	while (cur!=A){
		C.pb(cur);cur=par[cur];
	}
	C.pb(A);
	for (int i=0;i<C.size();i++){
		onc[C[i]]=1;
	}
	for (int i=1;i<C.size();i++){
		dL[i]=dL[i-1]+E[mp(C[i-1],C[i])];
	}
	for (int i=C.size()-2;i>=0;i--){
		dR[i]=dR[i+1]+E[mp(C[i],C[i+1])];
	}
	for (int i=0;i<C.size();i++){
		Mxd=0;
		int u=C[i];
		for (int j=0;j<G[u].size();j++){
			int v=G[u][j].first;
			if (!onc[v]){
				dfs2(v,u,G[u][j].second,i,v);
			}
		}
		bel[u]=i;br[u]=114514;
		if (Mxd==dL[i]) L[i]=1;
		if (Mxd==dR[i]) R[i]=1;
		for (int j=0;j<S[i].size();j++){
			int x=S[i][j].first,y=S[i][j].second;
			if (!ban[x]) continue;
			if (dep[x]==dL[i]){
				if (!ld[i]) ld[i]=y;
				else if (ld[i]==-1) ld[i]=-1;
				else if (ld[i]!=y) ld[i]=-1;
			}
			if (dep[x]==dR[i]){
				if (!rd[i]) rd[i]=y;
				else if (rd[i]==-1) rd[i]=-1;
				else if (rd[i]!=y) rd[i]=-1;
			}
		}
	}
	for (int i=0;i<C.size();i++){
		if (L[i]) pL[i]=i;
		else pL[i]=pL[i-1];
	}
	for (int i=C.size()-1;i>=0;i--){
		if (R[i]) pR[i]=i;
		else pR[i]=pR[i+1];
	}

	for (int i=0;i<C.size();i++){
		if (dL[i]==dR[i]){
			ans[i]=C[i];
		}
		else if (dR[i]>dL[i]){
			ans[i]=C[pR[i]];
		}
		else{
			ans[i]=C[pL[i]];
		}
	//	cout<<"DD"<<" "<<i<<' '<<dL[i]<<' '<<dR[i]<<endl;
	}

	for (int i=0;i<BB.size();i++){
		int x=BB[i];
		int RR=bel[x],R2=br[x];
	//	cout<<"FUCK"<<x<<" "<<RR<<endl;
		if (dL[RR]==dR[RR]){
			Ins(x,ans[RR]);
		}
		else if (dR[RR]>dL[RR]){
			if (!R[i]) Ins(x,ans[RR]);
			else{
				if (R2==rd[i]){
					Ins(x,C[pR[i+1]]);
				}
				else{
					Ins(x,ans[RR]);
				}
			}
		}
		else{
			if (!L[i]) Ins(x,ans[RR]);
			else{
				if (R2==ld[i]){
					Ins(x,C[pL[i+1]]);
				}
				else{
					Ins(x,ans[RR]);
				}
			}
		}
	}
	dfs3(1,-1);
	int Mx=-1,cnt=0;
	for (int i=1;i<=n;i++){
		if (!ban[i]){
			if (res[i]>Mx){
				Mx=res[i];cnt=1;
			}
			else if (res[i]==Mx) cnt++;
		}
	}
	printf("%d %d\n",Mx,cnt);
	return 0;
}
/*
10 2
1 5
5 3 2
8 4 8
7 6 9
7 10 1
10 1 4
9 5 1
5 8 2
7 2 9
6 5 6
*/


#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
namespace IO
{
    const int sz=1<<15;
    char inbuf[sz],outbuf[sz];
    char *pinbuf=inbuf+sz;
    char *poutbuf=outbuf;
    inline char _getchar()
    {
        if (pinbuf==inbuf+sz)fread(inbuf,1,sz,stdin),pinbuf=inbuf;
        return *(pinbuf++);
    }
    inline void _putchar(char x)
    {
        if (poutbuf==outbuf+sz)fwrite(outbuf,1,sz,stdout),poutbuf=outbuf;
        *(poutbuf++)=x;
    }
    inline void flush()
    {
        if (poutbuf!=outbuf)fwrite(outbuf,1,poutbuf-outbuf,stdout),poutbuf=outbuf;
    }
}
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
int Solve(int a,int n,int p){
	if (1ll*n*a<(LL)p) return a;
	int A=a-p%a,P=a,N=1ll*n*a/p;
	if (1ll*A*N<P){
		return max(A,P-A*N);
	}
	return Solve(A,N,P);
}
void mian(){
	int a,n,p,h;
	a=read();n=read();p=read();h=read();
	int x=Solve(a,n,p);
	if (x<=h){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while (t--){
		mian();
	}
}


#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
namespace IO
{
    const int sz=1<<15;
    char inbuf[sz],outbuf[sz];
    char *pinbuf=inbuf+sz;
    char *poutbuf=outbuf;
    inline char _getchar()
    {
        if (pinbuf==inbuf+sz)fread(inbuf,1,sz,stdin),pinbuf=inbuf;
        return *(pinbuf++);
    }
    inline void _putchar(char x)
    {
        if (poutbuf==outbuf+sz)fwrite(outbuf,1,sz,stdout),poutbuf=outbuf;
        *(poutbuf++)=x;
    }
    inline void flush()
    {
        if (poutbuf!=outbuf)fwrite(outbuf,1,poutbuf-outbuf,stdout),poutbuf=outbuf;
    }
}
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
int Solve(int a,int n,int p){
	a%=p;
	if (1ll*n*a<(LL)p) return max(a,p-a*n);
	int A=p%a,P=a,N=1ll*n*a/p;
	int tt=1ll*n*a%p;
	if (tt<(p/a-1)*a) N--;
	return Solve(A,N,P);
}
void mian(){
	int a,n,p,h;
	a=read();n=read();p=read();h=read();
	a%=p;
	int x;
	if (1ll*a*n<p){
		x=a;
	}
	else x=Solve(a,n,p);
	if (x<=h){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while (t--){
		mian();
	}
}
/*
1
79 31 58 3
*/


#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
namespace IO
{
    const int sz=1<<15;
    char inbuf[sz],outbuf[sz];
    char *pinbuf=inbuf+sz;
    char *poutbuf=outbuf;
    inline char _getchar()
    {
        if (pinbuf==inbuf+sz)fread(inbuf,1,sz,stdin),pinbuf=inbuf;
        return *(pinbuf++);
    }
    inline void _putchar(char x)
    {
        if (poutbuf==outbuf+sz)fwrite(outbuf,1,sz,stdout),poutbuf=outbuf;
        *(poutbuf++)=x;
    }
    inline void flush()
    {
        if (poutbuf!=outbuf)fwrite(outbuf,1,poutbuf-outbuf,stdout),poutbuf=outbuf;
    }
}
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
int Solve(int a,int n,int p){
	a%=p;
	if (1ll*n*a<(LL)p) return a;
	int A=a-p%a,P=a,N=1ll*n*a/p;
	int tt=1ll*n*a%p;
	if (tt+a<p) N--;
	if (1ll*A*N<P){
		return max(A,P-A*N);
	}
	return Solve(A,N,P);
}
void mian(){
	int a,n,p,h;
	a=read();n=read();p=read();h=read();
	int x=Solve(a,n,p);
	if (x<=h){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while (t--){
		mian();
	}
}
/*
1
79 31 58 3
*/


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

int solve(int a, int n, int p) {
  if (a * n <= p) return max(a, p - n * a);
  return solve(min(p % a, a - p % a), a * n / p, a);
}

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


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

int solve(int a, int n, int p) {
  if (1LL * a * n <= p) return max(a, p - n * a);
  int fi = 0;
  if (a * 2 <= p) fi = p - p % a - a;
  return solve(min(p % a, a - p % a), (1LL * a * n - fi) / p, a);
}

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


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

int solve(int a, int n, int p) {
  if (a * n <= p) return max(a, p - n * a);
  int fi = 0;
  if (a * 2 <= p) fi = p - p % a - a;
  return solve(min(p % a, a - p % a), (1LL * a * n - fi) / p, a);
}

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


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

int solve(int a, int n, int p) {
  if (1LL * a * n <= p) return max(a, p - n * a);
  int fi = 0;
  if (a * 2 <= p) fi = p - p % a - a;
  return solve(min(p % a, a - p % a), (1LL * a * n - fi) / p, a);
}

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


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int T;
int F(int a,int n,int p)
{
	ll t=(ll)a*n/p;
	if(!t)return max(a,p-a*n);
	return F(a-p%a,t-((ll)a*n%p<(p/a-1)*a),a);
}
int a,n,p,h;
void solve()
{
	scanf("%d%d%d%d",&a,&n,&p,&h);
	a%=p;
	puts(((ll)a*n<p?a:F(a,n,p))<=h?"YES":"NO");
}
int main()
{
	scanf("%d",&T);
	while(T--)solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int T;
int F(int a,int n,int p)
{
	ll t=(ll)a*n/p;
	if(!t)return max(a,p-a*n);
	return F(a-p%a,t-((ll)a*n%p<(p/a-1)*a),a);
}
int a,n,p,h;
void solve()
{
	scanf("%d%d%d%d",&a,&n,&p,&h);
	a%=p;
	puts(F(a,n,p)<=h?"YES":"NO");
}
int main()
{
	scanf("%d",&T);
	while(T--)solve();
	return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 200005;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);

    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }

    template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}

using namespace input;

namespace output {
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    template<class T, size_t SZ> void pr(const array<T,SZ>& x);
    template<class T> void pr(const vector<T>& x);
    template<class T> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);

    template<class T> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }

    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.f,", ",x.s,"}");
    }
    template<class T> void prContain(const T& x) {
        pr("{");
        bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
        pr("}");
    }
    template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    template<class T> void pr(const vector<T>& x) { prContain(x); }
    template<class T> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

    void ps() { pr("\n"); }
    template<class Arg> void ps(const Arg& first) {
        pr(first); ps(); // no space at end of line
    }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...); // print w/ spaces
    }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}

using namespace io;

template<class T> T invGeneral(T a, T b) {
    a %= b; if (a == 0) return b == 1 ? 0 : -1;
    T x = invGeneral(b,a);
    return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}

template<class T> struct modular {
    T val;
    explicit operator T() const { return val; }
    modular() { val = 0; }
    modular(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD;
    }

    // friend ostream& operator<<(ostream& os, const modular& a) { return os << a.val; }
    friend void pr(const modular& a) { pr(a.val); }
    friend void re(modular& a) { ll x; re(x); a = modular(x); }

    friend bool operator==(const modular& a, const modular& b) { return a.val == b.val; }
    friend bool operator!=(const modular& a, const modular& b) { return !(a == b); }
    friend bool operator<(const modular& a, const modular& b) { return a.val < b.val; }

    modular operator-() const { return modular(-val); }
    modular& operator+=(const modular& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
    modular& operator-=(const modular& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
    modular& operator*=(const modular& m) { val = (ll)val*m.val%MOD; return *this; }
    friend modular pow(modular a, ll p) {
        modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans;
    }
    friend modular inv(const modular& a) {
        auto i = invGeneral(a.val,MOD); assert(i != -1);
        return i;
    } // equivalent to return exp(b,MOD-2) if MOD is prime
    modular& operator/=(const modular& m) { return (*this) *= inv(m); }

    friend modular operator+(modular a, const modular& b) { return a += b; }
    friend modular operator-(modular a, const modular& b) { return a -= b; }
    friend modular operator*(modular a, const modular& b) { return a *= b; }

    friend modular operator/(modular a, const modular& b) { return a /= b; }
};

typedef modular<int> mi;
typedef pair<mi,mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int p;

ll cdiv(ll a, ll b) { return (a+b-1)/b; }

ll solve(ll a, ll n) {
	ll n2 = a*n/p; // how many times you subtracted p
	if (!n2) return a;
	ll a2 = a-p%a; // 5-3 = 2
	ll cat = p/a-1;
	if (n < cdiv(n2*p,a)+cat) n2 --; // how many times to get to n2*p
	if (n2*a2 < a) return max(a2,a-n2*a2);
	return solve(min(a2,a-a2),n2);
	// (ll)n*a/p is equal to the number of runarounds

}

int main() {
    setIO();
	int t; re(t);
    F0R(i,t) {
    	int a,n,h;
		re(a,n,p,h);
		if (solve(a,n) <= h) ps("YES");
		else ps("NO");
    }
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 200005;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);

    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }

    template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}

using namespace input;

namespace output {
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    template<class T, size_t SZ> void pr(const array<T,SZ>& x);
    template<class T> void pr(const vector<T>& x);
    template<class T> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);

    template<class T> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }

    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.f,", ",x.s,"}");
    }
    template<class T> void prContain(const T& x) {
        pr("{");
        bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
        pr("}");
    }
    template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    template<class T> void pr(const vector<T>& x) { prContain(x); }
    template<class T> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

    void ps() { pr("\n"); }
    template<class Arg> void ps(const Arg& first) {
        pr(first); ps(); // no space at end of line
    }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...); // print w/ spaces
    }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}

using namespace io;

template<class T> T invGeneral(T a, T b) {
    a %= b; if (a == 0) return b == 1 ? 0 : -1;
    T x = invGeneral(b,a);
    return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}

template<class T> struct modular {
    T val;
    explicit operator T() const { return val; }
    modular() { val = 0; }
    modular(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD;
    }

    // friend ostream& operator<<(ostream& os, const modular& a) { return os << a.val; }
    friend void pr(const modular& a) { pr(a.val); }
    friend void re(modular& a) { ll x; re(x); a = modular(x); }

    friend bool operator==(const modular& a, const modular& b) { return a.val == b.val; }
    friend bool operator!=(const modular& a, const modular& b) { return !(a == b); }
    friend bool operator<(const modular& a, const modular& b) { return a.val < b.val; }

    modular operator-() const { return modular(-val); }
    modular& operator+=(const modular& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
    modular& operator-=(const modular& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
    modular& operator*=(const modular& m) { val = (ll)val*m.val%MOD; return *this; }
    friend modular pow(modular a, ll p) {
        modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans;
    }
    friend modular inv(const modular& a) {
        auto i = invGeneral(a.val,MOD); assert(i != -1);
        return i;
    } // equivalent to return exp(b,MOD-2) if MOD is prime
    modular& operator/=(const modular& m) { return (*this) *= inv(m); }

    friend modular operator+(modular a, const modular& b) { return a += b; }
    friend modular operator-(modular a, const modular& b) { return a -= b; }
    friend modular operator*(modular a, const modular& b) { return a *= b; }

    friend modular operator/(modular a, const modular& b) { return a /= b; }
};

typedef modular<int> mi;
typedef pair<mi,mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll cdiv(ll a, ll b) { return (a+b-1)/b; }

ll brute(ll a, ll n, ll p) {
	vl v;
	F0R(i,n+1) v.pb(a*i%p);
	sort(all(v));
	ll ret = 0;
	F0R(i,sz(v)-1) ckmax(ret,v[i+1]-v[i]);
	return ret;
}

ll solve(ll a, ll n, ll p) { // 4, 3
	a %= p;
	// ps("??",a,n,p);
	ll n2 = a*n/p; // how many times you subtracted p
	if (!n2) return a;
	ll a2 = a-p%a; // 5-3 = 2
	ll cat = p/a-1;
	if (n < cdiv(n2*p,a)+cat) n2 --; // how many times to get to n2*p
	if (n2*a2 < a) return max(a2,a-n2*a2);
	if (n2*(a-a2) < a) return max(a-a2,a-n2*(a-a2));
	return solve(min(a2,a-a2),n2,a);
	// (ll)n*a/p is equal to the number of runarounds

}

int main() {
    setIO();
    // ps(solve(4,3,5)); exit(0);
    /*FOR(p,2,21) FOR(a,1,21) FOR(n,1,p) if (__gcd(a,p) == 1) {
    	auto x = brute(a,n,p);
    	auto y = solve(a,n,p);
    	if (x != y) {
    		ps("HUH",a,n,p,x,y);
    		exit(0);
    	}
    }*/
	int t; re(t);
    F0R(i,t) {
    	int a,n,h;
		re(a,n,p,h);
		// ps("HUH",solve(a,n));
		if (solve(a,n) <= h) ps("YES");
		else ps("NO");
    }
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 200005;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);

    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }

    template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}

using namespace input;

namespace output {
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    template<class T, size_t SZ> void pr(const array<T,SZ>& x);
    template<class T> void pr(const vector<T>& x);
    template<class T> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);

    template<class T> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }

    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.f,", ",x.s,"}");
    }
    template<class T> void prContain(const T& x) {
        pr("{");
        bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
        pr("}");
    }
    template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    template<class T> void pr(const vector<T>& x) { prContain(x); }
    template<class T> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

    void ps() { pr("\n"); }
    template<class Arg> void ps(const Arg& first) {
        pr(first); ps(); // no space at end of line
    }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...); // print w/ spaces
    }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}

using namespace io;

template<class T> T invGeneral(T a, T b) {
    a %= b; if (a == 0) return b == 1 ? 0 : -1;
    T x = invGeneral(b,a);
    return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}

template<class T> struct modular {
    T val;
    explicit operator T() const { return val; }
    modular() { val = 0; }
    modular(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD;
    }

    // friend ostream& operator<<(ostream& os, const modular& a) { return os << a.val; }
    friend void pr(const modular& a) { pr(a.val); }
    friend void re(modular& a) { ll x; re(x); a = modular(x); }

    friend bool operator==(const modular& a, const modular& b) { return a.val == b.val; }
    friend bool operator!=(const modular& a, const modular& b) { return !(a == b); }
    friend bool operator<(const modular& a, const modular& b) { return a.val < b.val; }

    modular operator-() const { return modular(-val); }
    modular& operator+=(const modular& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
    modular& operator-=(const modular& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
    modular& operator*=(const modular& m) { val = (ll)val*m.val%MOD; return *this; }
    friend modular pow(modular a, ll p) {
        modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans;
    }
    friend modular inv(const modular& a) {
        auto i = invGeneral(a.val,MOD); assert(i != -1);
        return i;
    } // equivalent to return exp(b,MOD-2) if MOD is prime
    modular& operator/=(const modular& m) { return (*this) *= inv(m); }

    friend modular operator+(modular a, const modular& b) { return a += b; }
    friend modular operator-(modular a, const modular& b) { return a -= b; }
    friend modular operator*(modular a, const modular& b) { return a *= b; }

    friend modular operator/(modular a, const modular& b) { return a /= b; }
};

typedef modular<int> mi;
typedef pair<mi,mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll cdiv(ll a, ll b) { return (a+b-1)/b; }

ll brute(ll a, ll n, ll p) {
	vl v;
	F0R(i,n+1) v.pb(a*i%p);
	sort(all(v));
	ll ret = 0;
	F0R(i,sz(v)-1) ckmax(ret,v[i+1]-v[i]);
	return ret;
}

ll solve(ll a, ll n, ll p) { // 4, 3
	a %= p;
	// ps("??",a,n,p);
	ll n2 = a*n/p; // how many times you subtracted p
	if (!n2) return a;
	ll a2 = a-p%a; // 5-3 = 2
	ll cat = p/a-1;
	if (n < cdiv(n2*p,a)+cat) n2 --; // how many times to get to n2*p
	if (n2*a2 < a) return max(a2,a-n2*a2);
	if (n2*(a-a2) < a) return max(a-a2,a-n2*(a-a2));
	return solve(min(a2,a-a2),n2,a);
	// (ll)n*a/p is equal to the number of runarounds

}

int main() {
    setIO();
    // ps(solve(4,3,5)); exit(0);
    /*FOR(p,2,21) FOR(a,1,21) FOR(n,1,p) if (__gcd(a,p) == 1) {
    	auto x = brute(a,n,p);
    	auto y = solve(a,n,p);
    	if (x != y) {
    		ps("HUH",a,n,p,x,y);
    		exit(0);
    	}
    }*/
	int t; re(t);
    F0R(i,t) {
    	int a,n,p,h;
		re(a,n,p,h);
		// ps("HUH",solve(a,n));
		if (solve(a,n,p) <= h) ps("YES");
		else ps("NO");
    }
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pob pop_back

vector<int> v1,v2,v3;

int main()
{
    ll n,a;
    cin>>n;
    for(ll i=0; i<n; i++){
            cin>>a;
     if(a<0) v1.pb(a);
     else if(a>0) v2.pb(a);
     else v3.pb(a);
    }
    if(v1.size()%2==0){
        v3.pb(v1.back());
        v1.pob();
    }
    else if(v2.size()==0 && v1.size()%2 !=0){
        for(ll i=0; i<2; i++){
            v2.pb(v1.back());
            v1.pob();
        }
    }
    cout<<v1.size();
    for(ll i =0; i<v1.size(); i++){
        cout<<" "<<v1[i];
    }
    cout<<endl;

     cout<<v2.size();
    for(ll i =0; i<v2.size(); i++){
        cout<<" "<<v2[i];
    }
    cout<<endl;

     cout<<v3.size();
    for(ll i =0; i<v3.size(); i++){
        cout<<" "<<v3[i];
    }
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> v1,v2,v3;

int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	int cnt1=0,cnt2=0,cnt3=0;
	for(int i=0; i<n; i++){
		if(a[i]<0){
			cnt1++;
			v1.push_back(a[i]);

		}
		else if(a[i]>0){
			cnt2++;
			v2.push_back(a[i]);
		}
		else{
			cnt3++;
			v3.push_back(a[i]);
		}

	}
	if(v1.size()%2!=0){
        cout<<1<<" "<<v1[0]<<endl;
	}
	for(int i=1; i<=v1.size()-1; i++){
        v2.push_back(v1[i]);
	}
	cout<<v2.size();
	for(int i=0; i<v2.size(); i++){
        cout<<" "<<v2[i];
	}
	cout<<endl;
	cout<<v3.size();
	for(int i=0; i<v3.size(); i++){
        cout<<" "<<v3[i];
	}
	cout<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pob pop_back

vector<int> v1,v2,v3;

int main()
{
    ll n,a;
    cin>>n;
    for(ll i=0; i<n; i++){
            cin>>a;
     if(a<0) v1.pb(a);
     else if(a>0) v2.pb(a);
     else v3.pb(a);
    }
    if(v1.size()%2==0){
        v3.pb(v1.back());
        v1.pob();
    }
    else if(v2.size()==0){
        for(ll i=0; i<2; i++){
            v2.pb(v1.back());
            v1.pob();
        }
    }
    cout<<v1.size();
    for(ll i =0; i<v1.size(); i++){
        cout<<" "<<v1[i];
    }
    cout<<endl;

     cout<<v2.size();
    for(ll i =0; i<v2.size(); i++){
        cout<<" "<<v2[i];
    }
    cout<<endl;

     cout<<v3.size();
    for(ll i =0; i<v3.size(); i++){
        cout<<" "<<v3[i];
    }
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back

vector<ll> v1,v2,v3;

 int main()
 {
     ll n;
     cin>>n;
     int a[n+1];
     for(ll i=0; i<n; i++){
        cin>>a[i];
     }
     for(ll i=0; i<n; i++){
        if(a[i]<0) v1.pb(a[i]);
        else if(a[i]>0) v2.pb(a[i]);
        else v3.pb(a[i]);
     }
    ll s= v1.size();
     if(v1.size()%2==0){
        v3.pb(v1[s-1]);
       s =  s-1;
     }
     else if(v1.size()%2 != 0 && v2.size()==0){
        for(ll i=1; i<=2; i++){
            v2.pb(v1[i]);
        }
        s=s-2;
     }
     cout<<s;
     for(ll i=0; i<s; i++){
        cout<<" "<<v1[i];
     }
     cout<<endl;

     cout<<v2.size();
     for(ll i=0; i<v2.size(); i++){
        cout<<" "<<v2[i];
     }
     cout<<endl;

     cout<<v3.size();
     for(ll i=0; i<v3.size(); i++){
        cout<<" "<<v3[i];
     }
     cout<<endl;
     return 0;
 }


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pob pop_back

vector<int> v1,v2,v3;

int main()
{
    ll n,a;
    cin>>n;
    for(ll i=0; i<n; i++){
            cin>>a;
     if(a<0) v1.pb(a);
     else if(a>0) v2.pb(a);
     else v3.pb(a);
    }
    if(v2.size()==0){
        for(ll i=0; i<2; i++){
            v2.pb(v1.back());
            v1.pob();
        }
    }
    if(v1.size()%2==0){
        v3.pb(v1.back());
        v1.pob();
    }

    cout<<v1.size();
    for(ll i =0; i<v1.size(); i++){
        cout<<" "<<v1[i];
    }
    cout<<endl;

     cout<<v2.size();
    for(ll i =0; i<v2.size(); i++){
        cout<<" "<<v2[i];
    }
    cout<<endl;

     cout<<v3.size();
    for(ll i =0; i<v3.size(); i++){
        cout<<" "<<v3[i];
    }
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int> v1,v2,v3;

int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	int cnt1=0,cnt2=0,cnt3=0;
	v1.clear();
	v2.clear();
	v3.clear();
	for(int i=0; i<n; i++){
		if(a[i]<0){
			cnt1++;
			v1.push_back(a[i]);

		}
		else if(a[i]>0){
			cnt2++;
			v2.push_back(a[i]);
		}
		else{
			cnt3++;
			v3.push_back(a[i]);
		}

	}
	cout<<v1.size();
	for(int i=0; i<v1.size(); i++){
        cout<<" "<<v1[i];
	}
	cout<<endl;
	cout<<v2.size();
	for(int i=0; i<v2.size(); i++){
        cout<<" "<<v2[i];
	}
	cout<<endl;
	cout<<v3.size();
	for(int i=0; i<v3.size(); i++){
        cout<<" "<<v3[i];
	}
	cout<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
vector<int>v1,v2,v3;
int main()
{
    ll n;
    cin>>n;
    ll a[n+1];
    for(ll i=0; i<n; i++){
        cin>>a[i];
    }
    for(ll i=0; i<n; i++){
        if(a[i]<0)
            v1.pb(a[i]);
        else if(a[i]>0)
            v2.pb(a[i]);
        else v3.pb(a[i]);
    }
    if(v1.size()==1){
        for(ll i=0; i<1; i++){
            cout<<1<<" "<<v1[i]<<endl;
        }
    }
    else if(v1.size()==2){
            cout<<1<<" "<<v1[1]<<endl;
            v3.pb(v2.size()-1);
    }
    else{
        cout<<1<<" "<<v1[0]<<endl;
     for(ll i=1; i<v1.size(); i++){
            v2.pb(v1[i]);
        }
    }
        cout<<v2.size();
        for(ll i=0; i<v2.size(); i++){
            cout<<" "<<v2[i];
        }
        cout<<endl;
        cout<<v3.size();
        for(ll i=0; i<v3.size(); i++){
            cout<<" "<<v3[i];
        }
        cout<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
vector<int>v1,v2,v3;
int main()
{
    ll n;
    cin>>n;
    ll a[n+1];
    for(ll i=0; i<n; i++){
        cin>>a[i];
    }
    for(ll i=0; i<n; i++){
        if(a[i]<0)
            v1.pb(a[i]);
        else if(a[i]>0)
            v2.pb(a[i]);
        else v3.pb(a[i]);
    }
    if(v1.size()==1){
        for(ll i=0; i<1; i++){
            cout<<1<<" "<<v1[i]<<endl;
        }
    }
    else if(v1.size()==2){
            cout<<1<<" "<<v1[0]<<endl;
            v3.pb(v1[1]);
    }
    else{
        cout<<1<<" "<<v1[0]<<endl;
     for(ll i=1; i<v1.size(); i++){
            v2.pb(v1[i]);
        }
    }
        cout<<v2.size();
        for(ll i=0; i<v2.size(); i++){
            cout<<" "<<v2[i];
        }
        cout<<endl;
        cout<<v3.size();
        for(ll i=0; i<v3.size(); i++){
            cout<<" "<<v3[i];
        }
        cout<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define llt long long int
int main()
{
    int pos=0,neg=0,n;
    cin >> n;
    set<int>s;
    for(int i=0;i<n;i++)
    {
        int temp;
        cin >> temp;
        s.insert(temp);
    }
    set<int>s1,s2;
    auto it = s.begin();
    s1.insert(*it);
    it++;
    for(;*it<0 && it!=s.end();it++)
        s2.insert(*it);
    it++;
    for(;it!=s.end();it++)
        s2.insert(*it);
    cout << s1.size() << " ";
    for(auto it = s1.begin();it!=s1.end();it++)
        cout << *it << " ";
    cout << endl;
    cout << s2.size() << " ";
    for(auto it = s2.begin();it!=s2.end();it++)
        cout << *it << " " ;
    cout << endl;
    cout << "1" << " ";
    cout << "0";
    cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define llt long long int
int main()
{
    int pos=0,neg=0,n;
    cin >> n;
    set<int>s;
    for(int i=0;i<n;i++)
    {
        int temp;
        cin >> temp;
        if(temp<0)
            neg++;
        s.insert(temp);
    }
    set<int>s1,s2,s3;
    s3.insert(0);
    auto it = s.begin();
    s1.insert(*it);
    if(neg%2==0)
    {
        it++;
        s3.insert(*it);
    }
    it++;
    for(;*it<0 && it!=s.end();it++)
        s2.insert(*it);
    it++;
    for(;it!=s.end();it++)
        s2.insert(*it);
    cout << s1.size() << " ";
    for(auto it = s1.begin();it!=s1.end();it++)
        cout << *it << " ";
    cout << endl;
    cout << s2.size() << " ";
    for(auto it = s2.begin();it!=s2.end();it++)
        cout << *it << " " ;
    cout << endl;
    cout << s3.size() << " ";
    for(auto it = s3.begin();it!=s3.end();it++)
        cout << *it << " " ;
    cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define llt long long int
int main()
{
    int pos=0,neg=0,n;
    cin >> n;
    set<int>s;
    for(int i=0;i<n;i++)
    {
        int temp;
        cin >> temp;
        if(temp<0)
            neg++;
        s.insert(temp);
    }
    set<int>s1,s2;
    auto it = s.begin();
    s1.insert(*it);
    if(neg%2==0)
        s2.insert(*it);
    it++;
    for(;*it<0 && it!=s.end();it++)
        s2.insert(*it);
    it++;
    for(;it!=s.end();it++)
        s2.insert(*it);
    cout << s1.size() << " ";
    for(auto it = s1.begin();it!=s1.end();it++)
        cout << *it << " ";
    cout << endl;
    cout << s2.size() << " ";
    for(auto it = s2.begin();it!=s2.end();it++)
        cout << *it << " " ;
    cout << endl;
    cout << "1" << " ";
    cout << "0";
    cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define llt long long int
int main()
{
    int pos=0,neg=0,n;
    cin >> n;
    set<int>s;
    for(int i=0;i<n;i++)
    {
        int temp;
        cin >> temp;
        s.insert(temp);
    }
    set<int>s1,s2;
    auto it = s.begin();
    s1.insert(*it);
    it++;
    for(;*it<0 && it!=s.end();it++)
        s2.insert(*it);
    it++;
    for(;it!=s.end();it++)
        s2.insert(*it);
    for(auto it = s1.begin();it!=s1.end();it++)
        cout << *it << " ";
    cout << endl;
    for(auto it = s2.begin();it!=s2.end();it++)
        cout << *it << " " ;
    cout << endl;
    cout << "0";
    cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define llt long long int
int main()
{
    int pos=0,neg=0,n;
    cin >> n;
    set<int>s;
    for(int i=0;i<n;i++)
    {
        int temp;
        cin >> temp;
        if(temp<0)
            neg++;
        s.insert(temp);
    }
    set<int>s1,s2,s3;
    s3.insert(0);
    auto it = s.begin();
    s1.insert(*it);
    if(neg%2==0)
    {
        s3.insert(*it);
        it++;
    }
    it++;
    for(;*it<0 && it!=s.end();it++)
        s2.insert(*it);
    it++;
    for(;it!=s.end();it++)
        s2.insert(*it);
    cout << s1.size() << " ";
    for(auto it = s1.begin();it!=s1.end();it++)
        cout << *it << " ";
    cout << endl;
    cout << s2.size() << " ";
    for(auto it = s2.begin();it!=s2.end();it++)
        cout << *it << " " ;
    cout << endl;
    cout << s3.size() << " ";
    for(auto it = s3.begin();it!=s3.end();it++)
        cout << *it << " " ;
    cout << endl;
}


#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int main() {
    int n, num;
    cin >> n;
    vector<int> arr1, arr2, arr3, all;
    int prod1 = 1, prod2 = 1, prod3 = 1;
    for (int i = 0; i < n; i++) {
        cin >> num;
        all.push_back(num);
        if (num > 0) arr2.push_back(num), prod2 *= num;
        else if (num == 0) arr3.push_back(num), prod3 *= num;
        else if (num < 0) arr1.push_back(num), prod1 *= num;
    }
    if (arr1.size() % 2 == 0) {
        arr3.push_back(arr1[arr1.size() - 1]);
        arr1.pop_back();
    }
    if (arr2.empty()) {
        arr2.push_back(arr1[arr1.size() - 1]);
        arr1.pop_back();
        arr2.push_back(arr1[arr1.size() - 1]);
        arr1.pop_back();
    }

    cout << arr1.size() << " ";
    for (int i = 0; i < arr1.size(); i++) cout << arr1[i] << " ";
    cout << endl;
    cout << arr2.size() << " ";
    for (int i = 0; i < arr2.size(); i++) cout << arr2[i] << " ";
    cout << endl;
    cout << arr3.size() << " ";
    for (int i = 0; i < arr3.size(); i++) cout << arr3[i] << " ";

    return 0;
}


#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <queue>

using namespace std;

vector<int>::iterator getLessNum(vector<int> arr) {
    vector<int>::iterator ite = arr.begin();
    for (; ite != arr.end(); ite++) {
        int val = *ite;
        if (val < 0) {
            return ite;
        }
    }
    return arr.end();
}

int main() {
    int n, num;
    cin >> n;
    vector<int> arr1, arr2, arr3, all;
    int prod1 = 1, prod2 = 1, prod3 = 1;
    for (int i = 0; i < n; i++) {
        cin >> num;
        all.push_back(num);
        if (num > 0) arr2.push_back(num), prod2 *= num;
        else if (num == 0) arr3.push_back(num), prod3 *= num;
        else if (num < 0) arr1.push_back(num), prod1 *= num;
    }

    if(prod1 > 0 && prod1 != 1){
        int val = arr1[arr1.size()-1];arr1.pop_back();prod1/=val ;
        if(prod2*val < 0){
            arr3.push_back(val);
        }else {
            arr2.push_back(val); prod2 *= val;
        }
    }
    else if(arr2.empty()){
        arr2.push_back(arr1[arr1.size()-1]); arr1.pop_back();
        arr2.push_back(arr1[arr1.size()-1]); arr1.pop_back();
    }

    cout << arr1.size() << " ";
    for (int i = 0; i < arr1.size(); i++) cout << arr1[i] << " ";
    cout << endl;
    cout << arr2.size() << " ";
    for (int i = 0; i < arr2.size(); i++) cout << arr2[i] << " ";
    cout << endl;
    cout << arr3.size() << " ";
    for (int i = 0; i < arr3.size(); i++) cout << arr3[i] << " ";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[105],n1out,countx=0;
    bool n1=false,n3[105];
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        n3[i]=true;
        cin>>a[i];
        if(a[i]==0)
        {
            n3[i]=false;
            countx--;
        }
        if(!n1&&a[i]<0)
        {
            n3[i]=false;
            countx--;
            n1=true;
            n1out=a[i];
        }
    }
    cout<<1<<' '<<n1out<<endl;
    cout<<n+countx<<' ';
    for(int i=1;i<=n;i++)
    {
        if(n3[i])
            cout<<a[i]<<' ';
    }
    cout<<endl<<-countx-1<<' ';
    for(int i=1;i<=-countx-1;i++)
        cout<<0<<' ';
    cout<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 105;
int n;
int nums[N];
vector<int>a,b,c;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>nums[i];
    int cnt1=0,cnt2=0;
    for(int i=1;i<=n;i++){
        if(nums[i]==0) c.push_back(nums[i]);
        if(nums[i]>0) b.push_back(nums[i]);
        if(nums[i]<0) a.push_back(nums[i]);
    }
    if(a.size() %2 == 0 && b.size()){
        c.push_back(a.back());
        a.pop_back();
    }
    if(b.empty()){
        for(int i=0;i<2;i++){
            b.push_back(a.back());
            a.pop_back();
        }
    }
    cout<<a.size()<<" ";
    for(int i=0;i<a.size();i++) cout<<a[i]<<" ";
    cout<<endl;
    cout<<b.size()<<" ";
    for(int i=0;i<b.size();i++) cout<<b[i]<<" ";
    cout<<endl;
    cout<<c.size()<<" ";
    for(int i=0;i<c.size();i++) cout<<c[i]<<" ";
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int read() {
	int x=0;
	bool f=1;
	char ch=getchar();
#define ge ch=getchar()
	for(; !isdigit(ch); ge) if(ch=='-') f=0;
	for(; isdigit(ch); ge) x=(x<<3)+(x<<1)+ch-48;
	return f?x:-x;
}
int n,cnt1,cnt2,cnt3,num1,num2,fa;
int a[101],b[101],c[101],d[101];
int main() {
	n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		num2+=(a[i]>0);
	}
	for(int i=1;i<=n;i++)
	{
		if(num2==0&&fa<2&&a[i]<0)
		{
			b[++cnt1]=a[i];
			fa++;
			continue;
		}
		if(a[i]<0&&!cnt2) {
			c[++cnt2]=a[i];
			continue;
		}
		else if(a[i]<0&&cnt2)
		{
			d[++cnt3]=a[i];
			continue;
		}
		if(num2&&a[i]<0&&!cnt2)
		{
			c[++cnt2]=a[i];
			continue;
		}
		if(a[i]==0) {
			d[++cnt3]=a[i];
			continue;
		}
		if(a[i]>0)
		{
			if(!cnt1)
			{
				b[++cnt1]=a[i];
				continue;
			}
			else {
				d[++cnt3]=a[i];
				continue;
			}
		 }
	}
	printf("%d ",cnt2);
	for(int i=1;i<=cnt2;i++)
	printf("%d ",c[i]);
	printf("\n");
	printf("%d ",cnt1);
	for(int i=1;i<=cnt1;i++)
	printf("%d ",b[i]);
	printf("\n");
	printf("%d ",cnt3);
	for(int i=1;i<=cnt3;i++)
	printf("%d ",d[i]);
	printf("\n");
	return 0;
}