```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 int
fmt.Fscan(reader, &n)
a := make([]int, n)
for i := 0; i < n; i++ {
fmt.Fscan(reader, &a[i])
}
ops := 0
for i := 1; i < n-1; i++ {
if a[i] > a[i-1] && a[i] > a[i+1] {
ops++
// Check if there is a local maximum at i+2
if i+2 < n-1 && a[i+2] > a[i+1] && a[i+2] > a[i+3] {
// We have a pattern like X (bad) Y (bad) Z
// Changing the middle element Y allows fixing both X and Z in 1 operation
val := a[i]
if a[i+2] > val {
val = a[i+2]
}
a[i+1] = val
// We fixed i and i+2, and i+1 is not a local max.
// Advancing i to skip unnecessary checks is not strictly required for correctness
// because the new value prevents i+2 from being detected as local max,
// but we can skip i+1 check naturally by loop increment.
} else {
// Only a[i] is a local maximum (or a[i+2] is not)
// Change right neighbor to fix a[i]
a[i+1] = a[i]
}
}
}
fmt.Fprintln(writer, ops)
for i := 0; i < n; i++ {
if i > 0 {
fmt.Fprint(writer, " ")
}
fmt.Fprint(writer, a[i])
}
fmt.Fprintln(writer)
}
}
```