You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side.

Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section is equal to $h_i$.

You should follow several rules to build the fence:

the consecutive sections should have a common side of length at least $1$;

the first and the last sections should stand on the corresponding ground levels;

the sections between may be either on the ground level or higher, but not higher than $k - 1$ from the ground level $h_i$ (the height should be an integer);

One of possible fences (blue color) for the first test case

Is it possible to build a fence that meets all rules?


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The first line of each test case contains two integers $n$ and $k$ ($2 \le n \le 2 \cdot 10^5$; $2 \le k \le 10^8$) — the number of sections in the fence and the height of each section.

The second line of each test case contains $n$ integers $h_1, h_2, \dots, h_n$ ($0 \le h_i \le 10^8$), where $h_i$ is the ground level beneath the $i$-th section.

It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$.


-----Output-----

For each test case print YES if it's possible to build the fence that meets all rules. Otherwise, print NO.

You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).


-----Examples-----

Input
3
6 3
0 0 2 5 1 1
2 3
0 2
3 2
3 0 2
Output
YES
YES
NO


-----Note-----

In the first test case, one of the possible fences is shown in the picture.

In the second test case, according to the second rule, you should build both sections on the corresponding ground levels, and since $k = 3$, $h_1 = 0$, and $h_2 = 2$ the first rule is also fulfilled.

In the third test case, according to the second rule, you should build the first section on height $3$ and the third section on height $2$. According to the first rule, the second section should be on the height of at least $2$ (to have a common side with the first section), but according to the third rule, the second section can be built on the height of at most $h_2 + k - 1 = 1$.

Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Amortized analysis

Implementation

Greedy algorithms
Skill types: Dynamic programming

Amortized analysis

Greedy algorithms

Starter code:

Solutions:
for _ in range(int(input())):
	(n, h) = map(int, input().split())
	a = list(map(int, input().split()))
	mi = a[0]
	ma = a[0]
	a = a[1:]
	s = 1
	for x in a:
		mi = max(x, mi - h + 1)
		ma = min(x + h - 1, ma + h - 1)
		if ma < mi:
			s = 0
	if mi != a[-1]:
		s = 0
	print('YES') if s == 1 else print('NO')


from sys import stdin
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	(bot, top) = (lst[0], lst[0])
	for i in range(1, n):
		bot = max(0, max(lst[i], bot - k + 1))
		top = min(lst[i] + k - 1, top + k - 1)
		if bot > top:
			print('NO')
			break
	else:
		if bot <= lst[-1] <= top:
			print('YES')
		else:
			print('NO')


from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	(n, k) = map(int, input().split())
	hh = [int(a) for a in input().split()]
	mx = hh[0]
	for h in hh[1:]:
		if h > mx + k - 1:
			print('No')
			return
		else:
			mx = min(mx + k - 1, h + k - 1)
	mx = hh[-1]
	for h in hh[-2::-1]:
		if h > mx + k - 1:
			print('No')
			return
		else:
			mx = min(mx + k - 1, h + k - 1)
	print('Yes')

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	(n, k) = sep()
	h = lis()
	mn = h[0]
	mx = h[0]
	for i in range(1, n):
		mn = max(mn - (k - 1), h[i])
		mx = min(mx + k - 1, h[i] + k - 1)
		if mn > mx:
			break
	if not mn <= h[-1] <= mx:
		print('NO')
		return
	print('YES')
testcase(int(inp()))


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, k) = R()
	(l, *a) = R()
	h = l
	f = 0
	for x in a:
		l = max(l - k + 1, x)
		h = min(h, x) + k - 1
		f |= l > h
	print('YNEOS'[l > a[-1] or f::2])


from functools import reduce
import os
import sys
from collections import *
from decimal import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	(n, k) = value()
	a = arr()
	mn = a[0]
	mx = a[0] + k
	ans = 'YES'
	for i in range(1, n - 1):
		if a[i] < mn:
			if a[i] + k - 1 + k <= mn:
				ans = 'NO'
				break
			mn = max(a[i], mn - (k - 1))
			mx = a[i] + k - 1 + k
		else:
			if a[i] >= mx:
				ans = 'NO'
				break
			mn = a[i]
			mx = min(a[i] + k - 1, mx - 1) + k
	if a[-1] >= mx or a[-1] + k <= mn:
		ans = 'NO'
	print(ans)


from sys import stdin
T = int(stdin.readline().strip())
for caso in range(T):
	(n, k) = map(int, stdin.readline().strip().split())
	s = list(map(int, stdin.readline().strip().split()))
	mx = s[0] + k
	mn = s[0] + k
	f = True
	for i in range(1, n - 1):
		if mx <= s[i] or mn - k + 1 > s[i] + k + k - 1:
			f = False
		mx = min(s[i] + k - 1 + k, mx + k - 1)
		mn = max(s[i] + k, mn - k + 1)
	if mx <= s[-1] or mn - k + 1 > s[-1] + k:
		f = False
	if f:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	mn = h[0]
	mx = h[0]
	f = 0
	for i in range(1, n - 1):
		mn = max(h[i], mn - (k - 1))
		mx = min(h[i] + k - 1, mx + k - 1)
		if mn > mx:
			f = 1
	if h[n - 1] < mn - k + 1 or h[n - 1] > mx + k - 1:
		f = 1
	if f == 1:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
for nt in range(int(input())):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	ans = 'YES'
	minn = h[0]
	maxx = h[0]
	for i in range(1, n):
		minn = max(h[i], minn - k + 1)
		maxx = min(h[i] + k - 1, maxx + k - 1)
		if maxx < minn or minn + k - 1 < maxx:
			ans = 'NO'
			break
	if minn > h[-1] or h[-1] > maxx:
		ans = 'NO'
	print(ans)


def calc():
	[n, k] = list(map(int, input().split(' ')))
	h = list(map(int, input().split(' ')))
	l = [0] * n
	u = [0] * n
	for i in range(1, n):
		l[i] = max([h[i - 1] + l[i - 1] - k + 1, h[i]]) - h[i]
		if l[i] >= k:
			print('NO')
			return
		u[i] = min([h[i - 1] + u[i - 1] + k - 1, h[i] + k - 1]) - h[i]
		if u[i] < 0 or u[i] < l[i]:
			print('NO')
			return
	if l[n - 1] == 0:
		print('YES')
	else:
		print('NO')
t = int(input())
for i in range(t):
	calc()


from sys import stdin
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())

def fun():
	(n, k) = mp()
	l = mp()
	(low, high) = (l[0], l[0])
	for i in l[1:]:
		(low, high) = (max(low - k + 1, i), min(high + k - 1, i + k - 1))
		if low > high:
			return False
	return low <= l[-1] <= high
for _ in range(it()):
	if fun():
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
import math as M
import itertools as ITR
from collections import defaultdict as D
from collections import Counter as C
from collections import deque as Q
import threading
from functools import lru_cache, reduce
from functools import cmp_to_key as CMP
from bisect import bisect_left as BL
from bisect import bisect_right as BR
import random as R
import string
import cmath, time
enum = enumerate
start_time = time.time()
MOD = 1000000007
MA = float('inf')
MI = float('-inf')
di8 = ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1))
di4 = ((1, 0), (0, 1), (-1, 0), (0, -1))

def increase_stack():
	sys.setrecursionlimit(2 ** 32 // 2 - 1)
	threading.stack_size(1 << 27)

def binary(n):
	return bin(n)[2:]

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def maxfactor(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
	if q:
		return q[-1]

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(M.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	l.sort()
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def seive(n):
	a = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	prime[0] = prime[1] = False
	return (a, prime)

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(M.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countchar(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def str_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def lis(arr):
	n = len(arr)
	lis = [1] * n
	maximum = 0
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
				maximum = max(maximum, lis[i])
	return maximum

def lcm(arr):
	a = arr[0]
	val = arr[0]
	for i in range(1, len(arr)):
		gcd = gcd(a, arr[i])
		a = arr[i]
		val *= arr[i]
	return val // gcd

def ncr(n, r):
	return M.factorial(n) // (M.factorial(n - r) * M.factorial(r))

def npr(n, r):
	return M.factorial(n) // M.factorial(n - r)

def IF(c, t, f):
	return t if c else f

def YES(c):
	print(IF(c, 'YES', 'NO'))

def Yes(c):
	print(IF(c, 'Yes', 'No'))

def yes(c):
	print(IF(c, 'yes', 'no'))

def JA(a, sep=' '):
	print(sep.join(map(str, a)))

def JAA(a, s='\n', t=' '):
	return s.join((t.join(map(str, b)) for b in a))

def PS(a, s=' '):
	print(str(a), end=s)

def I():
	return int(inp())

def F():
	return float(inp())

def LI():
	return list(map(int, inp().split()))

def LF():
	return list(map(float, inp().split()))

def MATI(n):
	return [LI() for i in range(n)]

def MATS(n):
	return [list(inp()) for i in range(n)]

def IV():
	return map(int, inp().split())

def FV():
	return map(float, inp().split())

def LS():
	return list(inp())

def S():
	return inp()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
inp = lambda : sys.stdin.readline().rstrip('\r\n')
TestCases = 1

def solve():
	(n, k) = IV()
	arr = LI()
	(mi, ma) = (arr[0], arr[0])
	flag = True
	for i in range(1, n):
		mi = max(arr[i], mi - k + 1)
		ma = min(ma + k - 1, arr[i] + k - 1)
		if mi > ma:
			flag = False
		if i == n - 1 and mi != arr[i]:
			flag = False
	YES(flag)

def main():
	flag = 1
	try:
		sys.stdin = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/input.txt', 'r')
		sys.stdout = open('c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/output.txt', 'w')
	except:
		flag = 0
	t = 1
	if TestCases:
		t = I()
	for _ in range(1, t + 1):
		solve()
	if flag:
		print('Time: %.4f sec' % (time.time() - start_time))
		localtime = time.asctime(time.localtime(time.time()))
		print(localtime)
		sys.stdout.close()
main()


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, k) = R()
	(l, *a, e) = R()
	h = l
	f = 1
	for x in a:
		l = max(l - k + 1, x)
		h = min(h, x) + k - 1
		f &= l <= h
	print('NYOE S'[f & (l - k < e < h + k)::2])


import sys
for _ in range(int(input())):
	(n, k) = map(int, sys.stdin.readline().split())
	h = [int(i) for i in sys.stdin.readline().split()]
	flag = 1
	available_interval = [h[0] + 1, h[0] + 1]
	for h_i in h:
		available_interval = [max(h_i + 1, available_interval[0] - k + 1), min(h_i + k + k - 1, available_interval[1] + k - 1)]
		if available_interval[1] - available_interval[0] + 1 < k or available_interval[0] - h_i > k:
			flag = 0
			break
	if flag and available_interval[0] == h[-1] + 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	lst = [0] * n
	lst[0] = h[0]
	for i in range(1, n - 1):
		if h[i] - lst[i - 1] >= k or lst[i - 1] - h[i] > 2 * (k - 1):
			print('NO')
			break
		if h[i + 1] > h[i]:
			lst[i] = min(lst[i - 1] + k - 1, h[i] + k - 1)
		else:
			lst[i] = max(h[i], lst[i - 1] - k + 1)
	else:
		if h[n - 1] - lst[n - 2] >= k or lst[n - 2] - h[n - 1] >= k:
			print('NO')
		else:
			print('YES')


n = int(input())
for i in range(n):
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	bot = nums[0]
	top = nums[0] + k
	control = 'YES'
	top2 = 0
	for j in range(1, n):
		if j == n - 1:
			top2 = nums[j] + k
		else:
			top2 = nums[j] + 2 * k - 1
		if top2 <= bot or nums[j] >= top:
			control = 'NO'
			break
		bot = max(nums[j], bot - k + 1)
		top = min(top + k - 1, top2)
	print(control)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	minn = [l[0]]
	maxx = [l[0]]
	for i in range(1, n):
		minnn = max(l[i], minn[i - 1] - k + 1)
		maxxx = min(l[i] + k - 1, maxx[i - 1] + k - 1)
		minn.append(minnn)
		maxx.append(maxxx)
	minn1 = [l[n - 1]]
	maxx1 = [l[n - 1]]
	i = n - 1
	j = 0
	while i > 0:
		i -= 1
		j += 1
		minnn = max(l[i], minn1[j - 1] - k + 1)
		maxxx = min(l[i] + k - 1, maxx1[j - 1] + k - 1)
		minn1.append(minnn)
		maxx1.append(maxxx)
	flag = 'YES'
	for i in range(n):
		if minn[i] > maxx[i] or minn1[i] > maxx1[i]:
			flag = 'NO'
			break
	print(flag)


def fence():
	(n, k) = map(int, input().split())
	H = list(map(int, input().split()))
	(l, r) = (0, 0)
	for i in range(len(H)):
		if i == 0:
			l = r = H[0]
		else:
			l = max(l - k + 1, H[i])
			r = min(r + k - 1, H[i] + k - 1)
		if l > r or (i == n - 1 and l != H[i]):
			return False
for _ in range(int(input())):
	if fence() == None:
		print('Yes')
	else:
		print('No')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	lo = list(h)
	hi = [i + k - 1 for i in h]
	hi[0] = lo[0]
	hi[n - 1] = lo[n - 1]
	valid = True
	for i in range(1, n):
		a = lo[i - 1] - k + 1
		b = hi[i - 1] + k - 1
		if a > hi[i] or b < lo[i]:
			valid = False
			break
		lo[i] = max(lo[i], a)
		hi[i] = min(hi[i], b)
	for i in range(n - 2, -1, -1):
		a = lo[i + 1] - k + 1
		b = hi[i + 1] + k - 1
		if a > hi[i] or b < lo[i]:
			valid = False
			break
		lo[i] = max(lo[i], a)
		hi[i] = min(hi[i], b)
	print('YES' if valid else 'NO')


def intersection(seg1, seg2):
	if seg1[0] <= seg2[0]:
		if seg1[1] < seg2[0]:
			return False
		elif seg1[1] <= seg2[1]:
			return [seg2[0], seg1[1]]
		else:
			return [seg2[0], seg2[1]]
	elif seg1[0] > seg2[1]:
		return False
	elif seg1[1] >= seg2[1]:
		return [seg1[0], seg2[1]]
	else:
		return [seg1[0], seg1[1]]
cases = int(input())
for _ in range(cases):
	(n, k) = list(map(int, input().split()))
	level = list(map(int, input().split()))
	seg_satis = [0, level[0]]
	seg_need = []
	seg_satis_temp = []
	den = 0
	for i in level[:-1]:
		seg_need = [i, i + k - 1]
		seg_satis_temp = intersection(seg_satis, seg_need)
		if seg_satis_temp == False:
			den = 1
			break
		else:
			seg_satis = [seg_satis_temp[0] - k + 1, seg_satis_temp[1] + k - 1]
	if den == 1:
		print('NO')
	else:
		seg_need = [level[-1], level[-1]]
		seg_satis_temp = intersection(seg_satis, seg_need)
		if seg_satis_temp == False:
			print('NO')
		else:
			print('YES')


for ___ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	hs = list(map(int, input().split()))
	rg = [-2, 10 ** 9]
	ok = True
	for (i, h) in enumerate(hs):
		if i == 0 or i == len(hs) - 1:
			rgn = [h, h + k]
		else:
			rgn = [h, h + k + k - 1]
		rg = [max(0, rg[0] - k + 1), rg[1] + k - 1]
		rg = [max(rg[0], rgn[0]), min(rg[1], rgn[1])]
		if rg[1] - rg[0] < k:
			ok = False
			break
	print('YES' if ok else 'NO')


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import combinations, permutations
from bisect import *
from fractions import Fraction
from heapq import *
from random import randint

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		h = list(map(int, input().split()))
		mi = h[0] + 1
		ma = h[0] + k
		f = 1
		for i in range(1, n):
			(x, y) = (h[i] + 1, h[i] + k + (k - 1) * (i != n - 1))
			if x <= ma and y >= ma or (mi <= y and ma >= y):
				mi = max(mi - k + 1, h[i] + 1)
				ma = min(h[i] + 2 * k - 1, ma + k - 1)
			else:
				f = 0
				break
		if f:
			print('YES')
		else:
			print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	ans = 1
	(lb, ub) = (h[0], h[0])
	for i in range(1, n):
		lb_next = h[i]
		ub_next = h[i] + k - 1
		lb_next = max(lb - (k - 1), lb_next)
		ub_next = min(ub + (k - 1), ub_next)
		if lb_next > ub_next:
			ans = 0
			break
		lb = lb_next
		ub = ub_next
	if lb > h[n - 1] or ub < h[n - 1]:
		ans = 0
	print('YES' if ans else 'NO')


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	H = list(map(int, input().split()))
	(lo, hi) = (H[0] + k, H[0] + k)
	for i in range(1, n - 1):
		(lo, hi) = (max(H[i] + k, lo - (k - 1)), min(H[i] + 2 * k - 1, hi - 1 + k))
		if lo > hi:
			return 'NO'
	return 'YES' if lo - k < H[-1] + k < hi + k else 'NO'
for _ in range(int(input())):
	print(solve())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	temp = l[0]
	prev = temp
	flag = False
	for i in range(1, n):
		temp = max(temp + 1 - k, l[i])
		prev = min(prev - 1 + k, l[i] + k - 1)
		if temp > prev:
			print('NO')
			flag = True
			break
	if flag:
		continue
	if l[n - 1] >= temp and prev >= l[n - 1]:
		print('YES')
	else:
		print('NO')


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		(n, k) = ria()
		a = ria()
		r = [0] * n
		f = 0
		for i in range(n):
			if i:
				lower = max(r[i - 1][0] + 1 - k, a[i])
				upper = min(a[i] + k - 1, r[i - 1][1] + k - 1)
				if lower > upper:
					f = 1
					print('NO')
					break
				r[i] = [lower, upper]
			else:
				r[i] = [a[i], a[i]]
		if f:
			continue
		if r[n - 1][0] > a[n - 1]:
			print('NO')
		else:
			print('YES')
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import heapq

def solve(h, k):
	if len(h) == 1:
		return True
	if len(h) == 2:
		return max(h) - min(h) < k
	n = len(h)
	UNDEF = -1
	total = [UNDEF] * n
	total[0] = h[0] + k
	total[-1] = h[-1] + k
	heap = []
	for j in range(1, n - 1):
		heapq.heappush(heap, (-h[j], j))
	while heap:
		(_, i) = heapq.heappop(heap)
		if total[i - 1] == UNDEF and total[i + 1] == UNDEF:
			total[i] = h[i] + k
		elif total[i - 1] == UNDEF and total[i + 1] != UNDEF:
			total[i] = max(h[i] + k, total[i + 1] - k + 1)
		elif total[i - 1] != UNDEF and total[i + 1] == UNDEF:
			total[i] = max(h[i] + k, total[i - 1] - k + 1)
		else:
			total[i] = max(h[i] + k, total[i - 1] - k + 1, total[i + 1] - k + 1)
	for i in range(n):
		if i > 0 and total[i] - k >= total[i - 1]:
			return False
		if i < n - 1 and total[i] - k >= total[i + 1]:
			return False
		if total[i] - k - h[i] > k - 1:
			return False
	return True
ans = []
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(*h,) = map(int, input().split())
	cur = 'YES' if solve(h, k) else 'NO'
	print(cur)
	ans.append(cur)


def solution(n, k, h):
	minn = h[0]
	maxx = h[0]
	for i in range(1, n):
		minn = max(h[i], minn - k + 1)
		maxx = min(maxx + k - 1, h[i] + k - 1)
		if minn > maxx:
			return 'NO'
	if not (h[n - 1] >= minn and h[n - 1] <= maxx):
		return 'NO'
	return 'YES'
for i in range(int(input())):
	(n, k) = (int(i) for i in input().split())
	h = [int(i) for i in input().split()]
	print(solution(n, k, h))


for __ in range(int(input())):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	status = 1
	(dom1, dom2) = ([h[0] + 1 - k, h[0] + k - 1], [])
	if dom1[0] < 0:
		dom1[0] = 0
	for i in range(1, n):
		if i != n - 1:
			dom2 = [h[i], h[i] + k - 1]
		else:
			dom2 = [h[i], h[i]]
		if dom2[0] > dom1[1] or dom1[0] > dom2[1]:
			status = 0
			break
		else:
			t1 = max([dom1[0], dom2[0]]) + 1 - k
			t2 = min([dom1[1], dom2[1]]) + k - 1
			if t1 < 0:
				t1 = 0
			dom1 = [t1, t2]
	if status:
		print('YES')
	else:
		print('NO')


for test in range(int(input())):
	(_, k) = list(map(int, input().split()))
	h = list(map(int, input().split()))
	if len(h) == 2:
		if abs(h[0] - h[1]) <= k - 1:
			print('YES')
		else:
			print('NO')
	else:
		placement = h[0]
		for (i, h_i) in list(enumerate(h)):
			if i == 0:
				if h[i + 1] >= h_i:
					if h_i + k - 1 < h[i + 1]:
						print('NO')
						break
				elif h_i > h[i + 1] + k - 1 + k - 1:
					print('NO')
					break
			elif i == len(h) - 2:
				if h[i + 1] >= h_i:
					if min(h_i + k - 1, placement + k - 1) + k - 1 < h[i + 1]:
						print('NO')
						break
				elif max(h_i, placement - k + 1) > h[i + 1] + k - 1:
					print('NO')
					break
				print('YES')
				break
			elif h[i + 1] >= h_i:
				if min(h_i + k - 1, placement + k - 1) + k - 1 < h[i + 1]:
					print('NO')
					break
				placement = min(h_i + k - 1, placement + k - 1)
			else:
				if max(h_i, placement - k + 1) > h[i + 1] + k - 1 + k - 1:
					print('NO')
					break
				placement = max(h_i, placement - k + 1)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	(n, k) = mp()
	arr = lmp()
	mx = mn = arr[0]
	t = True
	for i in range(1, n):
		l = arr[i]
		u = arr[i] + (k - 1)
		mx = min(mx + (k - 1), u)
		mn = max(mn - (k - 1), l)
		if mx < mn:
			t = False
			break
	if mn > arr[-1] or mx < arr[-1]:
		t = False
	print('YES' if t else 'NO')


for _ in range(int(input())):
	bool = True
	(n, h) = map(int, input().split())
	list = [int(x) for x in input().split()]
	(maxi, mini) = (list[0], list[0])
	list = list[1:]
	for i in list:
		maxi = max(maxi - h + 1, i)
		mini = min(mini + h - 1, i + h - 1)
		if maxi > mini:
			bool = False
	if maxi != list[-1]:
		bool = False
	print('NO') if bool == False else print('YES')


from collections import Counter as cc
from copy import deepcopy as dc
import random
import math
MAX_SIZE = 1e+18
try:
	t = int(input())
	while t:
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		(lb, ub) = ([a[0]], [a[-1]])
		flag = 0
		for i in range(1, n):
			lb.append(min(a[i] + k - 1, lb[-1] + k - 1))
			if lb[-1] < a[i]:
				flag = 1
				break
		for i in reversed(range(n - 1)):
			ub.append(min(a[i] + k - 1, ub[-1] + k - 1))
			if ub[-1] < a[i]:
				flag = 1
				break
		if flag == 1:
			print('NO')
		else:
			print('YES')
except EOFError as e:
	pass


import sys
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

def inIList():
	return list(map(int, input().split()))

def inSList():
	return input().split()

def bsearch(nums, target):
	N = len(nums or [])
	l = 0
	r = N - 1
	while l <= r:
		mid = (l + r) // 2
		if nums[mid] < target:
			l = mid + 1
		elif nums[mid] > target:
			r = mid - 1
		else:
			return (None, mid, None)
	return (r if r >= 0 else None, None, l if l <= N - 1 else None)

def yesOrNo(val):
	print('YES' if val else 'NO')

def printSpacedArray(nums):
	print(*nums)

def solve():
	(n, k) = inIList()
	h = inIList()
	top = bottom = 0
	for i in range(n):
		if i == 0:
			top = bottom = h[i]
		else:
			bottom = max(bottom - k + 1, h[i])
			top = min(top + k - 1, h[i] + k - 1)
		if top < bottom:
			return 'NO'
	if bottom != h[-1]:
		return 'NO'
	return 'YES'
tests = inInt()
for case in range(tests):
	print(solve())


from collections import defaultdict, deque
import sys
import bisect
import math
input = sys.stdin.readline
mod = 1000000007
t = int(input())
for ii in range(t):
	(n, k) = map(int, input().split())
	h = [int(i) for i in input().split() if i != '\n']
	out = 'y'.join(map(str, h))
	(min_pos, max_pos) = (max(0, h[0] - k + 1), h[0] + k - 1)
	for i in range(1, n - 1):
		(s, e) = (h[i], h[i] + k - 1)
		if s > max_pos or min_pos > e:
			print('NO')
			break
		max_pos = min(max_pos + k - 1, e + k - 1)
		min_pos = max(0, min_pos - k + 1, s - k + 1)
	else:
		(s, e) = (h[-1], h[-1])
		if s > max_pos or min_pos > e:
			print('NO')
		else:
			print('YES')


t = int(input())
for _ in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	h = list(map(int, input().split()))
	poss = True
	lo = h[0]
	hi = h[0]
	for i in range(1, n):
		lo = lo - k + 1
		hi = hi + k - 1
		cl = h[i]
		ch = h[i] + k - 1
		if i == n - 1:
			ch = cl
		if hi < cl or ch < lo:
			poss = False
			break
		lo = max(lo, cl)
		hi = min(hi, ch)
	if poss:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	h = [int(i) for i in input().split()]
	s = 'YES'
	hh = hl = h[0]
	for i in range(1, n):
		hh = min(hh + k - 1, h[i] + k - 1)
		hl = max(hl - k + 1, h[i])
		if hh < hl:
			s = 'NO'
			break
	if hl != h[-1]:
		s = 'NO'
	print(s)


def solve(arr, k):
	n = len(arr)
	(preL, preH) = (arr[0] + k, arr[0] + k)
	for i in range(1, n - 1):
		lo = preL - k + 1
		hi = preH + k - 1
		if lo - k >= arr[i] + k or hi <= arr[i]:
			return 'NO'
		(preL, preH) = (max(lo, arr[i] + k), min(hi, arr[i] + 2 * k - 1))
		if preL > preH:
			return 'NO'
	lo = preL - k + 1
	hi = preH + k - 1
	if lo > arr[-1] + k or hi < arr[-1] + k:
		return 'NO'
	return 'YES'
for _ in range(int(input())):
	(_, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(arr, k))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = [int(j) for j in input().split()]
	current_range = [arr[0] + k, arr[0] + k]
	flag = 0
	for i in range(1, n - 1):
		if arr[i] >= current_range[1] or arr[i] + k - 1 + k <= current_range[0] - k:
			flag = 1
			break
		if arr[i] + k <= current_range[0] - k:
			current_range[0] = current_range[0] - k + 1
		else:
			current_range[0] = arr[i] + k
		current_range[1] = current_range[1] - 1 + k
		current_range[1] = min(current_range[1], arr[i] + k - 1 + k)
	if arr[-1] + k <= current_range[0] - k or arr[-1] >= current_range[1]:
		flag = 1
	if flag == 1:
		print('NO')
	else:
		print('YES')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [a[0]]
	c = [a[-1]]
	d = []
	for x in a[1:]:
		b.append(min(b[-1] + k - 1, x + k - 1))
	for x in reversed(a[:-1]):
		c.append(min(c[-1] + k - 1, x + k - 1))
	c.reverse()
	for x in range(n):
		d.append(min(b[x], c[x]))
	flag = 'YES'
	for x in range(n):
		if a[x] > d[x]:
			flag = 'NO'
			break
	print(flag)


def sv():
	(N, K) = map(int, input().split())
	H = list(map(int, input().split()))
	(a, b) = (0, 10000000000)
	for (n, h) in enumerate(H):
		a = max(a, h)
		b = min(b, h + K - 1 if n > 0 and n < N - 1 else h)
		if a > b:
			return False
		a -= K - 1
		b += K - 1
	return True
TC = int(input())
for tc in range(TC):
	print('YES' if sv() else 'NO')


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	x = a[0]
	y = a[0]
	x2 = a[n - 1]
	f = 1
	for i in range(n):
		if i == 0:
			x = y = a[0]
		else:
			x = max(x - k + 1, a[i])
			y = min(y + k - 1, a[i] + k - 1)
		if x > y:
			f = 0
		if i == n - 1 and x != a[i]:
			f = 0
	if f == 0:
		print('NO')
	else:
		print('YES')


def check(n, k, h):
	a = [h[0]]
	b = [h[0]]
	for i in range(1, n - 1):
		if h[i] >= b[i - 1] + k or h[i] + k <= a[i - 1] + 1 - k:
			return 'NO'
		else:
			a.append(max(a[i - 1] + 1 - k, h[i]))
			b.append(min(b[i - 1] - 1 + k, h[i] + k - 1))
	if b[n - 2] + k <= h[n - 1] or a[n - 2] >= h[n - 1] + k:
		return 'NO'
	else:
		return 'YES'
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	print(check(n, k, h))


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	heights = list(map(int, input().split()))
	min_pos = heights[0]
	max_pos = heights[0]
	possible = True
	for j in range(1, n):
		min_pos = min_pos - k + 1
		max_pos = max_pos + k - 1
		if max_pos >= heights[j] and min_pos <= heights[j] + k - 1 and (j != n - 1):
			min_pos = max(min_pos, heights[j])
			max_pos = min(max_pos, heights[j] + k - 1)
		elif j == n - 1 and max_pos >= heights[j] and (min_pos <= heights[j]):
			print('YES')
		else:
			print('NO')
			break


for testcase in range(int(input())):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	x = [a[0], a[0]]
	cond = True
	for i in a[1:-1]:
		x = [max(i, x[0] - k + 1), min(i + k - 1, x[1] + k - 1)]
		cond = cond and x[0] <= x[1]
	if a[-1] + k - 1 < x[0] or x[1] + k - 1 < a[-1]:
		cond = False
	print('YES' * cond + 'NO' * (not cond))


for _ in ' ' * int(input()):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	(p, x, f) = (a[0], a[0], 0)
	for i in range(1, n):
		(l, g) = (max(a[i], p - k + 1), min(a[i] + k - 1, x + k - 1))
		(p, x) = (l, g)
		if l > g:
			f = 1
			break
	print('YNEOS'[f or not p <= a[-1] <= x::2])


for t in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	h = [int(x) for x in input().split()]
	flag = True
	pu = h[0]
	pd = h[0]
	for i in range(1, n):
		if pu + k <= h[i] or pd + 1 - k > k - 1 + h[i]:
			flag = False
			break
		else:
			pu = min(pu + k - 1, h[i] + k - 1)
			pd = max(pd + 1 - k, h[i])
	if flag and h[n - 1] <= pu and (h[n - 1] >= pd):
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	(n, k) = map(int, input().split())
	mas = list(map(int, input().split()))
	mn = mas[0]
	mx = mas[0] + k - 1
	f = True
	for i in range(1, n):
		if mx - mn < k - 1:
			print('No')
			f = False
			break
		if i == n - 1 and mn - k + 1 > mas[i]:
			print('No')
			f = False
			break
		if i == n - 1 and mx < mas[i]:
			print('No')
			f = False
			break
		if mn - k + 1 >= mas[i] + k:
			print('No')
			f = False
			break
		if mx < mas[i]:
			print('No')
			f = False
			break
		mx = min(mx + k - 1, mas[i] + 2 * k - 2)
		mn = max(mas[i], mn - k + 1)
	if f:
		print('Yes')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	(curmx, curmn) = (ar[0], ar[0])
	for i in range(1, n):
		if curmx + (k - 1) < ar[i]:
			print('NO')
			break
		if curmn - (k - 1) > ar[i] + (k - 1):
			print('NO')
			break
		if i == n - 1 and curmn - (k - 1) > ar[i]:
			print('NO')
			break
		curmx = min(curmx + k - 1, ar[i] + k - 1)
		curmn = max(ar[i], curmn - (k - 1))
	else:
		print('YES')


def readLine():
	return [int(s) for s in input().split(' ')]

def solve():
	xd = readLine()
	n = xd[0]
	k = xd[1]
	h = readLine()
	lo = h[0] + 1
	hi = h[0] + 1
	c = 0
	for cur in h:
		c = c + 1
		if c == 1:
			continue
		lo = lo - (k - 1)
		hi = hi + (k - 1)
		hi = min(hi, cur + 1 + k - 1)
		lo = max(lo, cur + 1)
		if lo > hi:
			print('No')
			return
	if lo <= h[-1] + 1 and h[-1] + 1 <= hi:
		print('Yes')
	else:
		print('No')
tt = int(input())
for x in range(tt):
	solve()


nt = int(input())
for i in range(nt):
	[n, k] = [int(x) for x in input().split()]
	h = [int(x) for x in input().split()]
	mins = h
	maxs = [x + k - 1 for x in h]
	maxs[0] = h[0]
	maxs[n - 1] = h[n - 1]
	good = [1]

	def update(i, fmin, fmax):
		dif = 0
		if fmin > mins[i]:
			mins[i] = fmin
			dif = 1
		if fmax < maxs[i]:
			maxs[i] = fmax
			dif = 1
		if mins[i] > maxs[i]:
			good[0] = 0
			dif = 1
		return dif
	i = 0
	while 0 <= i < n - 1 and good[0]:
		if update(i, mins[i + 1] - (k - 1), maxs[i + 1] + (k - 1)):
			i -= 1
		else:
			update(i + 1, mins[i] - (k - 1), maxs[i] + (k - 1))
			i += 1
	print('YES' if good[0] else 'NO')


def getCases():
	cases = []
	t = int(input())
	for case in range(t):
		(n, k) = list(map(int, input().strip().split()))
		h = list(map(int, input().strip().split()))
		cases.append([n, k, h])
	return cases

def check(case):
	(n, k, heights) = case
	_min = heights[0]
	_max = heights[0]
	foo = True
	for i in range(1, n):
		_min = max(_min - k + 1, heights[i])
		_max = min(_max + k - 1, heights[i] + k - 1)
		if _min > _max:
			foo = False
			break
	if heights[n - 1] < _min or heights[n - 1] > _max:
		foo = False
	return 'YES' if foo else 'NO'
for case in getCases():
	print(check(case))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	end = False
	cur = h[0]
	for i in range(n):
		if cur < h[i]:
			end = True
			break
		if i != n - 1:
			cur = min(cur + k - 1, h[i + 1] + k - 1)
	cur = h[-1]
	for i in range(n - 1, -1, -1):
		if cur < h[i]:
			end = True
			break
		if i:
			cur = min(cur + k - 1, h[i - 1] + k - 1)
	if end:
		print('NO')
	else:
		print('YES')


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	D = [*map(int, input().split())]
	min_height = [0] * n
	max_height = [0] * n
	min_height[0] = D[0]
	max_height[0] = D[0]
	min_height[n - 1] = D[n - 1]
	max_height[n - 1] = D[n - 1]
	for i in range(1, n - 1):
		min_height[i] = min(D[i] + k - 1, max(0, D[i], min_height[i - 1] + 1 - k))
		max_height[i] = min(D[i] + k - 1, max_height[i - 1] + k - 1)
	err = 0
	for i in range(n - 1):
		if max_height[i] + k > min_height[i + 1] and min_height[i] < max_height[i + 1] + k:
			continue
		else:
			err = 1
	if not err:
		print('YES')
	else:
		print('NO')


import sys
import math, bisect, operator
(inf, mod) = (float('inf'), 10 ** 9 + 7)
sys.setrecursionlimit(10 ** 6)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
I = lambda : int(sys.stdin.readline())
neo = lambda : map(int, sys.stdin.readline().split())
Neo = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	(n, k) = neo()
	H = Neo()
	maxi = [0] * (n - 1)
	mini = [0] * (n - 1)
	maxi[0] = H[0] + k
	mini[0] = H[0] + k
	f = 1
	for i in range(1, n - 1):
		curmax = H[i] + k + k - 1
		curmn = H[i] + k
		prevmx = maxi[i - 1]
		prevmn = mini[i - 1] - k
		if curmax <= prevmn:
			f = 0
			break
		if H[i] >= prevmx:
			f = 0
			break
		maxi[i] = min(maxi[i - 1] + k - 1, curmax)
		mini[i] = max(curmn, prevmn + 1)
	if H[-1] + k <= mini[-1] - k or H[-1] >= maxi[-1]:
		f = 0
	print('Yes') if f else print('No')


import sys
from pprint import pprint

def do():
	(n, k) = map(int, input().split())
	dat = list(map(int, input().split()))
	(canl, canr) = (dat[0] + 1, dat[0] + k - 1 + 1)
	for i in range(1, n - 1):
		maxThisFloor = dat[i] + (k - 1) + k
		if maxThisFloor < canl:
			print('NO')
			return
		if canr <= dat[i]:
			print('NO')
			return
		canl = canl - (k - 1)
		canr = canr + (k - 1)
		canl = max(dat[i] + 1, canl)
		canr = min(canr, maxThisFloor)
	if canl - dat[n - 1] > k:
		print('NO')
		return
	if canr <= dat[n - 1]:
		print('NO')
		return
	print('YES')
q = int(input())
for _ in range(q):
	do()


import sys, os, getpass
import heapq as hq
import math, random, functools, itertools
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve_(lst, k):
	k = k - 1
	upper = lst[0] + k
	lower = max(0, lst[0] - k)
	for (i, x) in enumerate(lst[1:-1], start=1):
		if lower > x + k or upper < x:
			return 'no'
		upper = min(upper, x + k) + k
		lower = max(0, max(lower, x) - k)
	if lower <= lst[-1] <= upper:
		return 'YES'
	return 'NO'

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]
for case_num in range(int(input())):
	(_, k) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	res = solve(lst, k)
	print(res)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	MIN = A[0]
	MAX = A[0]
	flag = 1
	for i in range(1, n):
		h = A[i]
		NMIN = max(h, MIN - (k - 1))
		NMAX = min(MAX + (k - 1), h + (k - 1))
		if NMIN > NMAX:
			flag = 0
			break
		(MIN, MAX) = (NMIN, NMAX)
	if flag == 0:
		print('NO')
	elif MIN <= A[-1] <= MAX:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	l = input().split(' ')
	(n, k) = (int(l[0]), int(l[1]))
	l = input().split(' ')
	for j in range(n):
		l[j] = int(l[j])
	lastbl = l[0]
	lastbh = l[0]
	isok = True
	for j in range(1, n - 1):
		if lastbh + (k - 1) < l[j]:
			isok = False
			break
		if lastbl - (k - 1) > l[j] + (k - 1):
			isok = False
			break
		lastbl = max(lastbl - (k - 1), l[j])
		lastbh = min(lastbh + (k - 1), l[j] + (k - 1))
		if lastbh < lastbl:
			isok = False
			break
	if lastbh + (k - 1) < l[n - 1]:
		isok = False
	if lastbl - (k - 1) > l[n - 1]:
		isok = False
	print('YES' if isok else 'NO')


import sys
lines = []
for line in sys.stdin:
	lines.append(line.rstrip('\n'))
t = int(lines[0])
for i in range(1, 2 * t + 1, 2):
	(n, k) = map(int, lines[i].split(' '))
	h = list(map(int, lines[i + 1].split(' ')))
	(m, M) = (h[0], h[0])
	for j in range(1, n):
		M = min(h[j] + k - 1, M + k - 1)
		m = max(h[j], m - (k - 1))
		if M < m:
			break
	if m <= h[n - 1] and h[n - 1] <= M:
		print('YES')
	else:
		print('NO')


T = int(input())
ans = []
for t in range(T):
	flag = True
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	tmp = [0] * n
	tmp[0] = h[0]
	for i in range(1, n - 1):
		ma = min(tmp[i - 1] + k - 1, h[i] + k - 1)
		mi = max(tmp[i - 1] - k + 1, h[i])
		if mi > ma:
			flag = False
		if h[i + 1] > h[i]:
			tmp[i] = ma
		else:
			tmp[i] = mi
	if abs(h[n - 1] - tmp[n - 2]) >= k:
		flag = False
	ans.append('YES' if flag else 'NO')
for i in range(T):
	print(ans[i])


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, k) = inputnums()
	a = inputlist()
	good = True
	low = a[0]
	high = a[0]
	for i in range(1, n):
		low = max(a[i], low - k + 1)
		high = min(a[i] + k - 1, high + k - 1)
		if low > high:
			good = False
		if i == n - 1 and low > a[i]:
			good = False
	if good:
		print('YES')
	else:
		print('NO')


for tc in range(int(input())):
	(n, k) = map(int, input().split())
	ls = [int(x) for x in input().split()]
	(mn, mx) = (ls[0], ls[0])
	for h in ls[1:]:
		(mn, mx) = (max(mn - k + 1, h), min(mx + k - 1, h + k - 1))
		if mn > mx:
			print('NO')
			break
	else:
		if mn <= ls[-1] <= mx:
			print('YES')
		else:
			print('NO')


import sys
import math
import bisect
import functools
from functools import lru_cache
from sys import stdin, stdout
from math import gcd, floor, sqrt, log, ceil
from collections import defaultdict as dd
from collections import Counter as cc
from bisect import bisect_left as bl
from bisect import bisect_right as br
sys.setrecursionlimit(100000000)
intinp = lambda : int(input().strip())
stripinp = lambda : input().strip()
fltarr = lambda : list(map(float, input().strip().split()))
intarr = lambda : list(map(int, input().strip().split()))
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
MOD = 1000000007
num_cases = intinp()
for _ in range(num_cases):
	(n, k) = intarr()
	arr = intarr()
	prev = []
	flag = True
	for (i, h) in enumerate(arr):
		if not i:
			prev = [h, h + k]
		elif h <= prev[1] - 1 and h + k + k - 1 > prev[0]:
			prev = [max(h, prev[0] + 1 - k), min(h + k + k - 1, prev[1] - 1 + k)]
		else:
			flag = False
			break
	if flag and prev[0] == arr[-1] and (prev[1] >= arr[-1] + k):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	mn = h[0]
	mx = h[0]
	b = 0
	for i in range(1, n):
		mn = max(mn + 1 - k, h[i])
		mx = min(h[i] + k - 1, mx - 1 + k)
		if mn > mx:
			print('NO')
			b = 1
			break
	if b == 0:
		if mn == h[-1]:
			print('YES')
		else:
			print('NO')


t = int(input())
for testcases in range(t):
	(n, k) = list(map(int, input().split()))
	a = [int(x) for x in input().split()]
	s = -1
	r = -1
	ok = 1
	for x in a:
		if s == -1:
			s = x
			r = x
		else:
			s = max(s - k + 1, x)
			r = min(r + k - 1, x + k - 1)
		if s > r:
			ok = 0
			break
	if ok == 1 and s <= x:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	prev = h[0]
	con = 0
	for i in range(1, n - 1):
		if h[i] > h[i - 1]:
			if prev + k > h[i]:
				if h[i + 1] > h[i]:
					if h[i] + k - 1 < prev + k:
						prev = h[i] + k - 1
					else:
						prev = prev + k - 1
				else:
					prev = h[i]
			else:
				con = 1
				break
		elif h[i] < h[i - 1]:
			if h[i] + 2 * k - 1 > prev:
				if h[i + 1] > h[i]:
					prev = h[i] + k - 1
				elif prev - (k - 1) >= h[i]:
					prev = prev - (k - 1)
				else:
					prev = h[i]
			else:
				con = 1
				break
		elif h[i + 1] > h[i]:
			prev = h[i] + k - 1
		else:
			prev = h[i]
	if con == 1:
		print('NO')
	elif abs(prev - h[-1]) > k - 1:
		print('NO')
	else:
		print('YES')


def buildFence():
	(lowest, highest) = (heights[0], heights[0])
	for i in range(1, n - 1):
		(newLow, newHigh) = (heights[i], heights[i] + k - 1)
		if newHigh + k <= lowest or newLow >= highest + k:
			return False
		newLow += max(0, lowest + 1 - newLow - k)
		newHigh -= max(0, newHigh + 1 - highest - k)
		lowest = newLow
		highest = newHigh
	if lowest - k < heights[-1] < highest + k:
		return True
	else:
		return False
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	heights = list(map(int, input().split()))
	if buildFence():
		print('YES')
	else:
		print('NO')


import math
import sys

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	(n, k) = Read.list_int()
	h = Read.list_int()
	y0 = h[0]
	y1 = h[0]
	for i in range(n - 1):
		v = h[i + 1]
		y0 = max(v, y0 - k + 1)
		y1 = min(v + k - 1, y1 + k - 1)
		if y0 > y1:
			print('NO')
			return
	if y0 == h[-1]:
		print('YES')
	else:
		print('NO')
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = int(1000000000.0) + 7
MAX = int(200000.0) + 1

def solve():
	(n, k) = vars()
	arr = array()
	maxi = arr[0]
	mini = arr[0]
	for i in range(1, n):
		maxi = min(maxi + (k - 1), arr[i] + k - 1)
		mini = max(mini - (k - 1), arr[i])
		if mini > maxi:
			print('NO')
			return
	if arr[-1] != mini:
		print('NO')
	else:
		print('YES')

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def input():
	return sys.stdin.readline().rstrip('\n').strip()

def print(*args, sep=' ', end='\n'):
	first = True
	for arg in args:
		if not first:
			sys.stdout.write(sep)
		sys.stdout.write(str(arg))
		first = False
	sys.stdout.write(end)
primes = [1 for i in range(MAX)]

def sieve():
	global primes
	primes[0] = primes[1] = 0
	i = 2
	while i <= MAX ** 0.5:
		j = i * i
		while primes[i] and j < MAX:
			if j % i == 0:
				primes[j] = 0
			j += i
		i += 1

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))
main()


import sys
try:
	sys.stdin = open('input.txt', 'r')
except FileNotFoundError:
	pass

def next_array():
	return [int(i) for i in input().split()]

def prefix(lst):
	assert len(lst)
	pre = [lst[0]]
	for i in range(1, len(lst)):
		pre.append(lst[i] + pre[i - 1])
	return pre

def solve():
	(l, k) = next_array()
	lst = next_array()
	max_bottom = lst[0]
	min_bottom = lst[0]
	for i in range(1, l):
		if max_bottom + k - 1 < lst[i] or min_bottom - k + 1 > (lst[i] + k - 1 if i < l - 1 else lst[i]):
			print('NO')
			return
		max_bottom = min(max_bottom, lst[i]) + k - 1
		min_bottom = max(min_bottom - k + 1, lst[i])
	print('YES')
test_cases = True
if test_cases:
	for i in range(int(input())):
		solve()
else:
	solve()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):

	def __init__(self, file):
		self.newlines = 0
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def S():
	return input().strip()

def print_list(l):
	print(' '.join(map(str, l)))

def judge():
	(n, k) = RL()
	a = RLL()
	(low, high) = (a[0], a[0])
	for v in a[1:]:
		(low, high) = (max(low - k + 1, v), min(high + k - 1, v + k - 1))
		if low > high:
			return False
	return low <= a[-1] <= high
for _ in range(N()):
	print('YES' if judge() else 'NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	l = a[0]
	h = a[0] + k
	ans = 'YES'
	for i in range(1, n - 1):
		t1 = a[i] + 2 * k - 1
		if t1 <= l or h <= a[i]:
			ans = 'NO'
		l = max(l - k + 1, a[i])
		h = min(h + k - 1, t1)
	if a[n - 1] + k <= l or h <= a[n - 1]:
		ans = 'NO'
	print(ans)


for _ in ' ' * int(input()):
	(n, k) = map(int, input().split())
	(*h,) = map(int, input().split())
	min_hs = [h[0]] * n
	max_hs = [h[0]] * n
	for i in range(1, n):
		min_touch = min_hs[i - 1] - k + 1
		max_touch = max_hs[i - 1] + k - 1
		min_ground = h[i]
		max_ground = h[i] + k - 1 if i != n - 1 else h[i]
		min_pos = max(min_touch, min_ground)
		max_pos = min(max_touch, max_ground)
		if min_pos > max_pos:
			print('NO')
			break
		min_hs[i] = min_pos
		max_hs[i] = max_pos
	else:
		print('YES')


import sys
input = sys.stdin.readline
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().rstrip()

def solve_case():
	(n, k) = rl()
	h = rl()
	lo = hi = 0
	ok = True
	for (i, v) in enumerate(h):
		if i == 0:
			(lo, hi) = (v, v)
		else:
			(lo, hi) = (max(lo - (k - 1), v), min(hi + (k - 1), v + (k - 1)))
		if lo > hi:
			ok = False
	if ok and lo == h[-1]:
		print('YES')
	else:
		print('NO')
T = ri()
for _ in range(T):
	solve_case()


case = int(input())
for c in range(case):
	(n, k) = map(int, input().split())
	myList = list(map(int, input().split()))
	mini = myList[0]
	maxi = myList[0]
	ok = True
	for ind1 in range(1, len(myList)):
		mini = max(myList[ind1], mini - (k - 1))
		maxi = min(myList[ind1] + k - 1, maxi + k - 1)
		if myList[ind1] > maxi or myList[ind1] + k - 1 < mini:
			ok = False
			break
	if myList[len(myList) - 1] < mini or myList[len(myList) - 1] > maxi:
		ok = False
	if ok:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(_, k) = map(int, input().split())
	hs = list(map(int, input().split()))
	(lo, hi) = (hs[0], hs[0])
	valid = len(hs) < 2 or hs[1] - hs[0] < k
	for h in hs[1:]:
		lo = max(h, lo - k + 1)
		hi = min(hi + k - 1, h + k - 1)
		if lo > hi:
			valid = False
			break
	if valid and hs[-1] != lo:
		valid = False
	print('YES' if valid else 'NO')


def solve():
	[n, k] = map(int, input().split(' '))
	h = list(map(int, input().split(' ')))
	assert len(h) == n
	assert n >= 2
	lo = h[0] + 1
	hi = lo

	def bnd(x, xmin, xmax):
		return min(xmax, max(xmin, x))
	for i in range(1, n):
		new_lo = lo - (k - 1)
		new_hi = hi + (k - 1)
		if new_hi < h[i] + 1 or new_lo > h[i] + k:
			print('NO')
			return
		lo = bnd(new_lo, h[i] + 1, h[i] + k)
		hi = bnd(new_hi, h[i] + 1, h[i] + k)
		if lo > hi:
			print('NO')
			return
	print('YES' if lo <= h[n - 1] + 1 and h[n - 1] + 1 <= hi else 'NO')

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


t = int(input())
for testCaseCounter in range(t):
	splitted = [int(amit) for amit in input().split(' ')]
	n = splitted[0]
	k = splitted[1]
	arr = [int(amit) for amit in input().split(' ')]
	lowestStartingPoint = arr[0]
	highestStartingPoint = arr[0]
	valid = True
	for i in range(1, n):
		lowestStartingPoint = max(arr[i], lowestStartingPoint - (k - 1))
		highestStartingPoint = min(arr[i] + (k - 1), highestStartingPoint + (k - 1))
		if lowestStartingPoint > highestStartingPoint:
			valid = False
			break
	if valid and lowestStartingPoint <= arr[n - 1] <= highestStartingPoint:
		print('YES')
	else:
		print('NO')


from sys import *
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ini = [0 + l[0], k + l[0]]
	ans = 'YES'
	for i in range(1, n):
		pMin = ini[0] + 1 - k
		pMax = ini[1] - 1 + k
		if i < n - 1 and pMin - (k - 1) <= l[i] < ini[1]:
			ini = [max(pMin, l[i]), min(pMax, l[i] + k + k - 1)]
		elif i == n - 1 and pMin <= l[i] < ini[1]:
			pass
		else:
			ans = 'NO'
			break
	print(ans)


innum = lambda : int(input())
inmul = lambda : map(int, input().split())
instr = lambda : str(input())
inarr = lambda : list(map(int, input().split()))

def solve():
	(n, k) = inmul()
	a = inarr()
	ma = a[0]
	mi = a[0]
	for i in range(1, n - 1):
		mi = max(mi - (k - 1), a[i])
		ma = min(ma + k - 1, a[i] + k - 1)
		if mi > ma:
			print('NO')
			return
	if a[-1] >= mi - k + 1 and a[-1] <= ma + k - 1:
		print('YES')
	else:
		print('NO')

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


def getints():
	return list(map(int, input().split()))

def solve():
	(n, k) = getints()
	k1 = k - 1
	(hi, *hlist) = getints()
	lo = hi
	for h in hlist[:-1]:
		(lo, hi) = (max(lo - k1, h), min(hi + k1, h + k1))
		if hi < lo:
			return 'NO'
	if lo - k1 <= hlist[-1] <= hi + k1:
		return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solve())


t = int(input())
for _ in range(t):
	(n, k) = tuple(map(int, input().split()))
	h = list(map(int, input().split()))
	top = h[0]
	bottom = h[0]
	check = True
	for i in range(1, n):
		top = min(top + k - 1, h[i] + k - 1)
		bottom = max(h[i], bottom - k + 1)
		if bottom > top:
			check = False
			break
	if h[n - 1] < bottom or h[n - 1] > top:
		check = False
	if check:
		print('YES')
	else:
		print('NO')


def Fence(ground, k):
	max_fence_last = ground[0] + k
	min_fence_last = ground[0]
	for i in range(1, len(ground)):
		max_f = min(max_fence_last + k - 1, ground[i] + k + k - 1)
		min_f = max(min_fence_last - k + 1, ground[i])
		if max_f - min_f < k:
			return 'NO'
		max_fence_last = max_f
		min_fence_last = min_f
	if min_f != ground[i]:
		return 'NO'
	else:
		return 'YES'
for i in range(int(input())):
	k = int(input().split()[1])
	ground = list(map(int, input().split()))
	print(Fence(ground, k))


t = int(input())
for i in range(t):
	(n, k) = tuple(map(int, input().split(' ')))
	heights = list(map(int, input().split(' ')))
	current_floor_range = [heights[0], heights[0]]
	is_possible = True
	for j in range(1, n):
		current_floor_range = [max(current_floor_range[0] - k + 1, heights[j]), min(current_floor_range[1], heights[j]) + k - 1]
		if current_floor_range[0] > current_floor_range[1]:
			is_possible = False
			break
	print('YES' if is_possible and current_floor_range[0] <= heights[n - 1] <= current_floor_range[1] else 'NO')


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	h = list(map(int, input().split()))
	minL = h[0]
	maxL = h[0]
	done = True
	for i in range(1, n):
		minL = max(minL - k + 1, h[i])
		maxL = min(maxL + k - 1, h[i] + k - 1)
		if minL > maxL:
			done = False
			break
	if h[n - 1] > maxL or h[n - 1] < minL:
		done = False
	if done == True:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	d = [[-1, -1] for i in range(n)]
	d[0] = [h[0], h[0]]
	ans = 'YES'
	for i in range(1, len(h)):
		d[i] = [max(h[i], d[i - 1][0] - (k - 1)), min(h[i] + (k - 1), d[i - 1][1] + (k - 1))]
		if d[i][0] - h[i] > k - 1:
			ans = 'NO'
			break
		if d[i - 1][1] + k <= d[i][0]:
			ans = 'NO'
			break
	if d[-1][0] > h[-1]:
		ans = 'NO'
	print(ans)


import sys
input = sys.stdin.readline

def solution():
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	if n == 2:
		if abs(h[0] - h[-1]) >= k:
			print('NO')
			return
	sweep = []
	for i in range(1, n - 1):
		sweep.append((h[i], i))
	sweep.sort(reverse=True)
	H = [-1] * n
	H[0] = h[0]
	H[-1] = h[-1]
	for (h_i, i) in sweep:
		cur = h_i
		if H[i - 1] != -1:
			cur = max(cur, H[i - 1] + 1 - k)
		if H[i + 1] != -1:
			cur = max(cur, H[i + 1] + 1 - k)
		if cur - h_i >= k:
			print('NO')
			return
		H[i] = cur
	for i in range(n - 1):
		if abs(H[i] - H[i + 1]) >= k:
			print('NO')
			return
	print('YES')
T = int(input())
for _ in range(T):
	solution()


import os, sys
from io import BytesIO, IOBase

def solve(n, k, h):
	ls = [[-1, -1] for _ in range(n)]
	for i in h:
		ran = [-1, -1]
		ran1 = [-1, -1]
		if i[1] and ls[i[1] - 1] != [-1, -1]:
			xx = max(0, ls[i[1] - 1][0] + 1 - i[0] - k)
			if xx >= k:
				return 'NO'
			ran = [i[0] + xx, i[0] + xx + k]
		if i[1] != n - 1 and ls[i[1] + 1] != [-1, -1]:
			xx1 = max(0, ls[i[1] + 1][0] + 1 - i[0] - k)
			if xx1 >= k:
				return 'NO'
			ran1 = [i[0] + xx1, i[0] + xx1 + k]
		ran = max([ran, ran1], key=lambda xxx: xxx[0])
		if not i[1] or i[1] == n - 1:
			if ran[0] != i[0] and ran[0] != -1:
				return 'NO'
		if ran == [-1, -1]:
			ls[i[1]] = [i[0], i[0] + k]
		else:
			ls[i[1]] = ran
	return 'YES'

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		h = list(map(lambda x: [int(x), 0], input().split()))
		for i in range(n):
			h[i][1] = i
		h.sort(key=lambda x: x[0], reverse=1)
		print(solve(n, k, h))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	hi = list(map(int, input().split()))
	minh = hi[0] - k + 1
	maxh = hi[0] + k - 1
	ans = 1
	for i in range(1, n - 1):
		curminh = hi[i]
		curmaxh = hi[i] + k - 1
		minh = max(curminh, minh)
		maxh = min(curmaxh, maxh)
		if minh > maxh:
			ans = 0
			break
		minh = minh - k + 1
		maxh = maxh + k - 1
	curminh = hi[-1]
	curmaxh = hi[-1]
	minh = max(curminh, minh)
	maxh = min(curmaxh, maxh)
	if minh > maxh:
		ans = 0
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	minh = [h[0] + k] + [0 for i in range(n - 1)]
	maxh = [h[0] + k] + [0 for i in range(n - 1)]
	flag = True
	for i in range(1, n - 1):
		if h[i] >= maxh[i - 1] or h[i] + 2 * k - 1 <= minh[i - 1] - k:
			flag = False
			break
		maxh[i] = min(maxh[i - 1] + k - 1, h[i] + 2 * k - 1)
		minh[i] = max(minh[i - 1] - k + 1, h[i] + k)
	if h[n - 1] + k > maxh[n - 2] + k - 1 or h[n - 1] + k < minh[n - 2] - k + 1:
		flag = False
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	h = list(map(int, input().split()))
	a = [0 for i in range(n)]
	poss = True
	for i in range(1, n - 1):
		lb = h[i - 1] + a[i - 1] - h[i] - k + 1
		ub = h[i - 1] + a[i - 1] - h[i] + k - 1
		if ub < 0 or lb >= k:
			poss = False
			break
		elif h[i + 1] > h[i]:
			a[i] = min(ub, k - 1)
		else:
			a[i] = max(lb, 0)
	if poss == True:
		lb = h[n - 2] + a[n - 2] - h[n - 1] - k + 1
		ub = h[n - 2] + a[n - 2] - h[n - 1] + k - 1
		if lb > 0 or ub < 0:
			poss = False
	if poss == True:
		print('YES')
	else:
		print('NO')


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	h = [int(x) for x in input().split()]
	ans = 'YES'
	min_1 = h[0] - (k - 1)
	max_1 = h[0] + (k - 1)
	for i in range(1, n):
		min_2 = h[i]
		if i == n - 1:
			max_2 = min_2
		else:
			max_2 = h[i] + (k - 1)
		if max_1 < min_2 or min_1 > max_2:
			ans = 'NO'
			break
		min_1 = max(min_1, min_2) - (k - 1)
		max_1 = min(max_1, max_2) + (k - 1)
	print(ans)


import sys
input = sys.stdin.readline

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		h = list(map(int, input().split()))
		currmax = h[0] + k
		f = 0
		for i in range(1, n - 1):
			if h[i] >= currmax:
				f = 1
			elif h[i] >= h[i - 1]:
				if h[i + 1] >= h[i]:
					currmax = h[i] + min(k - 1, currmax - h[i] - 1) + k
				else:
					currmax = h[i] + k
			elif h[i] + k + k - 1 <= currmax - k:
				f = 1
			elif h[i + 1] >= h[i]:
				currmax = h[i] + k + k - 1
			else:
				now = h[i] + k
				if now <= currmax - k:
					now += currmax - k - now + 1
				currmax = now
		if h[n - 1] >= currmax:
			f = 1
		elif h[n - 1] + k <= currmax - k:
			f = 1
		if f:
			print('NO')
		else:
			print('YES')
	return
main()


def cmp(a, h):
	return [max(a[0], h[0]), min(a[1], h[1])]
t = input()
for _ in range(int(t)):
	sign = 0
	(n, k) = input().split(' ')
	n = int(n)
	k = int(k)
	height = input().split(' ')
	height = [int(he) for he in height]
	now = [height[0], height[0]]
	for i in range(1, n):
		tem = cmp([height[i], height[i] + k - 1], [now[0] - k + 1, now[1] + k - 1]) if i != n - 1 else cmp([height[i], height[i]], [now[0] - k + 1, now[1] + k - 1])
		if tem[1] < tem[0]:
			sign = 1
			print('NO')
			break
		else:
			now = tem
	if sign == 0:
		print('YES')


from sys import stdin, exit
from bisect import bisect_left as bl, bisect_right as br
input = lambda : stdin.readline()[:-1]
intput = lambda : int(input())
sinput = lambda : input().split()
intsput = lambda : map(int, sinput())

def dprint(*args, **kwargs):
	if debugging:
		print(*args, **kwargs)
debugging = 1
t = intput()
for _ in range(t):
	(n, k) = intsput()
	heights = list(intsput())
	upper = heights[0]
	lower = heights[0]
	fail = False
	for i in range(1, n):
		upper = upper + k - 1
		lower = lower - k + 1
		l_upper = heights[i] + k - 1
		l_lower = heights[i]
		if upper < l_lower or l_upper < lower:
			fail = True
			break
		else:
			upper = min(upper, l_upper)
			lower = max(lower, l_lower)
	if lower <= heights[-1] <= upper:
		pass
	else:
		fail = True
	if fail:
		print('NO')
	else:
		print('YES')


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return list(map(int, sys.stdin.readline().strip().split()))[0]

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
N = 0
a = []

def solve():
	global N
	(N, k) = get_ints()
	a = get_list()
	mx = a[0]
	mn = a[0]
	possible = True
	for i in a[1:]:
		mn = max(mn - (k - 1), i)
		mx = min(mx + (k - 1), i + (k - 1))
		if mx < mn:
			possible = False
			break
	if a[-1:][0] not in range(mn, mx + 1):
		possible = False
	print('YES' if possible else 'NO')
test_cases = get_int()
for _ in range(test_cases):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [*map(int, input().split())]
	b = [(a[0], a[0])]
	f = 0
	for i in range(1, n):
		x = max(b[i - 1][0] - (k - 1), a[i])
		y = min(b[i - 1][1] + (k - 1), a[i] + (k - 1))
		b.append((x, y))
		if x > y:
			f = 1
			break
	if a[n - 1] not in range(x, y + 1):
		f = 1
	if f:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	H = [int(h) for h in input().split()]
	(a, b) = (H[0], H[0] + k)
	ans = 'YES'
	for h in H[1:-1]:
		(x, y) = (h, h + 2 * k - 1)
		a = max(x, a - k + 1)
		b = min(y, b + k - 1)
		if b - a < k:
			ans = 'NO'
	if H[-1] >= b or H[-1] + k <= a:
		ans = 'NO'
	print(ans)


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]

def solve(N, K, H):
	dp = [[0, 0] for _ in range(N)]
	dp[0] = [H[0], H[0]]
	for i in range(1, N):
		a = max(dp[i - 1][0] - K + 1, H[i])
		b = min(dp[i - 1][1] + K - 1, H[i] + K - 1)
		if a > b:
			return False
		dp[i] = [a, b]
	return dp[N - 1][0] == H[N - 1]

def main():
	N0 = int(input())
	for _ in range(N0):
		(N, K) = map(int, input().split())
		H = list(map(int, input().split()))
		if solve(N, K, H):
			print('YES')
		else:
			print('NO')
main()


def readInt():
	return int(input())

def readLine():
	return [int(s) for s in input().split(' ')]

def readString():
	return input()

def ask(arr, k):
	pLow = arr[0]
	pHigh = arr[0]
	for i in range(len(arr)):
		t = arr[i]
		pLow = pLow - (k - 1)
		pHigh = pHigh + (k - 1)
		if i == len(arr) - 1 or i == 0:
			allowLow = t
			allowHigh = t
		else:
			allowLow = t
			allowHigh = t + k - 1
		if allowLow > pHigh or pLow > allowHigh:
			return False
		pLow = max(allowLow, pLow)
		pHigh = min(allowHigh, pHigh)
	return True
t = readInt()
for _ in range(t):
	(n, k) = readLine()
	arrs = readLine()
	result = ask(arrs, k)
	if result:
		print('YES')
	else:
		print('NO')


import sys

def input():
	return sys.stdin.readline().strip()

def solve():
	for t in range(int(input())):
		(n, k) = map(int, input().split())
		k -= 1
		ii = iter(map(int, input().split()))
		m = next(ii)
		M = m
		bad = False
		for h in ii:
			m = max(m - k, h)
			M = min(M + k, h + k)
			if m > M:
				bad = True
				break
		if not bad and m <= h and (M >= h):
			print('YES')
		else:
			print('NO')
solve()


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	h = list(map(int, input().split()))
	min1 = h[0]
	max1 = h[0] + k
	yes = 0
	for i in range(1, n - 1):
		if h[i] + 2 * k - 1 <= min1 or h[i] >= max1:
			yes = 1
			break
		else:
			if h[i] >= min1:
				min1 = h[i]
			else:
				min1 = max(min1 - k + 1, h[i])
			if h[i] + k * 2 - 1 <= max1:
				max1 = h[i] + k * 2 - 1
			else:
				max1 = min(max1 + k - 1, h[i] + k * 2 - 1)
	if min1 >= k + h[-1] or max1 <= h[-1] or yes == 1:
		print('NO')
	else:
		print('YES')


class minmax:

	def __init__(self, min_, max_):
		self.min_ = min_
		self.max_ = max_

def lop():
	(n, k) = map(int, input().split())
	h = input().split()
	this_range = minmax(0, 0)
	prev_range = minmax(0, 0)
	for i in range(n):
		if i == 0 or i == n - 1:
			this_range = minmax(int(h[i]) + k, int(h[i]) + k)
		else:
			this_range = minmax(max(prev_range.min_ - k + 1, int(h[i]) + k), min(prev_range.max_ + k - 1, int(h[i]) + 2 * k - 1))
		if this_range.min_ > this_range.max_:
			return 'NO'
		if i == n - 1:
			u = this_range.min_
			if u < prev_range.min_ - k + 1 or u > prev_range.max_ + k - 1:
				return 'NO'
		prev_range = this_range
	return 'YES'
t = int(input())
out = []
for p in range(t):
	out.append(lop())
for p in out:
	print(p)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	b = [h[0]]
	flag = True
	for i in range(1, n - 1):
		min_must_base = max(0, b[i - 1] - (k - 1))
		max_must_base = b[i - 1] + (k - 1)
		min_can_base = max(h[i], 0)
		max_can_base = h[i] + (k - 1)
		if min_must_base <= max_can_base and max_must_base >= min_can_base:
			if h[i] < h[i + 1]:
				b.append(min(max_can_base, max_must_base))
			else:
				b.append(max(min_can_base, min_must_base))
		else:
			flag = False
			break
	if not flag:
		print('NO')
		continue
	if h[-1] - (k - 1) <= b[n - 2] <= h[-1] + k - 1:
		print('YES')
	else:
		print('NO')


import sys
import math
t = int(input().strip())
for a0 in range(t):
	l = [int(i) for i in input().split()]
	n = l[0]
	k = l[1]
	l1 = [int(i) for i in input().split()]
	flg = 0
	low = l1[0]
	high = l1[0]
	for i in range(1, n):
		low = max(l1[i], low - k + 1)
		high = min(l1[i] + k - 1, high + k - 1)
		if low > high:
			flg = 1
			break
	if l1[n - 1] < low or l1[n - 1] > high:
		flg = 1
	if flg == 1:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
from collections import Counter
import math
t = int(input())
for _ in range(t):
	(n, h) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	(x, y) = (arr[0], arr[0])
	ok = 1
	for i in range(n):
		new_x = max(arr[i], x - h + 1)
		new_y = min(arr[i] + h - 1, y + h - 1)
		if i == 0:
			new_x = x
			new_y = y
		if new_x > new_y:
			ok = 0
		x = new_x
		y = new_y
		if i == n - 1:
			if new_x > arr[i]:
				ok = 0
	if ok == 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	H = list(map(int, input().split()))
	lv = [-1] * n
	(lv[0], lv[-1]) = (H[0] + k, H[-1] + k)
	idx = 1
	while idx < n:
		while idx < n and H[idx] >= H[idx - 1]:
			idx += 1
		peak = idx - 1
		lv[peak] = H[peak] + k
		j = peak - 1
		while j > 0 and lv[j] == -1:
			if lv[j + 1] - (H[j] + 2 * k - 1) >= k:
				return 'NO'
			lv[j] = max(H[j] + k, lv[j + 1] - k + 1)
			j -= 1
		while idx < n - 1 and H[idx] <= H[idx - 1]:
			if lv[idx - 1] - (H[idx] + 2 * k - 1) >= k:
				return 'NO'
			lv[idx] = max(H[idx] + k, lv[idx - 1] - k + 1)
			idx += 1
		if idx < n - 1:
			valley = idx - 1
			lv[valley] = H[valley] + 2 * k - 1
		elif idx == n - 1:
			if H[idx] > H[idx - 1]:
				lv[idx - 1] = H[idx - 1] + 2 * k - 1
			idx += 1
	for i in range(n - 1):
		if abs(lv[i] - lv[i + 1]) >= k:
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	print(solve())


import sys
input = sys.stdin.readline

def intersect(a, b):
	return [max(a[0], b[0]), min(a[1], b[1])]
t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	k = int(l[1])
	l = input().split()
	li = [int(i) for i in l]
	curr = [li[0], li[0]]
	poss = 1
	for i in range(1, n - 1):
		curr[0] -= k - 1
		curr[1] += k - 1
		curr = intersect(curr, [li[i], li[i] + k - 1])
		if curr[1] < curr[0]:
			poss = 0
			break
	curr[0] -= k - 1
	curr[1] += k - 1
	if li[-1] < curr[0] or li[-1] > curr[1]:
		poss = 0
	if poss:
		print('Yes')
	else:
		print('No')


import math
t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	list1 = list(map(int, input().split()))
	max_height = list1[0] + k
	min_height = list1[0] + k
	f = 0
	for i in range(1, n - 1):
		if list1[i] >= max_height or list1[i] + k + k - 1 <= min_height - k:
			f = 1
			break
		max_height = min(list1[i] + k - 1, max_height - 1) + k
		min_height = max(list1[i], min_height - 2 * k + 1) + k
	if f == 0:
		if not (min_height - k < list1[-1] + k and list1[-1] < max_height):
			print('NO')
		else:
			print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	start = [max(a[0] - k + 1, 0), a[0] + k - 1]
	ok = True
	for i in range(1, n):
		if not ok:
			break
		if i != n - 1:
			p1 = a[i] + k - 1
			p2 = a[i]
			if start[0] <= p2 <= start[1] or start[0] <= p1 <= start[1]:
				l = [max(p2, start[0]), min(p1, start[1])]
				start = [max(l[0] - k + 1, 0), l[1] + k - 1]
			else:
				ok = False
		else:
			p1 = a[i]
			p2 = a[i]
			if start[0] <= p2 <= start[1] or start[0] <= p1 <= start[1]:
				l = [max(p2, start[0]), min(p1, start[1])]
				start = [max(l[0] - k + 1, 0), l[1] + k - 1]
			else:
				ok = False
	if ok:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ma = a[0]
	mi = a[0]
	f = True
	for i in range(1, n):
		if a[i] > a[i - 1]:
			if not k - 1 >= abs(ma - a[i]):
				f = False
		elif not 2 * (k - 1) >= abs(mi - a[i]):
			f = False
		ma = min(a[i] + k - 1, ma + k - 1)
		mi = max(a[i], mi - k + 1)
	if f and mi == a[n - 1]:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	m = 0
	str = input()
	(_, k) = [int(item) for item in str.split(' ')]
	str = input()
	ground = [int(item) for item in str.split(' ')]
	(_min, _max) = (ground[0], ground[0])
	for i in range(1, len(ground)):
		_min -= k - 1
		_max += k - 1
		if _min < ground[i]:
			_min = ground[i]
		if _max > ground[i] + k - 1:
			_max = ground[i] + k - 1
		if _min > _max:
			print('NO')
			m = 1
			break
	if m == 0:
		if _min == ground[-1]:
			print('YES')
		else:
			print('NO')


import copy
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def exgcd(a, b):
	if not b:
		return (1, 0)
	(y, x) = exgcd(b, a % b)
	y -= a // b * x
	return (x, y)

def getinv(a, m):
	(x, y) = exgcd(a, m)
	return --1 if x == 1 else x % m

def comb(n, b):
	res = 1
	b = min(b, n - b)
	for i in range(b):
		res = res * (n - i) * getinv(i + 1, mo) % mo
	return res % mo
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	li = [int(i) for i in input().split()]
	cur = li[0]
	ans = True
	upp = cur
	low = cur
	for (p, i) in enumerate(li[1:]):
		if i > upp and i - upp < k or (i < low and low - i < k + k - 1) or low <= i <= upp:
			upp = min(i + (k - 1), upp + (k - 1))
			low = max(i, low - (k - 1))
		else:
			ans = False
			break
	li.reverse()
	cur = li[0]
	upp = cur
	low = cur
	for (p, i) in enumerate(li[1:]):
		if i > upp and i - upp < k or (i < low and low - i < k + k - 1) or low <= i <= upp:
			upp = min(i + (k - 1), upp + (k - 1))
			low = max(i, low - (k - 1))
		else:
			ans = False
			break
	if ans:
		print('YES')
	else:
		print('NO')


cases = int(input())
ans_list = []
for c in range(cases):
	(n, k) = list(map(int, input().split(' ')))
	heights = list(map(int, input().split(' ')))
	max_top = heights[0] + k
	min_top = heights[0] + k
	ans = 'YES'
	for i in range(1, n - 1):
		if heights[i] >= max_top or heights[i] + k + k - 1 <= min_top - k:
			ans = 'NO'
			break
		max_top = min(heights[i] + k - 1, max_top - 1) + k
		min_top = max(heights[i], min_top - 2 * k + 1) + k
	if ans == 'YES':
		if not (min_top - k < heights[-1] + k and heights[-1] < max_top):
			ans = 'NO'
	ans_list.append(ans)
print('\n'.join(ans_list))


import sys
try:
	(sys.stdin, sys.stdout) = (open('in.txt', 'r'), open('out.txt', 'w'))
except:
	pass
ii1 = lambda : int(sys.stdin.readline().strip())
is1 = lambda : sys.stdin.readline().strip()
iia = lambda : list(map(int, sys.stdin.readline().strip().split()))
isa = lambda : sys.stdin.readline().strip().split()
mod = int(1000000000.0 + 7)
from collections import *
from math import *
for _ in range(ii1()):
	(n, k) = iia()
	(l, r) = (0, 0)
	arr = iia()
	ans = 'YES'
	for i in range(n):
		h = arr[i]
		if i == 0:
			l = r = h
		else:
			l = max(l - k + 1, h)
			r = min(r + k - 1, h + k - 1)
		if l > r:
			ans = 'NO'
		if i == n - 1 and l != h:
			ans = 'NO'
	print(ans)


def main():
	from sys import stdin
	input = stdin.buffer.readline
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		(*h,) = map(int, input().split())
		mn = [0] * n
		mx = [0] * n
		mn[0] = mx[0] = h[0]
		for i in range(1, n):
			mn[i] = max(h[i], mn[i - 1] - k + 1)
			mx[i] = min(h[i], mx[i - 1]) + k - 1
			if mn[i] > mx[i]:
				print('NO')
				break
		else:
			if mn[n - 1] <= h[n - 1] <= mx[n - 1]:
				print('YES')
			else:
				print('NO')
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	mn = arr[0]
	mx = arr[0]
	flage = True
	for i in range(1, n):
		mn = max(arr[i], mn - k + 1)
		mx = min(arr[i] + k - 1, mx + k - 1)
		if mn > mx:
			flage = False
	if mn > arr[n - 1] or mx < arr[n - 1]:
		flage = False
	if flage:
		print('YES')
	else:
		print('NO')


def fence():
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	low = h[0]
	high = h[0]
	for (a, b) in enumerate(h):
		low = max(low, b)
		high = min(high, b + k - 1 if a > 0 and a < n - 1 else b)
		if low > high:
			return False
		low -= k - 1
		high += k - 1
	return True
tests = int(input())
for t in range(tests):
	print('YES' if fence() else 'NO')


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = 0
	x = a[0]
	for j in range(1, n):
		if a[j] <= a[j - 1]:
			x = max(a[j], x - k + 1)
		if a[j] > a[j - 1]:
			x = a[j]
		if x - a[j] >= k:
			c = c + 1
			break
	if x != a[n - 1]:
		c = c + 1
	x = a[n - 1]
	for j in range(n - 2, -1, -1):
		if a[j] <= a[j + 1]:
			x = max(a[j], x - k + 1)
		if a[j] > a[j + 1]:
			x = a[j]
		if x - a[j] >= k:
			c = c + 1
			break
	if x != a[0]:
		c = c + 1
	if c > 0:
		print('NO')
	else:
		print('YES')


from sys import stdin
t = int(stdin.readline())

def run():
	L = [int(x) for x in stdin.readline().split(' ')]
	(n, k) = (L[0], L[1])
	A = [int(x) for x in stdin.readline().split(' ')]
	lo = A[0]
	hi = A[0]
	for i in range(1, n):
		lo = max(lo - (k - 1), A[i])
		hi = min(A[i] + (k - 1), hi + (k - 1))
		if lo > hi:
			print('NO')
			return
	if lo <= A[-1] <= hi:
		print('YES')
	else:
		print('NO')
for _ in range(t):
	run()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	h = list(map(int, input().split()))
	flag = False
	lo = h[0] - k + 1
	hi = h[0] + k - 1
	for i in range(1, n):
		if h[i] > hi or h[i] + k <= lo:
			flag = True
			break
		lo = max(lo - k + 1, h[i] - k + 1)
		hi = max(hi + k - 1, h[i] + k - 1)
	lo = h[-1] - k + 1
	hi = h[-1] + k - 1
	for i in range(n - 2, -1, -1):
		if h[i] > hi or h[i] + k <= lo:
			flag = True
			break
		lo = max(lo - k + 1, h[i] - k + 1)
		hi = max(hi + k - 1, h[i] + k - 1)
	if flag:
		print('No')
	else:
		print('Yes')


for y in range(int(input())):
	(n, m) = map(int, input().split())
	lst = list(map(int, input().split()))
	flag = 0
	if n == 1:
		print('YES')
		continue
	minstart = maxstart = 0
	for i in range(n):
		if i == 0:
			minstart = lst[0]
			maxstart = lst[0]
			minend = maxend = lst[0] + m - 1
		else:
			minstart = minstart - (m - 1)
			maxstart = maxstart + (m - 1)
			if lst[i] < minstart - (m - 1) or lst[i] > maxstart:
				flag = 1
				break
			minstart = max(lst[i], minstart)
			maxstart = min(lst[i] + (m - 1), maxstart)
		if i == n - 1:
			if lst[i] < minstart or lst[i] > maxstart:
				flag = 1
				break
	if flag == 0:
		print('YES')
	else:
		print('NO')


def get_overlap(A, B):
	(p, q) = A
	(r, s) = B
	haha = [r - K + 1, s - 1]
	nxt_a = max(p, haha[0])
	nxt_b = min(q, haha[1])
	if nxt_b >= nxt_a:
		return [nxt_a, nxt_b]
	else:
		return False
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	heights = list(map(int, input().split()))
	base_range = []
	base_range.append([heights[0], heights[0]])
	possible = True
	for i in range(1, N - 1):
		possible_base_range = [heights[i], heights[i] + K - 1]
		possible_last_range = [base_range[i - 1][0], base_range[i - 1][1] + K]
		nxt = get_overlap(possible_base_range, possible_last_range)
		if nxt == False:
			possible = False
			break
		else:
			base_range.append(nxt)
	if possible:
		possible_base_range = [heights[N - 1], heights[N - 1]]
		possible_last_range = [base_range[N - 2][0], base_range[N - 2][1] + K]
		nxt = get_overlap(possible_base_range, possible_last_range)
		if nxt == False:
			possible = False
	if possible:
		print('YES')
	else:
		print('NO')


def share(l1, u1, l2, u2):
	if l2 < u1 and l2 >= l1 or (u2 > l1 and u2 <= u1):
		return True
	return False
t = int(input())
for z in range(t):
	(n, k) = [int(i) for i in input().split()]
	h = [int(i) for i in input().split()]
	(u, l) = (h[0] + k, h[0])
	c = 0
	for i in range(1, n - 1):
		if share(l, u, h[i], h[i] + k) or share(l, u, h[i] + k - 1, h[i] + k + k - 1):
			lmin = max(h[i], l + 1 - k)
			umax = min(h[i] + k + k - 1, u - 1 + k)
			(u, l) = (umax, lmin)
		else:
			c = 1
	if c == 0 and share(l, u, h[n - 1], h[n - 1] + k) == False:
		c = 1
	if c == 0:
		print('YES')
	else:
		print('NO')


import sys
import io, os
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	H = list(map(int, input().split()))
	m = H[0]
	M = H[0]
	for i in range(1, n):
		m = max(m + 1 - k, H[i])
		M = min(H[i] + k - 1, M + k - 1)
		if M < m:
			print('NO')
			break
	else:
		if m != H[-1]:
			print('NO')
		else:
			print('YES')


from functools import cmp_to_key
from collections import deque, Counter
from heapq import heappush, heappop
from math import log, ceil
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def ii():
	return int(inp())

def si():
	return str(inp())

def li(lag=0):
	l = list(map(int, inp().split()))
	if lag != 0:
		for i in range(len(l)):
			l[i] += lag
	return l

def mi(lag=0):
	matrix = list()
	for i in range(n):
		matrix.append(li(lag))
	return matrix

def lsi():
	return list(map(str, inp().split()))

def print_list(lista, space=' '):
	print(space.join(map(str, lista)))

def bisect_left(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] < x:
			left = mid + 1
		else:
			right = mid
	return left

def bisect_right(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] > x:
			right = mid
		else:
			left = mid + 1
	return left

def bisect_elements(a, x):
	return bisect_right(a, x) - bisect_left(a, x)
MOD = 10 ** 9 + 7
maxN = 5
FACT = [0] * maxN
INV_FACT = [0] * maxN

def add(x, y):
	return (x + y) % MOD

def multiply(x, y):
	return x * y % MOD

def power(x, y):
	if y == 0:
		return 1
	elif y % 2:
		return multiply(x, power(x, y - 1))
	else:
		a = power(x, y // 2)
		return multiply(a, a)

def inverse(x):
	return power(x, MOD - 2)

def divide(x, y):
	return multiply(x, inverse(y))

def allFactorials():
	FACT[0] = 1
	for i in range(1, maxN):
		FACT[i] = multiply(i, FACT[i - 1])

def inverseFactorials():
	n = len(INV_FACT)
	INV_FACT[n - 1] = inverse(FACT[n - 1])
	for i in range(n - 2, -1, -1):
		INV_FACT[i] = multiply(INV_FACT[i + 1], i + 1)

def coeffBinom(n, k):
	if n < k:
		return 0
	return multiply(FACT[n], multiply(INV_FACT[k], INV_FACT[n - k]))

def create_graph(n, m, undirected=1, unweighted=1):
	graph = [[] for i in range(n)]
	if unweighted:
		for i in range(m):
			[x, y] = li(lag=-1)
			graph[x].append(y)
			if undirected:
				graph[y].append(x)
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			graph[x].append([y, w])
			if undirected:
				graph[y].append([x, w])
	return graph

def create_tree(n, unweighted=1):
	children = [[] for i in range(n)]
	if unweighted:
		for i in range(n - 1):
			[x, y] = li(lag=-1)
			children[x].append(y)
			children[y].append(x)
	else:
		for i in range(n - 1):
			[x, y, w] = li(lag=-1)
			w += 1
			children[x].append([y, w])
			children[y].append([x, w])
	return children

def dist(tree, n, A, B=-1):
	s = [[A, 0]]
	(massimo, massimo_nodo) = (0, 0)
	distanza = -1
	v = [-1] * n
	while s:
		(el, dis) = s.pop()
		if dis > massimo:
			massimo = dis
			massimo_nodo = el
		if el == B:
			distanza = dis
		for child in tree[el]:
			if v[child] == -1:
				v[child] = 1
				s.append([child, dis + 1])
	return (massimo, massimo_nodo, distanza)

def diameter(tree):
	(_, foglia, _) = dist(tree, n, 0)
	(diam, _, _) = dist(tree, n, foglia)
	return diam

def dfs(graph, n, A):
	v = [-1] * n
	s = [[A, 0]]
	v[A] = 0
	while s:
		(el, dis) = s.pop()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def bfs(graph, n, A):
	v = [-1] * n
	s = deque()
	s.append([A, 0])
	v[A] = 0
	while s:
		(el, dis) = s.popleft()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def parents_children_root_unrooted_tree(tree, n, root=0):
	q = deque()
	visited = [0] * n
	parent = [-1] * n
	children = [[] for i in range(n)]
	q.append(root)
	while q:
		all_done = 1
		visited[q[0]] = 1
		for child in tree[q[0]]:
			if not visited[child]:
				all_done = 0
				q.appendleft(child)
		if all_done:
			for child in tree[q[0]]:
				if parent[child] == -1:
					parent[q[0]] = child
					children[child].append(q[0])
			q.popleft()
	return (parent, children)

def all_longest_path_passing_from_node(parent, children, n):
	q = deque()
	visited = [len(children[i]) for i in range(n)]
	downwards = [[0, 0] for i in range(n)]
	upward = [1] * n
	longest_path = [1] * n
	for i in range(n):
		if not visited[i]:
			q.append(i)
			downwards[i] = [1, 0]
	while q:
		node = q.popleft()
		if parent[node] != -1:
			visited[parent[node]] -= 1
			if not visited[parent[node]]:
				q.append(parent[node])
		else:
			root = node
		for child in children[node]:
			downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse=True)[0:2]
	s = [node]
	while s:
		node = s.pop()
		if parent[node] != -1:
			if downwards[parent[node]][0] == downwards[node][0] + 1:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
			else:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
		longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
		for child in children[node]:
			s.append(child)
	return longest_path

def interseca(l1, r1, l2, r2):
	if r1 < l2 or r2 < l1:
		return False
	return True
for test in range(ii()):
	[n, k] = li()
	h = li()
	cur = [h[0], h[0]]
	flag = True
	for i in range(1, n - 1):
		if h[i + 1] > h[i]:
			l = min(h[i] + k - 1, cur[1] + k - 1)
			if l < h[i] or l > h[i] + k - 1:
				flag = False
			flag = flag and interseca(l, l + k - 1, cur[0], cur[1] + k - 1)
			cur = [l, l]
		elif h[i + 1] < h[i]:
			l = max(h[i], cur[0] - k + 1)
			if l < h[i] or l > h[i] + k - 1:
				flag = False
			flag = flag and interseca(l, l + k - 1, cur[0], cur[1] + k - 1)
			cur = [l, l]
		elif h[i - 1] == h[i]:
			cur[0] = max(h[i], cur[0] - k + 1)
			cur[1] = min(h[i] + k - 1, cur[1] + k - 1)
		else:
			mi = max(cur[0] - k + 1, h[i])
			ma = min(h[i] + k - 1, cur[1] + k - 1)
			if mi > ma or interseca(mi, ma + k - 1, cur[0], cur[1] + k - 1) == False:
				flag = False
			cur = [mi, ma]
	if h[n - 1] < cur[0] - k + 1 or h[n - 1] > cur[1] + k - 1:
		flag = False
	if flag == False:
		print('NO')
	else:
		print('YES')


t = int(input())
while t > 0:
	t -= 1
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	v = [int(x) for x in input().split(' ')]
	mn = v[0]
	mx = v[0]
	ok = True
	for i in range(1, n):
		mn = max(v[i], mn - k + 1)
		mx = min(v[i] + k - 1, mx + k - 1)
		if mn > mx:
			ok = False
			break
	if mn > v[n - 1] or mx < v[n - 1]:
		ok = False
	if ok == True:
		print('YES')
	else:
		print('NO')


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
t = int(input())
for tt in range(t):
	(n, k) = nii()
	h = lnii()
	min_h = h[0]
	max_h = h[0] + k
	for i in range(1, n):
		if i < n - 1:
			if h[i] > max_h - 1:
				print('NO')
				break
			min_h = max(h[i], min_h - (k - 1))
			max_h = min(max_h + (k - 1), h[i] + k + (k - 1))
			if min_h + k > max_h:
				print('NO')
				break
		elif min_h >= h[i] + k or max_h <= h[i]:
			print('NO')
		else:
			print('YES')