import java.util.*;
import java.io.*;

public class DeletionGame {

	boolean solve(long n, long k) {
		if (n == 2) {
			if (k == 3 || k == 1 || k == -1) {
				return true;
			}
			return false;
		}
		long s = n * (n + 1) / 2;
		if (k % 2 != s % 2) {
			return false;
		}
		if (-s + 2 <= k && k <= s) {
			return true;
		}
		return false;
	}

	static void load(Scanner scanner) {
		int t = scanner.nextInt();
		for (int i = 0; i < t; i++) {
			long n = scanner.nextLong();
			long k = scanner.nextLong();
			System.out.println((new DeletionGame().solve(n, k)) ? "YES" : "NO");
		}
	}

	public static void main(String[] args) throws Exception {
		Scanner scanner;
		if (args.length == 1 && "COHADAR".equals(args[0])) {
			scanner = new Scanner(new File("deletion-game.in"));
		} else {
			scanner = new Scanner(System.in);
		}
		load(scanner);
	}
}

@@ -61,16 +61,187 @@
 Game %7B%0A%0A
+%09// I got only half points on this challenge because I forgot modulo is a signed operation.%0A%09// I was behaving like an idiot, did not make a single test for a negative K.%0A
 %09boolean
@@ -265,16 +265,16 @@
 ng k) %7B%0A
-
 %09%09if (n 
@@ -399,14 +399,24 @@
 %09if 
+(Math.abs
 (k %25 2
+)
  != 

negative modulo