← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var t int
	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {
		var n, k int64
		fmt.Fscan(reader, &n, &k)

		// Maximum Manhattan value for permutation of length n
		// If n is even: n/2 pairs, each pair (i, n+1-i) contributes 2*(n+1-2i) when swapped
		// Max value: swap pairs from outside in
		// For pair (i, n+1-i): contribution when swapped = 2*(n+1-2i)
		// Total max = 2*(n/2 * (n+1)/2) roughly
		
		// Let's compute max Manhattan value
		// Identity permutation has value 0
		// We can swap pairs: swap position i and position j (i < j)
		// This adds 2*(j-i) to the Manhattan value if both were at identity
		// Actually let's think differently
		
		// For n elements, maximum Manhattan value:
		// If n even: n/2 * (n/2) * 2 ... let me just compute
		// Swap pairs (1, n), (2, n-1), etc.
		// Each swap of positions i and n+1-i contributes 2*(n+1-2i)
		// For i=1: 2*(n-1), i=2: 2*(n-3), ...
		
		var maxVal int64
		if n%2 == 0 {
			maxVal = (n / 2) * (n / 2) * 2
		} else {
			maxVal = ((n - 1) / 2) * ((n + 1) / 2) * 2
		}

		// k must be even and <= maxVal
		if k > maxVal || k%2 != 0 {
			fmt.Fprintln(writer, "No")
			continue
		}

		fmt.Fprintln(writer, "Yes")

		// Build identity permutation
		p := make([]int64, n+1)
		for i := int64(1); i <= n; i++ {
			p[i] = i
		}

		// Greedily swap pairs from outside to reduce k to 0
		// Pair (l, r) where l=1,r=n, l=2,r=n-1, ...
		// Swapping l and r adds 2*(r-l)
		l := int64(1)
		r := n
		for k > 0 && l < r {
			gain := 2 * (r - l)
			if gain <= k {
				p[l], p[r] = p[r], p[l]
				k -= gain
				l++
				r--
			} else {
				// We need less than gain
				// Current gain is 2*(r-l)
				// We need k which is even and k < 2*(r-l)
				// Move r closer to l: swap l and r-k/2
				// Swap position l with position l + k/2
				newR := l + k/2
				p[l], p[newR] = p[newR], p[l]
				k = 0
			}
		}

		for i := int64(1); i <= n; i++ {
			if i > 1 {
				fmt.Fprint(writer, " ")
			}
			fmt.Fprint(writer, p[i])
		}
		fmt.Fprintln(writer)
	}
}
```