CQXYM wants to create a connected undirected graph with $n$ nodes and $m$ edges, and the diameter of the graph must be strictly less than $k-1$. Also, CQXYM doesn't want a graph that contains self-loops or multiple edges (i.e. each edge connects two different vertices and between each pair of vertices there is at most one edge).

The diameter of a graph is the maximum distance between any two nodes.

The distance between two nodes is the minimum number of the edges on the path which endpoints are the two nodes.

CQXYM wonders whether it is possible to create such a graph.


-----Input-----

The input consists of multiple test cases.

The first line contains an integer $t (1 \leq t \leq 10^5)$ — the number of test cases. The description of the test cases follows.

Only one line of each test case contains three integers $n(1 \leq n \leq 10^9)$, $m$, $k$ $(0 \leq m,k \leq 10^9)$.


-----Output-----

For each test case, print YES if it is possible to create the graph, or print NO if it is impossible. You can print each letter in any case (upper or lower).


-----Examples-----

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


-----Note-----

In the first test case, the graph's diameter equal to 0.

In the second test case, the graph's diameter can only be 2.

In the third test case, the graph's diameter can only be 1.

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms

Graph algorithms

Mathematics

Constructive algorithms


Solutions:
t = int(input())
while t:
	t -= 1
	(n, m, k) = map(int, input().split())
	if m < n - 1 or m > n * (n - 1) // 2:
		print('NO')
		continue
	if k > 3:
		print('YES')
	elif k == 3:
		if m == n * (n - 1) // 2:
			print('YES')
		else:
			print('NO')
	elif k == 2:
		if n == 1 and m == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	p = (n - 1) * (n - 2) // 2
	if k <= 1 or m < n - 1:
		print('NO')
	elif k == 2:
		if m == 0:
			print('YES')
		else:
			print('NO')
	elif m >= p + n - 1:
		if m > p + n - 1:
			print('NO')
		else:
			print('YES')
	elif k >= 4:
		print('YES')
	else:
		print('NO')


from sys import stdin

def read_input():
	(n, m, k) = map(int, stdin.readline().split())
	return (n, m, k)

def solve(n, m, k):
	if k == 0 or k == 1:
		return 'NO'
	elif k == 2:
		if n == 1 and m == 0:
			return 'YES'
		else:
			return 'NO'
	elif k == 3:
		if m == n * (n - 1) // 2:
			return 'YES'
		else:
			return 'NO'
	elif m >= n - 1 and m <= n * (n - 1) // 2:
		return 'YES'
	else:
		return 'NO'

def main():
	t = int(stdin.readline())
	for _ in range(t):
		(n, m, k) = read_input()
		answer = solve(n, m, k)
		print(answer)
main()


from collections import deque
import heapq
from math import sqrt
import operator
from operator import itemgetter
import sys
import time
import copy
inf_var = 0
if inf_var == 1:
	inf = open('input.txt', 'r')
else:
	inf = sys.stdin
input = inf.readline

def read_one_int():
	return int(input().rstrip('\n'))

def read_one_float():
	return float(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split()]
	return res

def read_list_of_ints_zero():
	return [int(val) - 1 for val in input().rstrip('\n').split()]

def read_str():
	return input().rstrip()

def main():
	tests = read_one_int()
	for _ in range(tests):
		(n, m, k) = read_list_of_ints()
		max_edges = (n - 1) * n // 2
		res = 'NO'
		if m < n - 1 or max_edges < m:
			res = 'NO'
		elif max_edges == m and k - 1 > 1:
			res = 'YES'
		elif m >= n - 1 and m < max_edges and (k - 1 > 2):
			res = 'YES'
		elif m == 0 and n == 1 and (k - 1 > 0):
			res = 'YES'
		else:
			res = 'NO'
		print(res)
main()


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n == 1 and k == 2 and (m == 0):
		print('YES')
	elif m < n - 1 or k < 3 or m > n * (n - 1) / 2:
		print('NO')
	elif k == 3 and m < n * (n - 1) / 2:
		print('NO')
	else:
		print('YES')


import sys, math
input = sys.stdin.readline

def yes():
	print('YES')

def no():
	print('NO')
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	c = math.comb(n, 2)
	if m > c:
		no()
		continue
	elif m < n - 1:
		no()
		continue
	if k == 0:
		no()
	elif k == 1:
		no()
	elif k == 2:
		if n == 1:
			yes()
		else:
			no()
	elif k == 3:
		if m == c:
			yes()
		else:
			no()
	else:
		yes()


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if n * (n - 1) // 2 < m or k - 2 < 0 or m < n - 1:
		print('NO')
		continue
	if k == 2:
		if m == 0:
			print('YES')
		else:
			print('NO')
	elif k == 3:
		if n * (n - 1) // 2 == m:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


import math
for q in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	k -= 1
	temp2 = n * (n - 1) // 2
	temp = temp2 - m
	temp = temp + 1 if m != n - 1 else n - 1
	if n == 1 and k > 0 and (m == 0):
		print('YES')
	elif m > temp2:
		print('NO')
	elif m == temp2 and k > 1:
		print('YES')
	elif m == n - 1 and k > 2:
		print('YES')
	elif m < n - 1:
		print('NO')
	elif 2 < k:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m == n * (n - 1) // 2 and n != 1:
		if k >= 3:
			print('YES')
		else:
			print('NO')
	elif m > n * (n - 1) // 2:
		print('NO')
	elif n - m >= 2:
		print('NO')
	elif n == 1:
		if k >= 2:
			print('YES')
		else:
			print('NO')
	elif k >= 4:
		print('YES')
	else:
		print('NO')


t = int(input())

def mm(l, n):
	if l == 0 or l == 1:
		return l
	if l == n * (n - 1) / 2 and l > 1:
		return 1
	else:
		return 2
x = 0
while x < t:
	li = list(map(int, input().split()))
	n = li[0]
	l = li[1]
	k = li[2]
	if l > (n - 1) * n / 2 or l < n - 1:
		print('NO')
	elif mm(l, n) < k - 1:
		print('YES')
	else:
		print('NO')
	x = x + 1


import sys
readline = sys.stdin.readline
T = int(readline())
for t in range(T):
	(N, M, K) = map(int, readline().split())
	tree = N - 1
	if M < tree:
		print('NO')
		continue
	allpat = N * (N - 1) // 2
	if allpat < M:
		print('NO')
		continue
	min_val = 2
	if allpat == M:
		min_val = 1
	if N == 1 and M == 0:
		min_val = 0
	if min_val < K - 1:
		print('YES')
	else:
		print('NO')


l0 = []
l1 = []
for x in range(int(input())):
	(a, b, c) = map(int, input().split())
	i = 1
	sum0 = a * (a - 1) / 2
	if a == 1 and b == 0:
		d = 0
	elif b == sum0:
		d = 1
	elif a - 1 <= b < sum0:
		d = 2
	else:
		d = c
	l0.append(d)
	l1.append(c - 1)
for x in range(len(l0)):
	print('YES' if l0[x] < l1[x] else 'NO')


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
mod = 10 ** 9 + 7
INF = float('inf')

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

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

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def inps():
	return sys.stdin.readline()

def inpsl(x):
	tmp = sys.stdin.readline()
	return list(tmp[:x])

def err(x):
	print(x)
	exit()
for _ in range(inp()):
	(n, m, k) = inpl()
	if m < n - 1 or m > n * (n - 1) // 2:
		print('NO')
		continue
	if (n, k) == (1, 2):
		print('YES')
		continue
	dist = 1 if m == n * (n - 1) // 2 else 2
	if dist < k - 1:
		print('YES')
	else:
		print('NO')


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main(t):
	(n, m, k) = map(int, input().split())
	if k <= 2:
		if n == 1 and m == 0 and (k == 2):
			print('YES')
		else:
			print('NO')
	elif k == 3:
		if m < n * (n - 1) // 2 or m > n * (n - 1) // 2:
			print('NO')
		else:
			print('YES')
	elif m < n - 1 or m > n * (n - 1) // 2:
		print('NO')
	else:
		print('YES')
T = int(input())
t = 1
while t <= T:
	main(t)
	t += 1


for s in [*open(0)][1:]:
	(n, m, k) = map(int, s.split())
	c = n * n - n >> 1
	print('NYOE S'[n - 2 < m <= c and (n < 2 < k + 1 or (k > 2 and (n < 3 or m == c)) or k - 2 > 1 < m)::2])


numberTestCases = int(input())
cases = []
for i in range(numberTestCases):
	arr = input().split(' ')
	cases.append(list(map(int, arr)))
for case in cases:
	n = case[0]
	m = case[1]
	k = case[2]
	if k <= 1:
		print('NO')
	elif k == 2:
		if n == 1 and m == 0:
			print('YES')
		else:
			print('NO')
	elif k == 3:
		if n * (n - 1) / 2 == m:
			print('YES')
		else:
			print('NO')
	elif m >= n - 1 and n * (n - 1) / 2 >= m:
		print('YES')
	else:
		print('NO')


def c(n):
	return n * (n - 1) // 2

def solve(n, m, k):
	if n == 1:
		if m == 0 and k >= 2:
			return 'YES'
		else:
			return 'NO'
	if n == 2:
		if m == 1 and k >= 3:
			return 'YES'
		else:
			return 'NO'
	if m < n - 1:
		return 'NO'
	if m < c(n):
		if k > 3:
			return 'YES'
	elif m == c(n):
		if k >= 3:
			return 'YES'
	return 'NO'
for case in range(int(input())):
	(n, m, k) = map(int, input().split())
	ans = solve(n, m, k)
	print(ans)


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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	(n, m, k) = map(int, input().split())
	if not (m >= n - 1 and m <= n * (n - 1) // 2):
		print('NO')
		continue
	if k == 0 or k == 1:
		print('NO')
	elif k == 2:
		print('YES' if n == 1 else 'NO')
	elif k == 3:
		print('YES' if n == 1 or m == n * (n - 1) // 2 else 'NO')
	else:
		print('YES')


import os, 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))
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)
for _ in range(ii1()):
	(n, m, k) = iia()
	k -= 1
	if n == 1:
		if m == 0:
			ans = 1 if 0 < k else 0
		else:
			ans = 0
	elif n == 2:
		if m == 1:
			ans = 1 if 1 < k else 0
		else:
			ans = 0
	elif n == m + 1:
		ans = 1 if 2 < k else 0
	elif n <= m <= n * (n - 1) // 2:
		if m == n * (n - 1) // 2:
			ans = 1 if 1 < k else 0
		else:
			ans = 1 if 2 < k else 0
	else:
		ans = 0
	print('YES' if ans else 'NO')


t = int(input())
a = []
for x in range(1, 1 + t):
	(n, m, k) = [int(y) for y in input().split()]
	if n == 1 and m == 0 and (k > 1):
		a.append('YES')
	elif m < n - 1 or m > n * (n - 1) / 2:
		a.append('NO')
	elif m != n * (n - 1) / 2:
		if k > 3:
			a.append('YES')
		else:
			a.append('NO')
	elif k > 2:
		a.append('YES')
	else:
		a.append('NO')
for y in a:
	print(y)


for fghj in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	if m < n - 1 or m > n * (n - 1) / 2:
		print('NO')
		continue
	if n == 1 and m == 0 and (k > 1):
		print('YES')
		continue
	if m == n * (n - 1) / 2:
		dia = 1
	else:
		dia = 2
	req = k - 1
	if dia < req:
		print('YES')
	else:
		print('NO')


import decimal
import heapq
import math
import os
import sys
from io import BytesIO, IOBase
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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def ints_get():
	return map(int, input().strip().split())

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

def chars_get():
	return list(map(str, sys.stdin.readline().strip().split()))

def output(to_be_printed, end='\n'):
	sys.stdout.write(str(to_be_printed) + end)

def ipn():
	return int(input())

def main():
	for _ in range(ipn()):
		(n, m, k) = ints_get()
		val = n * (n - 1) // 2
		if k <= 1:
			output('NO')
		elif n == 1 and m == 0:
			output('YES')
		elif n == 1:
			output('NO')
		elif val == m and k == 3:
			output('YES')
		elif val < m or m < n - 1:
			output('NO')
		elif k > 3:
			output('YES')
		else:
			output('NO')
	return
main()


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	Kn = n * (n - 1) // 2
	if Kn < m or n - 1 > m:
		print('NO')
	elif n == 1:
		if k <= 1:
			print('NO')
		else:
			print('YES')
	else:
		d = 2
		if m == Kn:
			d = 1
		if d < k - 1:
			print('YES')
		else:
			print('NO')


t = int(input())
import sys
while t:
	(n, m, k) = map(int, sys.stdin.readline().split())
	if m > n * (n - 1) // 2 or m < n - 1:
		print('NO')
	elif k == 1 or k == 0:
		print('NO')
	elif k == 2:
		print('YES' if n == 1 else 'No')
	elif k == 3:
		print('YES' if m == n * (n - 1) // 2 else 'NO')
	else:
		print('YES')
	t -= 1


import math
import heapq
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
H = 1000000000 + 7
for _ in range(I()):
	(n, m, k) = M()
	k -= 2
	if n == 1 and m == 0 and (k == 0):
		print('YES')
		continue
	if m > n * (n - 1) // 2 or m < n - 1:
		print('NO')
		continue
	if m == n * (n - 1) // 2 and k >= 1:
		print('YES')
		continue
	if n - 1 <= m <= n * (n - 1) // 2 and k >= 2:
		print('YES')
		continue
	print('NO')


import sys
input = sys.stdin.readline
rep = int(input())
for i in range(rep):
	(n, m, k) = map(int, input().split())
	if k <= 1:
		print('NO')
		continue
	if n == 1:
		if m == 0:
			print('YES')
		else:
			print('NO')
		continue
	(a, b) = (n - 1, n * (n - 1) // 2)
	if a <= m <= b and k >= 4:
		print('YES')
	elif m == b and k >= 3:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
import math
import bisect
from collections import defaultdict, Counter
input = stdin.readline

def inp():
	return map(int, input().split())
for _ in range(int(input())):
	(n, m, k) = inp()
	if k <= 1:
		print('NO')
	elif k == 2:
		if n == 1 and m == 0:
			print('YES')
		else:
			print('NO')
	elif k == 3:
		if m == n * (n - 1) // 2:
			print('YES')
		else:
			print('NO')
	elif m >= n - 1 and m <= n * (n - 1) // 2:
		print('YES')
	else:
		print('NO')


import time
start = time.time()
(test, i, result) = (int(input()), 0, [])
while i < test:
	(n, m, k) = map(int, input().split())
	edges = n * (n - 1) / 2
	if edges < m or m < n - 1:
		result.append('NO')
	elif k >= 4:
		result.append('YES')
	elif k == 3 and (n <= 2 or edges == m):
		result.append('YES')
	elif k == 2 and n == 1:
		result.append('YES')
	else:
		result.append('NO')
	i += 1
print('\n'.join(result))


import sys
input = sys.stdin.buffer.readline

def process(n, m, k):
	if m < n - 1:
		return 'NO'
	if m > n * (n - 1) // 2:
		return 'NO'
	if k <= 1:
		return 'NO'
	if n == 1:
		return 'YES'
	if k == 2:
		return 'NO'
	if k == 3 and m == n * (n - 1) // 2:
		return 'YES'
	if k == 3:
		return 'NO'
	return 'YES'
t = int(input())
for i in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	sys.stdout.write(process(n, m, k) + '\n')


for i in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	maxVal = n * (n - 1) // 2
	if m > maxVal:
		print('NO')
	elif k <= 1:
		print('NO')
	elif k == 2:
		if n == 1:
			print('YES')
		else:
			print('NO')
	elif k == 3:
		if m >= maxVal:
			print('YES')
		else:
			print('NO')
	elif m >= n - 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	(n, m, k) = invr()
	flag = True
	if m < n - 1:
		flag = False
	elif 2 * m > n * (n - 1):
		flag = False
	elif k <= 1:
		flag = False
	elif k == 2:
		if n != 1:
			flag = False
	elif k == 3:
		if 2 * m < n * (n - 1):
			flag = False
	print('YES' if flag else 'NO')


import sys
from math import *
from functools import *
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	d = 10 ** 9 + 1
	if m >= n - 1 and m <= n * (n - 1) // 2:
		if m == 0:
			d = 0
		elif m == 1 or m == n * (n - 1) // 2:
			d = 1
		else:
			d = 2
	if d < k - 1:
		print('YES')
	else:
		print('NO')


import math
import sys
import operator as op
from functools import reduce
from collections import OrderedDict

class Input:

	@staticmethod
	def string():
		return str(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)))

class Output:

	@staticmethod
	def print(res):
		print(res)

	@staticmethod
	def string(res):
		print(str(res))

	@staticmethod
	def list(res):
		print(' '.join((str(x) for x in res)))

class Algorithms:

	@staticmethod
	def isPrime(n):
		return all((n % i != 0 for i in range(2, int(math.sqrt(n) + 1))))

	@staticmethod
	def getPrimeNumbers(n):
		a = [1]
		for num in range(2, n):
			if all((num % i != 0 for i in range(2, int(math.sqrt(num) + 1)))):
				a.append(num)
		return a

	@staticmethod
	def factorization(n):
		res = {}
		for i in range(2, n * n):
			cnt = 0
			while n % i == 0:
				cnt += 1
				n = n / i
			if cnt > 0:
				res[i] = cnt
		if n > 1:
			res[n] = 1
		return res

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		else:
			a = a % b
			return Algorithms.gcd(b, a)

	@staticmethod
	def lcm(a, b):
		return abs(a * b) // Algorithms.gcd(a, b)

	@staticmethod
	def fibonacci(n):
		a = [0, 1]
		for i in range(2, n + 1):
			a.append(a[i - 1] - a[i - 2])
		return a[n]

	@staticmethod
	def z_func(s):
		n = len(s)
		z = [0] * n
		l = r = 0
		for i in range(1, n):
			if r >= i:
				z[i] = min(z[i - l], r - i + 1)
			while z[i] + i < n and s[z[i]] == s[z[i] + i]:
				z[i] += 1
			if i + z[i] - 1 > r:
				l = i
				r = i + z[i] - 1
		return z

	@staticmethod
	def faktorial(n):
		factorial = 1
		for i in range(3, n + 1):
			factorial *= i
			factorial = factorial % (math.pow(10, 9) + 7)
		return factorial

def solve():
	(n, m, k) = Input.list_int()
	if n - m < 2 and n * (n - 1) / 2 == m and (k - 1 > 1):
		print('YES')
	elif n - m < 2 and n * (n - 1) / 2 > m and (k - 1 > 2):
		print('YES')
	elif n - m < 2 and m == 0 and (k - 1 > 0):
		print('YES')
	else:
		print('NO')
query_count = Input.int()
while query_count:
	query_count -= 1
	solve()


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

def rint():
	return int(input())

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

def rlstr():
	return list(input().strip().split())

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

def main():
	(n, m, k) = rlint()
	k -= 1
	if n * (n - 1) // 2 < m or m < n - 1:
		print('NO')
		return
	if n == 1:
		if k > 0:
			print('YES')
		else:
			print('NO')
		return
	if m == n * (n - 1) // 2:
		if k > 1:
			print('YES')
		else:
			print('NO')
		return
	if k > 2:
		print('YES')
	else:
		print('NO')
for _ in range(rint()):
	main()


import math
import os
import sys
from io import BytesIO, IOBase
M = 1000000007
import random
import heapq
import bisect
import time
from functools import *
from collections import *
from itertools import *
BUFSIZE = 8192
import array
sys.setrecursionlimit(2 * 10 ** 5)

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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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 fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def build(arr, a, b, st, node):
	if a == b:
		st[node] = arr[a]
		return st[node]
	mid = (a + b) // 2
	st[node] = min(build(arr, a, mid, st, 2 * node + 1), build(arr, mid + 1, b, st, 2 * node + 2))
	return st[node]

def getmin(arr, a, b, l, r, st, node):
	if l > b or r < a:
		return float('inf')
	if l <= a and r >= b:
		return st[node]
	mid = (a + b) // 2
	return min(getmin(arr, a, mid, l, r, st, 2 * node + 1), getmin(arr, mid + 1, b, l, r, st, 2 * node + 2))

def main():
	t = 1
	t = int(input())
	for tc in range(1, t + 1):
		(n, m, k) = sep()
		if n * (n - 1) // 2 < m or n - 1 > m:
			print('NO')
		elif k <= 1 and n == 1:
			print('NO')
		elif k <= 2 and n == 2:
			print('NO')
		elif n >= 3 and (m < n * (n - 1) // 2 and k <= 3 or n - 1 > m or (m >= n * (n - 1) // 2 and k <= 2)):
			print('NO')
		else:
			print('YES')
main()


Q = int(input())
import sys
input = sys.stdin.readline
for _ in range(Q):
	(n, m, k) = map(int, input().split())
	k -= 2
	ans = False
	m_max = n * (n - 1) // 2
	if n == 1 and m == 0 and (k == 0):
		ans = True
	elif m == m_max and k >= 1:
		ans = True
	elif n - 1 <= m and m < m_max and (k >= 2):
		ans = True
	print('YES' if ans else 'NO')


ans = []
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if k >= 2 and n == 1 and (m == 0) or (k == 3 and m == n * (n - 1) // 2) or (k > 3 and n - 1 <= m and (m <= n * (n - 1) // 2)):
		ans.append('YES')
	else:
		ans.append('NO')
for i in ans:
	print(i)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m < n - 1 or m > n * (n - 1) // 2:
		print('NO')
		continue
	if n == 1:
		if 0 < k - 1:
			print('YES')
		else:
			print('NO')
	else:
		if m == n * (n - 1) // 2:
			r = 1
		else:
			r = 2
		if r < k - 1:
			print('YES')
		else:
			print('NO')


from math import ceil, gcd, factorial
from bisect import bisect_left as bl
from bisect import bisect_right as br
from array import array
from collections import Counter as ctr
from collections import deque as dq

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

def arr(a):
	return array('i', a)

def solve():
	for _ in range(int(input())):
		(n, m, k) = li()
		t = n * (n - 1) // 2
		if m > t or m < n - 1 or k < 2 or ((n != 1 or m != 0) and k == 2) or (k == 3 and m != t):
			print('NO')
		else:
			print('YES')
solve()


t = int(input())
for i in range(0, t):
	(n, m, k) = map(int, input().split(' '))
	maxr = n * (n - 1) / 2
	if m >= n - 1 and m < maxr and (2 < k - 1):
		print('YES')
	elif m == maxr and 1 < k - 1:
		print('YES')
	elif n == 1 and m == 0 and (k >= 2):
		print('YES')
	else:
		print('NO')


from sys import stdin

def test():
	(n, m, k) = (int(_) for _ in stdin.readline().split())
	k = k - 2
	if k == 0:
		return n == 1 and m == 0
	if k < 1:
		return False
	if k == 1:
		if m == n * (n - 1) // 2:
			return True
		else:
			return False
	if k >= 2:
		return m <= n * (n - 1) // 2 and m >= n - 1
tn = int(stdin.readline())
for _ in range(0, tn):
	if test():
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n == 1 and m == 0:
		d = 0
	elif n - 1 > m:
		print('NO')
		continue
	else:
		me = n * (n - 1) / 2
		if me == m:
			d = 1
		elif m > me:
			print('NO')
			continue
		else:
			d = 2
	if d < k - 1:
		print('YES')
	else:
		print('NO')


import sys
t = int(sys.stdin.readline())
for test in range(t):
	(n, m, k) = map(int, sys.stdin.readline().split())
	least = n - 1
	most = n * (n - 1) // 2
	ans = 'NO'
	if least <= m <= most:
		if k > 3:
			ans = 'YES'
		else:
			if k == 3 and m == most:
				ans = 'YES'
			if k == 2 and n == 1:
				ans = 'YES'
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter
from pprint import pprint
from itertools import permutations
from bisect import bisect_right
sz = 2010

def main():
	(n, m, k) = map(int, input().split())
	k -= 2
	if k < 0 or m > n * (n - 1) // 2:
		return False
	elif k == 0:
		return n == 1
	elif k == 1:
		return m == n * (n - 1) // 2
	else:
		return m >= n - 1
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')
for _ in range(int(input())):
	if main():
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
for nt in range(int(input())):
	(n, m, k) = map(int, input().split())
	if k <= 1:
		print('NO')
		continue
	if m < n - 1:
		print('NO')
		continue
	if m > n * (n - 1) // 2:
		print('NO')
		continue
	if n == 1:
		print('YES')
		continue
	if m == n * (n - 1) // 2:
		if k > 2:
			print('YES')
		else:
			print('NO')
		continue
	if k > 3:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	bad = 0
	if m < n - 1:
		bad = 1
	elif m > n * (n - 1) / 2:
		bad = 1
	else:
		if n == 1:
			d = 0
		elif n == 2:
			d = 1
		elif m == n * (n - 1) / 2:
			d = 1
		else:
			d = 2
		if k - 1 <= d:
			bad = 1
	if bad:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	k -= 2
	if n == 1 and m == 0 and (k >= 0):
		print('YES')
	elif k < 1 or m < n - 1 or m > n * (n - 1) // 2:
		print('NO')
	elif k == 1:
		if m == n * (n - 1) // 2:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


import sys

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

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

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

def get_int():
	return int(sys.stdin.readline().strip())

def get_list_strings():
	return list(map(str, sys.stdin.readline().strip().split()))

def solve(n, m, k):
	diameter = k - 2
	up = n * (n - 1) // 2
	low = n - 1
	if m > up:
		print('NO')
		return
	if m < low:
		print('NO')
		return
	if k < 2:
		print('NO')
		return
	if k == 2:
		if n == 1:
			print('YES')
		else:
			print('NO')
		return
	if k > 3:
		print('YES')
		return
	if m == up:
		print('YES')
	else:
		print('NO')
T = get_int()
while T:
	(n, m, k) = get_ints()
	solve(n, m, k)
	T -= 1


import sys
input = sys.stdin.readline

class Node:

	def __init__(self, value) -> None:
		self.value = value
		self.next = None

	@staticmethod
	def print_list(head):
		curr = head
		while curr != None:
			print(curr.value, end=' ')
			curr = curr.next
		print('')
import math

def modInverse(b, m):
	g = math.gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def modDivide(a, b, m):
	a = a % m
	inv = modInverse(b, m)
	return inv * a % m
mod = 10 ** 9 + 7

def fact(n):
	x = 1
	for k in range(1, 2 * n + 1):
		x = x * k % mod
	return x

def main():
	(n, m, k) = map(int, input().split())
	k -= 1
	if m >= n - 1 and m <= n * (n - 1) // 2:
		if m == 0:
			if k >= 1:
				ans = 'YES'
			else:
				ans = 'NO'
		elif m == n * (n - 1) // 2:
			if k >= 2:
				ans = 'YES'
			else:
				ans = 'NO'
		elif k >= 3:
			ans = 'YES'
		else:
			ans = 'NO'
	else:
		ans = 'NO'
	print(ans)
for _t in range(int(input())):
	main()


from sys import stdin, stdout
import math
import bisect
from collections import defaultdict, Counter
input = stdin.readline
test = int(input())

def edges(val):
	return val * (val - 1) // 2
for _ in range(test):
	(n, m, k) = map(int, input().split())
	if edges(n) < m or m < n - 1:
		print('NO')
	elif k >= 4:
		print('YES')
	elif k == 3 and (n <= 2 or edges(n) == m):
		print('YES')
	elif k == 2 and n == 1:
		print('YES')
	else:
		print('NO')


def solve():
	s = input()
	s = s.split()
	n = int(s[0])
	m = int(s[1])
	k = int(s[2])
	k -= 1
	if m >= n - 1 and m <= n * (n - 1) / 2:
		if n == 1 and k > 0:
			print('YES')
			return 0
		if n == 2 and k > 1:
			print('YES')
			return 0
		if n > 2 and k > 2:
			print('YES')
			return 0
		if n > 2 and k > 1 and (m == n * (n - 1) / 2):
			print('YES')
			return 0
	print('NO')
	return 0

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


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if not n * (n - 1) // 2 >= m >= n - 1:
		print('NO')
		continue
	if k < 2:
		print('NO')
		continue
	if k == 2:
		if n == 1:
			print('YES')
		else:
			print('NO')
		continue
	if k == 3:
		if m == n * (n - 1) // 2:
			print('YES')
		else:
			print('NO')
		continue
	print('YES')


for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	answer = 'NO'
	if m == 0 and m == n - 1 and (k >= 2):
		answer = 'YES'
	elif m >= n - 1 and m <= n * (n - 1) // 2:
		if m == n * (n - 1) // 2 and k >= 3:
			answer = 'YES'
		elif k >= 4:
			answer = 'YES'
	print(answer)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	nd = n * (n - 1) // 2
	if m < n - 1 or m > nd:
		print('NO')
	elif n == 1:
		print(['NO', 'YES'][k > 1])
	elif m < nd:
		print(['NO', 'YES'][k > 3])
	else:
		print(['NO', 'YES'][k > 2])


from sys import stdin, stdout
input = stdin.readline

def inp():
	return map(int, input().split())
for i in range(int(input())):
	(n, m, k) = inp()
	if k <= 1:
		print('NO')
	elif k == 2:
		if n == 1 and m == 0:
			print('YES')
		else:
			print('NO')
	elif k == 3:
		if m == n * (n - 1) / 2:
			print('YES')
		else:
			print('NO')
	elif m >= n - 1 and m <= n * (n - 1) // 2:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	(d, e) = (n * (n - 1) // 2, n - 1)
	if n == 1:
		if m == 0 and k > 1:
			print('YES')
		else:
			print('NO')
	elif n == 2:
		if m == 1 and k > 2:
			print('YES')
		else:
			print('NO')
	elif m >= e and m <= d:
		if d == m:
			if k > 2:
				print('YES')
			else:
				print('NO')
		elif k > 3:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	(n, m, k) = map(int, input().strip().split())
	if m > n * (n - 1) / 2:
		print('NO')
	elif m < n - 1:
		print('NO')
	elif n == 2:
		if k > 2:
			print('YES')
		else:
			print('NO')
	elif n == 1:
		if k > 1:
			print('YES')
		else:
			print('NO')
	elif 1 + int(m != n * (n - 1) // 2) < k - 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	ans = 'NO'
	if m == 0 and n == 1 and (k > 1):
		ans = 'YES'
	elif m >= n - 1 and m <= n * (n - 1) // 2:
		if m == n * (n - 1) // 2 and k > 2:
			ans = 'YES'
		elif k > 3:
			ans = 'YES'
	print(ans)


def main():
	test_cases = range(int(input()))
	for test_case in test_cases:
		(n, m, k) = [int(i) for i in input().split(' ')]
		if n - 1 > m:
			print('NO')
		else:
			if m > n * (n - 1) // 2:
				print('NO')
				continue
			k = max(0, k - 1)
			if k == 0:
				print('NO')
			elif k == 1:
				if n == 1:
					print('YES')
				else:
					print('NO')
			elif k == 2:
				d = (n - 1) * n // 2
				if n <= 2 or m == d:
					print('YES')
				else:
					print('NO')
			else:
				print('YES')
main()


import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
	(n, m, k) = list(map(int, input().split()))
	max_edges = n * (n - 1) // 2
	if m < n - 1 or m > max_edges:
		print('NO')
	elif n == 1:
		if k > 1:
			print('YES')
		else:
			print('NO')
	elif m < max_edges:
		if k > 3:
			print('YES')
		else:
			print('NO')
	elif k > 2:
		print('YES')
	else:
		print('NO')


import sys
input = lambda : sys.stdin.readline()

def read_ints():
	return [int(x) for x in input().split(' ')]

def read_int():
	return int(input())

def min_e(n):
	return n - 1

def max_e(n):
	return n * (n - 1) // 2
T = read_int()
ans = []
for t in range(T):
	(n, m, k) = read_ints()
	mie = min_e(n)
	mae = max_e(n)
	if mie <= m <= mae:
		if n == 1:
			d = 0
		elif m == mae:
			d = 1
		else:
			d = 2
		if k - 1 > d:
			ans.append('YES')
		else:
			ans.append('NO')
	else:
		ans.append('NO')
print('\n'.join(ans))


import sys
from bisect import bisect_right as lb
from collections import deque
from queue import PriorityQueue as pq
from math import gcd
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
lii = lambda : list(map(int, list(ip())))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
for _ in range(ii()):
	(n, m, k) = il()
	if k <= 1:
		print('NO')
		continue
	if n == 1:
		if m == 0:
			prinT('YES')
		else:
			prinT('NO')
		continue
	if m < n - 1 or m > n * (n - 1) // 2:
		prinT('NO')
		continue
	t = n * (n - 1) // 2
	d = 0
	if m == t:
		d = 1
	else:
		d = 2
	if d < k - 1:
		prinT('YES')
	else:
		prinT('NO')


import math
import array

def solve():
	(n, m, k) = [int(i) for i in input().split(' ')]
	if m > n * (n - 1) // 2:
		print('No')
		return
	if k < 2:
		print('No')
		return
	if n == 1:
		print('Yes')
		return
	if k <= 2:
		print('No')
		return
	if m == n * (n - 1) // 2:
		print('Yes')
		return
	if k <= 3:
		print('No')
		return
	print(['No', 'Yes'][m >= n - 1])
	return

def main():
	t = 0
	t = int(input())
	for i in range(t):
		solve()
	return
main()


import sys

def solution():
	(n, m, k) = list(map(int, sys.stdin.readline().split()))
	if n == 1 and m == 0 and (k > 1):
		print('YES')
	elif m > n * (n - 1) // 2:
		print('NO')
	elif m == n * (n - 1) // 2 and k > 2:
		print('YES')
	elif m < n - 1:
		print('NO')
	elif k > 3:
		print('YES')
	else:
		print('NO')
for _ in range(int(sys.stdin.readline())):
	solution()


import os, sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd
from _collections import deque
import heapq as hp
from bisect import bisect_left, bisect_right
from math import cos, sin
from itertools import permutations
from operator import itemgetter
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')
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	k -= 2
	if m < n - 1 or n * (n - 1) // 2 < m:
		print('NO')
		continue
	if n == 1 or n == 2:
		if k >= n - 1:
			print('YES')
		else:
			print('NO')
		continue
	if m == n * (n - 1) // 2:
		if k >= 1:
			print('YES')
		else:
			print('NO')
		continue
	if k >= 2:
		print('YES')
	else:
		print('NO')


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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter, defaultdict
import math
import heapq
import bisect

def nck(n, k):
	res = 1
	for i in range(1, k + 1):
		res = res * (n - i + 1) // i
	return res
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if m < n - 1 or m > (n - 1) * n // 2 or k == 0 or (k == 1):
		print('NO')
	elif k - 1 == 2:
		if m == (n - 1) * n // 2:
			print('YES')
		else:
			print('NO')
	elif k - 1 == 1:
		print('YES' if n == 1 else 'NO')
	else:
		print('YES')


t = int(input())
for tc in range(t):
	(n, m, k) = map(int, input().split())
	if k <= 1 and n == 1:
		print('NO')
		continue
	elif n == 2 and k <= 2:
		print('NO')
		continue
	if n - 1 > m or m > n * (n - 1) // 2:
		print('NO')
		continue
	elif n >= 3 and (m < n * (n - 1) // 2 and k <= 3 or n - 1 > m or (m >= n * (n - 1) // 2 and k <= 2)):
		print('NO')
		continue
	else:
		print('YES')


t = int(input())
for i in range(0, t):
	(v, e, k) = [int(i) for i in input().split()]
	if k < 2:
		print('NO')
	elif k == 2:
		if v == 1 and e == 0:
			print('YES')
		else:
			print('NO')
	elif k == 3:
		if e == v * (v - 1) / 2:
			print('YES')
		else:
			print('NO')
	elif v - 1 <= e <= v * (v - 1) / 2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	if n == 1 and m == 0 and (k > 1):
		print('YES')
		continue
	if m < n - 1:
		print('NO')
	else:
		e = n * (n - 1) // 2
		if e == m and k >= 3 or (e > m and k >= 4):
			print('YES')
		else:
			print('NO')


import sys
import string
from decimal import Decimal
from math import log, sqrt, floor

def inp():
	return int(input())

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

def inpstrlist():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
t = int(input())
for _ in range(t):
	(n, m, k) = invr()
	if m < n - 1:
		print('NO')
		continue
	max_edges = n * (n - 1) // 2
	if m > max_edges:
		print('NO')
		continue
	if k == 0 or k == 1:
		print('NO')
		continue
	elif k == 2:
		if m == 0:
			print('YES')
		else:
			print('NO')
	elif k == 3:
		if m == max_edges:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')


t = int(input())
for i in range(t):
	answer = 'YES'
	(n, m, k) = map(int, input().split())
	if k <= 2:
		if n != 1 or k != 2 or m != 0:
			answer = 'NO'
	if k == 3:
		if m != n * (n - 1) // 2:
			answer = 'NO'
	if k >= 3:
		if not n - 1 <= m <= n * (n - 1) // 2:
			answer = 'NO'
	print(answer)


from sys import stdin, stdout

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

def printi(s):
	return stdout.write(s + '\n')
t = int(input())
for _ in range(t):
	(n, m, k) = get_ints()
	f = 2
	l = n * (n - 1) // 2
	if l < m or n - 1 > m:
		print('NO')
	elif n == 1:
		if m != 0 or k <= 1:
			print('NO')
		else:
			print('YES')
	else:
		if m == l:
			f = 1
		if f < k - 1:
			print('YES')
		else:
			print('NO')


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = n * (n - 1) // 2
	if l < m or n - 1 > m:
		print('NO')
	elif n == 1:
		if m != 0 or k <= 1:
			print('NO')
		else:
			print('YES')
	else:
		d = 2
		if m == l:
			d = 1
		if d < k - 1:
			print('YES')
		else:
			print('NO')


from sys import stdin
input = stdin.readline
test = int(input())
for _ in range(test):
	(n, m, k) = map(int, input().split())
	edges = n * (n - 1) // 2
	if edges < m or m < n - 1:
		print('NO')
	elif k >= 4:
		print('YES')
	elif k == 3 and (n <= 2 or edges == m):
		print('YES')
	elif k == 2 and n == 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
a = int(input())
for i in range(a):
	(n, m, k) = map(int, input().split())
	if m < n - 1 or m > n * (n - 1) // 2:
		print('NO')
		continue
	edges = n * (n - 1) // 2
	if k > 3:
		print('YES')
		continue
	if k == 3:
		if m == edges:
			print('YES')
		else:
			print('NO')
	if k <= 2:
		if k == 2 and n == 1:
			print('YES')
			continue
		print('NO')


def solution():
	(n, m, k) = map(int, input().split())
	if n * (n - 1) / 2 < m or n - 1 > m:
		print('NO')
	elif k <= 1 and n == 1:
		print('NO')
	elif k <= 2 and n == 2:
		print('NO')
	elif n >= 3 and (m < n * (n - 1) / 2 and k <= 3 or n - 1 > m or (m >= n * (n - 1) / 2 and k <= 2)):
		print('NO')
	else:
		print('YES')
t = int(input())
for loop in range(t):
	solution()


import sys
input = sys.stdin.readline

def get():
	return input().strip()
for _ in range(int(get())):
	(n, m, k) = map(int, input().split())
	k = k - 2
	if m > n * (n - 1) // 2:
		print('NO')
	elif m < n - 1:
		print('NO')
	elif k >= 2:
		print('YES')
	elif k == 1 and m == n * (n - 1) // 2:
		print('YES')
	elif k == 0 and n == 1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def solve():
	(n, m, k) = [int(_) for _ in input().split()]
	if n * (n - 1) // 2 < m or m < n - 1:
		print('no')
		return
	if k >= 4:
		print('yes')
		return
	if k == 3 and m == n * (n - 1) // 2:
		print('yes')
		return
	if k == 2 and n == 1:
		print('yes')
		return
	print('no')
tt = int(input())
for test in range(tt):
	solve()


import sys
input = sys.stdin.readline
print = sys.stdout.write
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	su = a * (a - 1) // 2
	if a == 1:
		if b == 0:
			print('YES\n' if c > 1 else 'NO\n')
		else:
			print('NO\n')
	elif a == 2:
		if b == 1:
			print('YES\n' if c > 2 else 'NO\n')
		else:
			print('NO\n')
	elif b < a - 1:
		print('NO\n')
	elif su < b:
		print('NO\n')
	elif su == b:
		print('YES\n' if c > 2 else 'NO\n')
	elif c <= 3:
		print('NO\n')
	elif c > 3:
		print('YES\n')


t = int(input())
while t:
	(n, m, k) = map(int, input().split())
	mx = n * (n - 1) / 2
	mn = n - 1
	if m > mx:
		print('NO')
	elif m < mn:
		print('NO')
	elif k <= 1:
		print('NO')
	elif k == 2:
		if n == 1:
			print('YES')
		else:
			print('NO')
	elif k == 3:
		if m == mx:
			print('YES')
		else:
			print('NO')
	else:
		print('YES')
	t -= 1


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	t = a * (a - 1) // 2
	if b < a - 1 or b > t:
		print('NO')
	elif c <= 2 and a == 2:
		print('NO')
	elif c <= 1 and a == 1:
		print('NO')
	elif a >= 3 and (b < t and c <= 3 or (b >= t and c <= 2)):
		print('NO')
	else:
		print('YES')


t = int(input())

def f(n, m, k):
	if k <= 1:
		return False
	if m > n * (n - 1) / 2:
		return False
	if k - 2 == 0:
		return n == 1
	if k - 2 == 1:
		return m == n * (n - 1) // 2
	if k - 2 >= 2:
		return m >= n - 1
for _ in range(t):
	(n, m, k) = map(int, input().split())
	ok = f(n, m, k)
	if ok:
		print('YES')
	else:
		print('NO')


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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	if n == 1:
		if m == 0 and k >= 2:
			print('YES')
		else:
			print('NO')
	else:
		flag = 0
		if m > (n - 1) * n // 2:
			flag = 1
		if m == (n - 1) * n // 2:
			diameter = 1
		elif m >= n - 1:
			diameter = 2
		else:
			flag = 1
		if flag == 0:
			if diameter < k - 1:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')


t = int(input())
for tests in range(t):
	(n, m, k) = map(int, input().split(' '))
	if m > n * (n - 1) // 2:
		print('NO')
		continue
	elif m < n - 1:
		print('NO')
		continue
	elif k - 1 > 2:
		print('YES')
	elif k - 1 <= 0:
		print('NO')
	elif k - 1 == 1:
		if n == 1:
			print('YES')
		else:
			print('NO')
	elif m == n * (n - 1) // 2 and k - 1 == 2:
		print('YES')
	else:
		print('NO')


from math import sqrt, gcd, ceil, floor, log, factorial
from itertools import permutations, combinations
from collections import Counter, defaultdict
import collections, sys, threading
import collections, sys, threading
input = sys.stdin.readline

def ii():
	return int(input())

def si():
	return input()

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

def msi():
	return map(str, input().split())

def li():
	return list(mi())
t = ii()
for _ in range(t):
	(n, m, k) = mi()
	if k <= 1:
		print('NO')
	elif k == 2:
		if n <= 1 and m == 0:
			print('YES')
		else:
			print('NO')
	elif n - 1 <= m <= n * (n - 1) // 2:
		if m == n * (n - 1) // 2:
			if k > 2:
				print('YES')
			else:
				print('NO')
		elif k > 3:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import bisect
import heapq
import math
import collections
import sys
import copy
from functools import reduce
import decimal
from io import BytesIO, IOBase
import os
import itertools
import functools
from types import GeneratorType
sys.setrecursionlimit(10 ** 9)
decimal.getcontext().rounding = decimal.ROUND_HALF_UP
graphDict = collections.defaultdict
queue = collections.deque

def bootstrap(f, stack=[]):

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

class Graphs:

	def __init__(self):
		self.graph = graphDict(set)

	def add_edge(self, u, v):
		self.graph[u].add(v)

	def dfs_utility(self, nodes, visited_nodes):
		visited_nodes.add(nodes)
		for neighbour in self.graph[nodes]:
			if neighbour not in visited_nodes:
				self.dfs_utility(neighbour, visited_nodes)

	def dfs(self, node):
		Visited = set()
		self.dfs_utility(i, Visited)

	def bfs(self, node, f_node):
		count = float('inf')
		visited = set()
		level = 0
		if node not in visited:
			queue.append([node, level])
			visited.add(node)
		flag = 0
		while queue:
			parent = queue.popleft()
			if parent[0] == f_node:
				flag = 1
				count = min(count, parent[1])
			level = parent[1] + 1
			for item in self.graph[parent[0]]:
				if item not in visited:
					queue.append([item, level])
					visited.add(item)
		return count if flag else -1
		return False

	def solve(self, in_degree):
		c = 0
		tracker = queue()
		ans = graphDict(lambda : 1)
		for ii in range(n):
			if in_degree[ii + 1] == 0:
				tracker.append(ii + 1)
		while tracker:
			node = tracker.popleft()
			c += 1
			for neighbour in self.graph[node]:
				in_degree[neighbour] -= 1
				if neighbour < node:
					ans[neighbour] = max(ans[neighbour], ans[node] + 1)
				else:
					ans[neighbour] = max(ans[neighbour], ans[node])
				if in_degree[neighbour] == 0:
					tracker.append(neighbour)
		if c != n:
			return False
		else:
			return max(ans.values()) if len(ans.values()) > 0 else 1
		return 'Send Help!!!!'

class Tree:

	def __init__(self, data):
		self.data = data
		self.left = None
		self.right = None

def inorder(node, lis):
	if node:
		inorder(node.left, lis)
		lis.append(node.data)
		inorder(node.right, lis)
	return lis

def leaf_node_sum(root):
	if root is None:
		return 0
	if root.left is None and root.right is None:
		return root.data
	return leaf_node_sum(root.left) + leaf_node_sum(root.right)

def hight(root):
	if root is None:
		return -1
	if root.left is None and root.right is None:
		return 0
	return max(hight(root.left), hight(root.right)) + 1

class UF:

	def __init__(self, N):
		self._id = list(range(N))
		self._count = N
		self._rank = [0] * N

	def find(self, p):
		id = self._id
		while p != id[p]:
			p = id[p]
		return p

	def count(self):
		return self._count

	def connected(self, p, q):
		return self.find(p) == self.find(q)

	def union(self, p, q):
		id = self._id
		rank = self._rank
		i = self.find(p)
		j = self.find(q)
		if i == j:
			return
		self._count -= 1
		if rank[i] < rank[j]:
			id[i] = j
		elif rank[i] > rank[j]:
			id[j] = i
		else:
			id[j] = i
			rank[i] += 1

	def add_roads(self):
		return set(self._id)

	def __str__(self):
		return ' '.join([str(x) for x in self._id])

	def __repr__(self):
		return 'UF(' + str(self) + ')'

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

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

def p_sum(array):
	return list(itertools.accumulate(array))

def diophantine(a: int, b: int, c: int):
	(d, x, y) = extended_gcd(a, b)
	r = c // d
	return (r * x, r * y)

@bootstrap
def extended_gcd(a: int, b: int):
	if b == 0:
		(d, x, y) = (a, 1, 0)
	else:
		(d, p, q) = (yield extended_gcd(b, a % b))
		x = q
		y = p - q * (a // b)
	yield (d, x, y)
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, **kwargs):
		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 inp():
	return sys.stdin.readline().strip()

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))

def update(fen_tree, index):
	while index < len(fen_tree):
		fen_tree[index] += 1
		index += index & -index

def query(fen_tree, index):
	s = 0
	while index > 0:
		s += fen_tree[index]
		index -= index & -index
	return s
for _ in range(int(inp())):
	(n, m, k) = map_inp(int)
	if n == 1:
		if m > 0 or k <= 1:
			print('NO')
		else:
			print('YES')
	elif k <= 2:
		print('NO')
	elif n - m > 1:
		print('NO')
	elif n - m == 1:
		if k <= 2 and n == 2:
			print('NO')
		elif k <= 3 and n >= 3:
			print('NO')
		else:
			print('YES')
	elif m > n * (n - 1) // 2:
		print('NO')
	elif m < n * (n - 1) // 2:
		if k <= 2 and n == 2:
			print('NO')
		elif k <= 3 and n >= 3:
			print('NO')
		else:
			print('YES')
	else:
		print('YES')


t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	if m < n - 1 or m > n * (n - 1) // 2:
		print('NO')
	elif n == 1:
		if k > 1:
			print('YES')
		else:
			print('NO')
	elif m < n * (n - 1) // 2:
		if k > 3:
			print('YES')
		else:
			print('NO')
	elif k > 2:
		print('YES')
	else:
		print('NO')


from __future__ import print_function
from math import *
from collections import deque
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
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')
mod = 10 ** 9 + 7

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	(n, m, k) = invr()
	k = k - 2
	if m > n * (n - 1) // 2 or m < n - 1:
		print('NO')
		continue
	if k < 0:
		print('NO')
		continue
	if k == 0:
		if n == 1:
			print('YES')
		else:
			print('NO')
		continue
	if k == 1:
		if n * (n - 1) // 2 == m:
			print('YES')
		else:
			print('NO')
		continue
	print('YES')


import math
from collections import defaultdict, Counter
from bisect import bisect_left
from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, m, k) = list(map(int, input().split()))
	if m > n * (n - 1) // 2 or m < n - 1:
		print('NO')
	elif k <= 1:
		print('NO')
	elif m == 0 or n == 1:
		print('YES')
	elif m < n - 1 or m > n * (n - 1) // 2:
		print('NO')
	elif m == n * (n - 1) // 2:
		if k > 2:
			print('YES')
		else:
			print('NO')
	elif k > 3:
		print('YES')
	else:
		print('NO')


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07

def update_it(bit, i, val):
	n = len(bit)
	while i < n:
		bit[i] += val
		i += i & -i

def get_ans(bit, i):
	n = len(bit)
	tot = 0
	while i > 0:
		tot += bit[i]
		i -= i & -i
	return tot

def hnbhai(tc):
	(n, m, k) = sd()
	if k <= 1:
		print('NO')
		return
	if n == 1:
		print('YES' if m == 0 else 'NO')
		return
	if m < n - 1 or m > n * (n - 1) // 2:
		print('NO')
		return
	mx = n * (n - 1) // 2
	if mx == m:
		tot = 1
	else:
		tot = 2
	if tot < k - 1:
		print('YES')
		return
	print('NO')
for _ in range(sb()):
	hnbhai(_ + 1)


a = int(input())
for i in range(a):
	arr = [int(a) for a in input().split()]
	n = int(arr[0])
	m = int(arr[1])
	k = int(arr[2])
	if n == 1 and m == 0:
		if 0 < k - 1:
			print('yes')
		else:
			print('no')
	else:
		mi = 2000000000000000.0
		if m < n - 1:
			mi = 2000000000000000.0
		elif m < n * (n - 1) / 2:
			mi = 2
		elif m == n * (n - 1) / 2:
			mi = 1
		if mi < k - 1:
			print('yes')
		else:
			print('no')


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	large = n * (n - 1) // 2
	d = 0
	if k <= 1:
		print('NO')
	elif n == 1:
		if m == 0:
			print('YES')
		else:
			print('NO')
	elif m >= n - 1 and m <= large:
		k -= 1
		if m == large:
			if k >= 2:
				print('YES')
			else:
				print('NO')
		elif k >= 3:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def solve(n, m, k):
	if n * (n - 1) // 2 < m or m < n - 1:
		return False
	if n == 1:
		if k > 1:
			return True
		else:
			return False
	elif m < n * (n - 1) // 2:
		if k > 3:
			return True
		else:
			return False
	elif k > 2:
		return True
	else:
		return False
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	ans = solve(n, m, k)
	if ans:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

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

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import copy, string, math, time, functools, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, chain, combinations, groupby
from operator import itemgetter
from types import GeneratorType
from typing import Iterable, TypeVar, Union
for _ in range(II()):
	(n, m, k) = LI()
	k -= 2
	if n == 1:
		if m == 0 and k >= 0:
			print('YES')
		else:
			print('NO')
		continue
	if m > n * (n - 1) // 2:
		print('NO')
		continue
	if m == n * (n - 1) // 2:
		if k >= 1:
			print('YES')
		else:
			print('NO')
		continue
	if m >= n - 1:
		if k >= 2:
			print('YES')
		else:
			print('NO')
		continue
	print('NO')


import sys
sys.setrecursionlimit(100000)

def _r():
	return sys.stdin.buffer.readline()

def rs():
	return _r().decode('ascii').strip()

def rn():
	return int(_r())

def rnt():
	return map(int, _r().split())

def rnl():
	return list(rnt())

def solve(n, m, k):
	if n == 1:
		return m == 0 and k > 1
	full = n * (n - 1) // 2
	if k > 2 and n - 1 <= m <= full:
		return k > 3 or m == full
	return False
for _ in range(rn()):
	(n, m, k) = rnt()
	print('YES' if solve(n, m, k) else 'NO')


import sys
from math import factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest, nsmallest
from itertools import groupby, accumulate
from copy import deepcopy
MOD = 10 ** 9 + 7
INF = float('inf')
input = sys.stdin.readline
rl = lambda : list(map(int, input().split()))
rs = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, m, k) = rl()
	if n == 1:
		if m > 0 or k <= 1:
			print('NO')
		else:
			print('YES')
	elif m < n - 1 or k <= 2:
		print('NO')
	elif k == 3 and n * (n - 1) // 2 != m:
		print('NO')
	elif m > n * (n - 1) // 2:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline

def solve():
	(n, m, k) = map(int, input().split())
	if not n - 1 <= m <= n * (n - 1) // 2:
		return 'NO'
	if k <= 1:
		return 'NO'
	if m == 0:
		if n > 1:
			return 'NO'
		else:
			return 'YES'
	if n == 1:
		if m != 0:
			return 'NO'
		else:
			return 'YES'
	maxEdge = n * (n - 1) // 2
	if maxEdge == m:
		return 'YES' if k >= 3 else 'NO'
	elif maxEdge < m:
		return 'NO'
	else:
		return 'NO' if k < 4 or m < n - 1 else 'YES'
for _ in range(int(input())):
	print(solve())


t = int(input())
for time in range(t):
	(n, m, k) = (int(i) for i in input().split())
	if n == 1 and m == 0 and (k >= 2):
		print('YES')
	elif k < 3 or n > m + 1 or m > n * (n - 1) / 2:
		print('NO')
	elif m == n * (n - 1) / 2 and k >= 3:
		print('YES')
	elif k >= 4:
		print('YES')
	else:
		print('NO')


from itertools import permutations, combinations
import math
import io, os, sys
input1 = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
pf = lambda i: sys.stdout.write(str(i) + '\n')
p = lambda i: sys.stdout.write(i)
LST = lambda : list(map(int, input1().split()))
INT = lambda : int(input1())
STR = lambda : input1().decode()
MAP = lambda : map(int, input1().split())
c_lst = lambda item: list(item)
c_STR = lambda item: ''.join(item)
d_To_Binary = lambda item: bin(n).replace('0b', '')
b_to_decimal = lambda item: int(item, 2)
even = lambda item: item % 2 == 0
odd = lambda item: item % 2 == 1

def flatten_list(l):
	return sum(l, [])

def perm(s, size=0):
	if size == 0:
		size = len(s)
	s = c_lst(s)
	perm = permutations(s, size)
	return list(perm)

def combi(s, size=0):
	if size == 0:
		size = len(s)
	s = c_lst(s)
	comb = combinations(s, size)
	return list(comb)

def countPrime(n):
	n = n + 1
	primes = []
	prime = [True for i in range(n + 1)]
	p = 2
	count = 0
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n):
		if prime[p]:
			count += 1
	return count

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

def factors(x):
	result = []
	i = 1
	while i * i <= x:
		if x % i == 0:
			result.append(i)
			if x // i != i:
				result.append(x // i)
		i += 1
	return result

def factorial(n):
	ans = 1
	for i in range(3, n + 1):
		ans *= i
		ans %= 10 ** 9 + 7
	return ans
for _ in range(INT()):
	(n, m, k) = MAP()
	k -= 2
	if n == 1 and m == 0 and (k >= 0):
		pf('YES')
		continue
	if k <= 0 or m > n * (n - 1) // 2:
		pf('NO')
		continue
	if m == n * (n - 1) // 2:
		pf('YES')
		continue
	if k >= 2 and m >= n - 1:
		pf('YES')
	else:
		pf('NO')


n = int(input())
for time in range(n):
	(a, b, c) = (int(i) for i in input().split())
	if a == 1 and b == 0 and (c >= 2):
		print('YES')
	elif c < 3 or a > b + 1 or b > a * (a - 1) / 2:
		print('NO')
	elif b == a * (a - 1) / 2 and c >= 3:
		print('YES')
	elif c >= 4:
		print('YES')
	else:
		print('NO')


tc = int(input())
for t in range(tc):
	(n, m, k) = map(int, input().split())
	diam = 10
	pos = False
	full_graph_n = int(n * ((n - 1) / 2))
	if m > full_graph_n:
		pos = False
	elif n == 1:
		diam = 0
		pos = True
	elif m == full_graph_n:
		diam = 1
		pos = True
	elif m >= n - 1:
		diam = 2
		pos = True
	if diam < k - 1 and pos:
		print('YES')
	else:
		print('NO')


try:
	import sys
	from functools import lru_cache, cmp_to_key
	from heapq import merge, heapify, heappop, heappush
	from collections import defaultdict as dd, deque, Counter as C
	from itertools import combinations as comb, permutations as perm
	from bisect import bisect_left as bl, bisect_right as br, bisect, insort
	from time import perf_counter
	from fractions import Fraction
	import copy
	from copy import deepcopy
	import time
	starttime = time.time()
	mod = int(pow(10, 9) + 7)
	mod2 = 998244353

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

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

	def L():
		return list(sp())

	def sl():
		return list(ssp())

	def sp():
		return map(int, data().split())

	def ssp():
		return map(str, data().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 A2(n, m):
		return [[0] * m for i in range(n)]

	def A(n):
		return [0] * n
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
for _ in range(L()[0]):
	(n, m, k) = L()
	if k <= 2:
		if k <= 1:
			print('NO')
		elif k == 2:
			if n > 1:
				print('NO')
			elif m == 0:
				print('YES')
			else:
				print('NO')
	elif k == 3:
		if m == n * (n - 1) // 2:
			print('YES')
		else:
			print('NO')
	elif n - 1 <= m <= n * (n - 1) // 2:
		print('YES')
	else:
		print('NO')


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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict, deque
from math import ceil, floor, sqrt, log2, gcd, pi
from heapq import heappush, heappop
from bisect import bisect_left, bisect
from functools import reduce
import sys
abc = 'abcdefghijklmnopqrstuvwxyz'
ABC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	mini = n - 1
	maxi = n * (n - 1) // 2
	if m < mini:
		print('NO')
	elif m > maxi:
		print('NO')
	else:
		d = float('inf')
		if m == maxi:
			d = 1
		else:
			d = 2
		if n == 1 and m == 0:
			d = 0
		if d + 1 < k:
			print('YES')
		else:
			print('NO')


from collections import deque as de
import math
import sys
from math import sqrt as sq
from math import floor as fl
from math import ceil as ce
from sys import getfilesystemencodeerrors, stdin, stdout
sys.setrecursionlimit(10 ** 7)
from collections import Counter as cnt
from functools import reduce
from itertools import groupby as gb
from bisect import bisect_left as bl, bisect_right as br
from typing import Coroutine

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

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def __iter__(self):
		return iter(self.data)

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0

	def len(self):
		return len(self.data)
arrStack = My_stack()

class graph:

	def __init__(self):
		self.graphdict = {}

	def add_edge(self, node, neighbor):
		if node not in self.graphdict:
			self.graphdict[node] = [neighbor]
		else:
			self.graphdict[node].append(neighbor)

	def show_edge(self):
		for node in self.graphdict:
			for neighbors in self.graphdict:
				print(node, neighbors)

	def show_graph(self):
		return self.graphdict

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

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

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def regularBracketsequence(str, arrStack):
	for i in range(len(str)):
		if str[i] == '(':
			arrStack.my_push(str[i])
		elif arrStack.isEmpty():
			return False
		else:
			arrStack.my_pop()
	if arrStack.isEmpty():
		return True
	else:
		return False

def lcm(x, y):
	lcm = x * y // math.gcd(x, y)
	return lcm

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def checkisap(list):
	d = list[1] - list[0]
	for i in range(2, len(list)):
		temp = list[i] - list[i - 1]
		if temp != d:
			return False
	return True

def primes_method5(n):
	out = {}
	sieve = [True] * (n + 1)
	for p in range(2, n + 1):
		if sieve[p]:
			out[p] = 1
			for i in range(p, n + 1, p):
				sieve[i] = False
	return out

def id(i, j, col):
	ans = (i - 1) * col
	ans += j
	return ans

def getSum(n):
	strr = str(n)
	list_of_number = list(map(int, strr.strip()))
	return sum(list_of_number)

def checkperfectsquare(n):
	if ce(sq(n)) == fl(sq(n)):
		return True
	else:
		return False

def ceildiv(x, y):
	return (x + y - 1) // y

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

def ii():
	return int(input())

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

def si():
	return list(map(str, input()))

def indict():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(value)] = int(index)
	return dic

def frqdict():
	dic = {}
	for (index, value) in enumerate(input()):
		if value not in dic:
			dic[value] = 1
		else:
			dic[value] += 1
	return dic

def func(n, m, k):
	if m > n * (n - 1) // 2:
		return 'NO'
	if k <= 1:
		return 'NO'
	if k == 2:
		if n == 1 and m == 0:
			return 'YES'
		return 'NO'
	if k == 3:
		if m == n * (n - 1) // 2:
			return 'YES'
		return 'NO'
	if m < n - 1:
		return 'NO'
	return 'YES'
t = ii()
while t:
	t -= 1
	(n, m, k) = di()
	ans = func(n, m, k)
	print(ans)


import sys
import os
from io import BytesIO
if sys.version_info[0] < 3:
	sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
f = sys.stdin
if os.environ.get('USER') == 'loic':
	f = open('data.in')
line = lambda : f.readline().strip('\r\n').split()

def write(w):
	sys.stdout.write(w)
	sys.stdout.write('\n')

def solve():
	k = K - 2
	if N == 1:
		if M == 0 and k >= 0:
			return 'YES'
		else:
			return 'NO'
	if N > M + 1:
		return 'NO'
	if (N - 1) * N // 2 == M:
		if k >= 1:
			return 'YES'
		else:
			return 'NO'
	if (N - 1) * N // 2 < M:
		return 'NO'
	if N == M + 1:
		if k >= 2:
			return 'YES'
		else:
			return 'NO'
	if k >= 2:
		return 'YES'
	return 'NO'
T = int(line()[0])
for test in range(1, T + 1):
	(N, M, K) = map(int, line())
	write(solve())
f.close()


import sys
testcases = int(input())
while testcases > 0:
	(n, m, k) = map(int, sys.stdin.readline().split())
	if k == 3 and m == n * (n - 1) // 2 or (k > 3 and n - 1 <= m <= n * (n - 1) // 2) or (n == 1 and m == 0 and (k > 1)):
		print('YES')
	else:
		print('NO')
	testcases -= 1


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
inf = 10 ** 20
mod = 10 ** 9 + 7

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

def II():
	return int(input())

def LS():
	return list(input().split())

def S():
	return input()

def solve():
	(n, m, k) = LI()
	if n * (n - 1) // 2 < m:
		return 'NO'
	if k <= 1:
		return 'NO'
	if k == 2:
		return 'NO' if n > 1 else 'YES'
	if k == 3:
		return 'YES' if n * (n - 1) // 2 == m else 'NO'
	return 'NO' if n - 1 > m else 'YES'

def main():
	t = II()
	res = list()
	for _ in range(t):
		ans = solve()
		res.append(ans)
	for ans in res:
		print(ans)
	return 0
main()