description: 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 ≤ t ≤ 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 ≤ n ≤ 10^9), m, k (0 ≤ m,k ≤ 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).
  
  Example
  
  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.
solution: import java.lang.reflect.Array;
  import java.math.BigInteger;
  import java.nio.file.attribute.FileAttribute;
  import java.util.*;
  import java.io.*;
  //a+b = (a^b) + 2*(a&b)
  //b^c = (a^b)^(a^c)
  //gcd(x,y) = gcd(x-y,y)
  // bit value at ith position changes in interval of 2^i
  // Do not define variables by a weird name
  // always use   (p*1LL >> q)
  // prefer 'int' than 'long long'
  // gcd(Fn,Fm) = Fgcd(n,m)  // Property of Fibonacci
  // lets prime factorization of n=(p1^e1)*(p2^e2) //total factors will be (e1+1)*(e2+1)
  // and some of factors would be (1+p1+p1^2 + .. p1^e1)*(1+p2+p2^2+...+p2^e2)
  // nC(r) + nC(r+1) = (n+1)C(r+1) => pascal's formula
  public class Main {
  
      static int gcd(int a, int b) {
          if (a == 0) return b;
          return gcd(b % a, a);
      }
  
      static class TrieNode {
          TrieNode childern[] = new TrieNode[26];
          int count = 0;
          boolean isEnd = false;
  
          TrieNode() {
              for (int i = 0; i < childern.length; ++i) childern[i] = null;
          }
      }
  
      //----------------------
  
  
      static int max(int tree[], int index, int left, int right, int l, int r, int max) {
  
          if (left >= right) {
              return 0;
          }
          if (right < l || r < left) {
              return 0;
          }
  
          System.out.println(index + " " + left + " " + right);
  
          int mid = (left + right) / 2;
          int first = max(tree, 2 * index + 1, left, mid, l, r, max);
          int second = max(tree, 2 * index + 2, mid + 1, right, l, r, max);
          return Math.max(first, second);
  
      }
  
      static class FastReader {
          BufferedReader br;
          StringTokenizer st;
  
          public FastReader() {
              br = new BufferedReader(
                      new InputStreamReader(System.in));
          }
  
          String next() {
              while (st == null || !st.hasMoreElements()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          long nextLong() {
              return Long.parseLong(next());
          }
  
          double nextDouble() {
              return Double.parseDouble(next());
          }
  
          String nextLine() {
              String str = "";
              try {
                  str = br.readLine();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return str;
          }
      }
  
      static int mod = 1000000007;
  
      static long mul(long a, long b) {
          return (a % mod * b % mod) % mod;
      }
  
      static long add(long a, long b) {
          return (a % mod + b % mod) % mod;
      }
  
      static long factorial(int n) {
          long ans = 1;
          for (int i = 1; i <= n; ++i) {
              ans = (ans % mod * i % mod) % mod;
          }
          return ans;
      }
  
  
      static long power(long x, long y, int p) {
          long res = 1;
          x = x % p;
          while (y > 0) {
  
  
              if (y % 2 == 1)
                  res = (res * x) % p;
  
              y = y >> 1;
              x = (x * x) % p;
          }
  
          return res;
      }
  
  
      static long modInverse(long n, int p) {
          return power(n, p - 2, p);
      }
  
      static long nCrModPFermat(int n, int r,
                                int p) {
  
          if (n < r) {
              return 0;
          } else if (r == 0) {
              return 1;
          }
  
  
          long[] fac = new long[n + 1];
          fac[0] = 1;
  
          for (int i = 1; i <= n; i++)
              fac[i] = fac[i - 1] * i % p;
  
          return (fac[n] * modInverse(fac[r], p)
                  % p * modInverse(fac[n - r], p)
                  % p)
                  % p;
      }
  
      static void print(int arr[]) {
          for (int elements : arr) System.out.print(elements + " ");
      }
  
      static boolean union(int x, int y, int parent[]) {
          int root1 = find(x, parent);
          int root2 = find(y, parent);
          if (root1 == root2) {
              return false;
          }
          parent[root1] = root2;
          return true;
      }
  
      static int find(int x, int parent[]) {
          if (x == parent[x]) {
              return x;
          }
          return parent[x] = find(parent[x], parent);  //path compression
      }
  
      static int dp[] = new int[1000006];
  
      static void count() {
          int dp[] = new int[1000006];
          Arrays.fill(dp, -1);
          int count = 0;
          for (int i = 2; i < dp.length; ++i) {
              if (dp[i] == -1) {
                  for (int j = i; j < dp.length; j += i) {
                      dp[j] = 1;
                      Main.dp[j]++;
                  }
              }
          }
  
      }
  
      static class Pair {
          int a;
          int b;
  
  
          Pair(int a, int b) {
              this.a = a;
              this.b = b;
  
  
          }
      }
  
      static int binarysearch(ArrayDeque<Integer> A, int low, int end, int element) {
          int ans1 = 0;
          ArrayList<Integer> ans = new ArrayList<>(A);
          //   System.out.println(ans);
          while (low <= end) {
              int mid = (low + end) / 2;
              if (ans.get(mid) > element) {
                  //  System.out.println(mid);
                  ans1 = mid;
                  end = mid - 1;
  
              } else {
                  low = mid + 1;
              }
          }
          return ans1;
      }
  
      static long arr[] = new long[1000001];
  
      static void fill() {
          Arrays.fill(arr, -1);
          boolean bl[] = new boolean[1000001];
          for (int i = 2; i * i <= arr.length; ++i) {
              if (arr[i] == -1) {
                  for (int j = i * i; j < arr.length; j += i) {
                      arr[j] = 1;
  
                  }
              }
          }
  
      }
  
      public static void main(String[] args) {
       FastReader scan=new FastReader();
       int t=scan.nextInt();
       while(t-->0) {
           long n = scan.nextLong(); //No of vertix
           int m = scan.nextInt(); //No of edges
           int k = scan.nextInt(); //Maximum distance;
           long max=n*(n-1)/2;
           int distance=k-2;
  
           if(m<(n-1)||m>max||distance<0){
               System.out.println("NO");
           }
           else
               if(n==1){
                   System.out.println("YES");
                   continue;
               }
           else
               if(max==m){
                   if(distance>=1){
                       System.out.println("YES");
                   }
                   else{
                       System.out.println("NO");
                   }
               }
               else{
                   if(distance>=2){
                       System.out.println("YES");
                   }
                   else{
                       System.out.println("NO");
                   }
               }
  
  
  
       }
      }
  }
  
  
  
  
  
  