import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.ObjectInputStream.GetField; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.InputMismatchException; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.PriorityQueue; import java.util.Queue; import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; public class first { static long MOD = 1000000007; static boolean b[],bc[]; static boolean boo[][][]; static ArrayList[] amp,amp1; static int sum[],dist[],cnt[]; static long ans = 0; static int p = 0; //static ArrayList[][][] pmp; static FasterScanner sc = new FasterScanner(); static Queue q = new LinkedList<>(); static int arr[],start[],color[]; static PriorityQueue pq; //static ArrayList parent = new ArrayList<>(); static LinkedList fa; static BufferedWriter log; static TreeMap tm = new TreeMap<>(); static HashSet hs = new HashSet<>(); static Stack stack = new Stack<>(); static Pair prr[]; static long parent1[],parent2[],size[][],size1[],size2[]; public static void main(String[] args) throws Exception { new Thread(null, new Runnable() { public void run() { try { soln(); } catch (Exception e) { e.printStackTrace(); } } }, "1", 1 << 26).start(); } public static void soln() throws IOException { log = new BufferedWriter(new OutputStreamWriter(System.out)); int q = sc.nextInt(); while(q-->0){ long l = sc.nextInt(), c = sc.nextInt(); long l1 = (l)/2; long min = (l1*(2*(l-1)+(l1-1)*(-2)))/2; long fact[] = new long[100001]; for(int i = 0;i<=100000;i++){ fact[i] = (1L*i*(i-1))/2; } long max =(l*(l-1))/2; if(c(max) )log.write("-1\n"); else{ long b = (max-c+1)/2; int k = (int) (l-1); for(int i = 0;i(); q.add(x); while(!q.isEmpty()){ int y = q.poll(); for(int i = 0;i { long u; long v; public Pair(long u, long v) { this.u = u; this.v = v; } public int hashCode() { int hu = (int) (u ^ (u >>> 32)); int hv = (int) (v ^ (v >>> 32)); return 31*hu + hv; } public boolean equals(Object o) { Pair other = (Pair) o; return (u == other.u && v == other.v); } public int compareTo(Pair other) { return Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u)) : (Long.compare(v, other.v)); } public String toString() { return "[u=" + u + ", v=" + v + "]"; } } public static void buildGraph(int n){ for(int i =0;i>2; si*=2; build(ss,mid,si);build(mid+1,se,si+1); } } /*int[] get(int qs, int qe, int ss, int se, int si){ if(qe < ss || se < qs) return new int[2]; if(qs<=ss && qe>=se){ return new int[]{max[si],val[si]}; } int mid = (ss+se)/2; si*=2; if(qe<=mid) return get(qs,qe,ss,mid,si); else if(qs>mid) return get(qs,qe,mid+1,se,si+1); long a1[] = build(ss,mid,si*2), a2[] = build(mid+1,se,si*2+1); long ans[] = new long[4]; if(arr[mid] == arr[mid+1]){ long temp = a1[2]+a2[0]; if(temp>=a2[1] && temp>=a1[1]){ ans[1] = temp; ans[3] = arr[mid]; } else if(a2[1]>=a1[1]){ ans[1] = a2[1]; ans[3] = a2[3]; } else{ ans[1] = a1[1]; ans[3] = a1[3]; } if(a1[1]==(mid-ss+1)) ans[0] = ans[1]; else ans[0] = a1[0]; if(a2[2]==(se-mid)) ans[2] = ans[1]; else ans[2] = a2[2]; } else{ if(a2[1]>=a1[1]){ ans[1] = a2[1]; ans[3] = a2[3]; } else{ ans[1] = a1[1]; ans[3] = a1[3]; } ans[0] = a1[0]; ans[2] = a2[2]; } return ans; } void print(){ for(int i = 0;i parent = new ArrayList<>(); HashMap hm = new HashMap<>(); public void insert(int x){ Node2 n = new Node2(); n.data = x; if(root==null){ root = n; } else{ Node2 temp = root,temp2 = null; while(temp!=null){ temp2 = temp; if(x>temp.data) temp = temp.right; else temp = temp.left; } if(x>temp2.data) temp2.right = n; else temp2.left = n; n.parent = temp2; parent.add(temp2.data); } } public Node2 getSomething(int x, int y, Node2 n){ if(n.data==x || n.data==y) return n; else if(n.data>x && n.datan.data){ max = Math.max(max, n.data); return search(x,n.right); } else{ max = Math.max(max, n.data); return search(x,n.left); } } public int getHeight(Node2 n){ if(n==null) return 0; height = 1+ Math.max(getHeight(n.left), getHeight(n.right)); return height; } } static long findDiff(long[] arr, long[] brr, int m){ int i = 0, j = 0; long fa = 1000000000000L; while(i=0){ if(x=y && x>=z) return x; if(y>=x && y>=z) return y; return z; } public static void seive(long n){ b = new boolean[(int) (n+1)]; Arrays.fill(b, true); for(int i = 2;i*i<=n;i++){ if(b[i]){ for(int p = 2*i;p<=n;p+=i){ b[p] = false; } } } } static long modInverse(long a, long mOD2){ return power(a, mOD2-2, mOD2); } static long power(long x, long y, long m) { if (y == 0) return 1; long p = power(x, y/2, m) % m; p = (p * p) % m; return (y%2 == 0)? p : (x * p) % m; } static long power2(long x,BigInteger y,long m){ long ans = 1; BigInteger two = new BigInteger("2"); while(y.compareTo(BigInteger.ZERO)>0){ if(y.getLowestSetBit()==y.bitCount()){ x = (x*x)%MOD; y = y.divide(two); } else{ ans = (ans*x)%MOD; y = y.subtract(BigInteger.ONE); } } return ans; } static BigInteger power2(BigInteger x, BigInteger y, BigInteger m){ BigInteger ans = new BigInteger("1"); BigInteger one = new BigInteger("1"); BigInteger two = new BigInteger("2"); BigInteger zero = new BigInteger("0"); while(y.compareTo(zero)>0){ //System.out.println(y); if(y.mod(two).equals(one)){ ans = ans.multiply(x).mod(m); y = y.subtract(one); } else{ x = x.multiply(x).mod(m); y = y.divide(two); } } return ans; } static BigInteger power(BigInteger x, BigInteger y, BigInteger m) { if (y.equals(0)) return (new BigInteger("1")); BigInteger p = power(x, y.divide(new BigInteger("2")), m).mod(m); p = (p.multiply(p)).mod(m); return (y.mod(new BigInteger("2")).equals(0))? p : (p.multiply(x)).mod(m); } static long d,x,y; public static void extendedEuclidian(long a, long b){ if(b == 0) { d = a; x = 1; y = 0; } else { extendedEuclidian(b, a%b); int temp = (int) x; x = y; y = temp - (a/b)*y; } } public static long gcd(long n, long m){ if(m!=0) return gcd(m,n%m); else return n; } public static class FasterScanner { private byte[] buf = new byte[1024]; private int curChar; private int numChars; public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = System.in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { return nextIntArray(n, 0); } public int[] nextIntArray(int n, int off) { int[] arr = new int[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextInt(); } return arr; } public long[] nextLongArray(int n) { return nextLongArray(n, 0); } public long[] nextLongArray(int n, int off) { long[] arr = new long[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }