```go
package main
import (
"bufio"
"os"
"strconv"
)
func main() {
// Use buffered I/O for efficient reading and writing
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
// Helper function to read the next integer from input
nextInt := func() int {
scanner.Scan()
val, _ := strconv.Atoi(scanner.Text())
return val
}
// Read the number of test cases
if !scanner.Scan() {
return
}
t, _ := strconv.Atoi(scanner.Text())
for i := 0; i < t; i++ {
n := nextInt()
// To minimize the equal sum subarrays, we can cyclically shift the permutation p left by 1.
// q[i] = p[(i+1)%n].
// This means we print elements from index 1 to n-1, then index 0.
first := nextInt() // Read p[0]
// Read and print p[1] through p[n-1]
for j := 1; j < n; j++ {
val := nextInt()
writer.WriteString(strconv.Itoa(val))
writer.WriteByte(' ')
}
// Print p[0] at the end
writer.WriteString(strconv.Itoa(first))
writer.WriteByte('\n')
}
}
```