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.io.DataInputStream;
  import java.io.FileInputStream;
  import java.io.IOException;
  
  public class DiameterGraph {
      private static String solve(int n, int m, int k) {
          int d = 0;
          if (2l * (long) m + (long) n > (long) n * (long) n || m < n - 1)
              return "NO";
          if (m > 0 && m <= 2)
              d = m;
          else if (m > 2)
              d = 2;
  
          if (2l * (long) m + (long) n == (long) n * (long) n)
              d = 1;
  
  
          if (m == 0) d = 0;
  
  //        System.out.println(d);
          return (d < k - 1) ? "YES" : "NO";
      }
  
      public static void main(String[] args)
              throws IOException {
          Scanner s = new Scanner();
          int t = 1;
          t = s.nextInt();
          StringBuilder ans = new StringBuilder();
          int count = 0;
          while (t-- > 0) {
              int n = s.nextInt();
              int m = s.nextInt();
              int k = s.nextInt();
              ans.append(solve(n, m, k)).append("\n");
          }
          System.out.println(ans.toString());
      }
  
      static class Scanner {
          final private int BUFFER_SIZE = 1 << 16;
          private DataInputStream din;
          private byte[] buffer;
          private int bufferPointer, bytesRead;
  
          public Scanner() {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public Scanner(String file_name) throws IOException {
              din = new DataInputStream(
                      new FileInputStream(file_name));
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public String readLine() throws IOException {
              byte[] buf = new byte[64]; // line length
              int cnt = 0, c;
              while ((c = read()) != -1) {
                  if (c == '\n') {
                      if (cnt != 0) {
                          break;
                      } else {
                          continue;
                      }
                  }
                  buf[cnt++] = (byte) c;
              }
              return new String(buf, 0, cnt);
          }
  
          public int nextInt() throws IOException {
              int ret = 0;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          public long nextLong() throws IOException {
              long ret = 0;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
              if (neg)
                  return -ret;
              return ret;
          }
  
          public double nextDouble() throws IOException {
              double ret = 0, div = 1;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
  
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
  
              if (c == '.') {
                  while ((c = read()) >= '0' && c <= '9') {
                      ret += (c - '0') / (div *= 10);
                  }
              }
  
              if (neg)
                  return -ret;
              return ret;
          }
  
          private void fillBuffer() throws IOException {
              bytesRead = din.read(buffer, bufferPointer = 0,
                      BUFFER_SIZE);
              if (bytesRead == -1)
                  buffer[0] = -1;
          }
  
          private byte read() throws IOException {
              if (bufferPointer == bytesRead)
                  fillBuffer();
              return buffer[bufferPointer++];
          }
  
          public void close() throws IOException {
              if (din == null)
                  return;
              din.close();
          }
      }
  
      public static long norm(long a, long MOD) {
          return ((a % MOD) + MOD) % MOD;
      }
  
      public static long msub(long a, long b, long MOD) {
          return norm(norm(a, MOD) - norm(b, MOD), MOD);
  
      }
  
      public static long madd(long a, long b, long MOD) {
          return norm(norm(a, MOD) + norm(b, MOD), MOD);
  
      }
  
      public static long mMul(long a, long b, long MOD) {
          return norm(norm(a, MOD) * norm(b, MOD), MOD);
  
  
      }
  
      public static long mDiv(long a, long b, long MOD) {
          return norm(norm(a, MOD) / norm(b, MOD), MOD);
      }
  
      public static String formattedArray(int a[]) {
          StringBuilder res = new StringBuilder("");
          for (int e : a)
              res.append(e).append(" ");
          return res.toString().trim();
  
      }
  
  }
  