Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but that won't stop them.The game they came up with has the following rules. Initially, there are n stickers on the wall arranged in a row. Each sticker has some number written on it. Now they alternate turn, Petya moves first.One move happens as follows. Lets say there are m ≥ 2 stickers on the wall. The player, who makes the current move, picks some integer k from 2 to m and takes k leftmost stickers (removes them from the wall). After that he makes the new sticker, puts it to the left end of the row, and writes on it the new integer, equal to the sum of all stickers he took on this move. Game ends when there is only one sticker left on the wall. The score of the player is equal to the sum of integers written on all stickers he took during all his moves. The goal of each player is to maximize the difference between his score and the score of his opponent.Given the integer n and the initial sequence of stickers on the wall, define the result of the game, i.e. the difference between the Petya's and Gena's score if both players play optimally.

The first line of input contains a single integer n (2 ≤ n ≤ 200 000) — the number of stickers, initially located on the wall. The second line contains n integers a1, a2, ..., an ( - 10 000 ≤ ai ≤ 10 000) — the numbers on stickers in order from left to right.

Print one integer — the difference between the Petya's score and Gena's score at the end of the game if both players play optimally.

NoteIn the first sample, the optimal move for Petya is to take all the stickers. As a result, his score will be equal to 14 and Gena's score will be equal to 0.In the second sample, the optimal sequence of moves is the following. On the first move Petya will take first three sticker and will put the new sticker with value  - 8. On the second move Gena will take the remaining two stickers. The Petya's score is 1 + ( - 7) + ( - 2) =  - 8, Gena's score is ( - 8) + 3 =  - 5, i.e. the score difference will be  - 3.

package main

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

func solve() {
    n := readInt()
    a := readIntArray(n)
    s, dp := make([]int, n), make([]int, n)
    for i := range s {
        s[i] = a[i]
        if i > 0 {
            s[i] += s[i-1]
        }
    }
    maxDiff := s[n-1]
    for i := n-2; i >= 0; i-- {
        dp[i] = maxDiff
        if curDiff := s[i]-dp[i]; curDiff > maxDiff {
            maxDiff = curDiff
        }
    }
    fmt.Println(dp[0])
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// Math

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

// Sort

type Ints64 []int64

func (a Ints64) Len() int           { return len(a) }
func (a Ints64) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Ints64) Less(i, j int) bool { return a[i] < a[j] }

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var n int
	fmt.Fscanf(bufin, "%d\n", &n)

	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(bufin, "%d\n", &a[i])
	}

	sum := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		sum[i] = sum[i-1] + int64(a[i])
	}

	dp := make([]int64, n+1)
	dp[n] = 0

	best := sum[n]
	for i := n - 1; i >= 1; i-- {
		prev := sum[i+1] - dp[i+1]
		if best < prev {
			best = prev
		}
		dp[i] = best
	}

	fmt.Fprintf(bufout, "%d\n", dp[1])
}


There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights.    Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).

The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence.

Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them.

NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int64
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int64) {
	var k, m, min int64
	I(&k, "\n")
	ans := int64(1)
	arr := make([]int64, n+1)
	for i := int64(1); i <= n; i++ {
		o := " "
		if i == n {
			o = "\n"
		}
		I(&arr[i], o)
		if i <= k {
			m += arr[i]
			min = m
		} else {
			m += arr[i] - arr[i-k]
			if m < min {
				min = m
				ans = i - k + 1
			}
		}
	}
	O(ans, "\n")
}

package main
import (
	"fmt"
	//"sort"
	"bufio"
	"os"
	"strconv"
)
func main() {
	var n,k,hsl int
	fmt.Scan(&n,&k)
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	v:=make([]int,150005)
	for i:=1;i<=n;i++ {
		input.Scan()
		aa,_:= strconv.Atoi(input.Text())
		//fmt.Scan(&v[i])
		v[i]=aa
		v[i]+=v[i-1]
	}
	for j:=0;j<=n-k;j++ {
		if (v[hsl+k]-v[hsl])>(v[j+k]-v[j]) {
			hsl=j
		}
	}
	hsl++
	fmt.Println(hsl)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n,k int
    fmt.Scan(&n,&k)
    a, cnt := make([]int,n), 0
    for i := 0; i < k; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
        cnt += a[i]
    }
    ans, min := 1, cnt
    for i := k; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
        cnt = cnt-a[i-k]+a[i]
        if min > cnt { min = cnt; ans = i-k+2; }
    }
    fmt.Println(ans)
}

package main

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

func main() {
	var n, k int
	if _, err := fmt.Scanf("%d %d\n", &n, &k); err != nil {
		return
	}

	var last_k_height int = 0
	var min_k_height int = 0
	var min_k_index int = 1

	fences := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan(); i++ {
		h, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		fences[i] = h
		if i < k {
			last_k_height += fences[i]
			min_k_height += fences[i]
		} else {
			height := last_k_height - fences[i-k] + fences[i]
			last_k_height = height
			if height < min_k_height {
				min_k_height = height
				min_k_index = i - k + 2
			}
		}
	}

	fmt.Println(min_k_index)
}

package main

import (
	"fmt"
  "math"
)

const N = 200000

func main() {
  var n, k int
  fmt.Scan(&n, &k)
  var height [N]int
  for i := 0; i < n; i++ {
    fmt.Scan(&height[i])
  }

  sum, index, min_seq := 0, -1, math.MaxInt32
  for i := 0; i < n; i++ {
    sum += height[i]
    if i >= k {
      sum -= height[i - k]
    }
    if sum < min_seq && i >= k - 1 {
      min_seq, index = sum, i
    }
  }
  fmt.Println(index + 2 - k)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	defer writer.Flush()
	var n, k int
	scanf("%d %d\n", &n, &k)
	//printf("n=%d, k=%d\n", n, k)
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d", &a[i])
	}
	//fmt.Println(a)
	var dp = make([]int, n+1)
	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = dp[i-1] + a[i-1]
	}
	var ans int = 1e9
	var pos = -1
	for i := 1; i <= n-k+1; i++ {
		ans = min(ans, dp[i+k-1]-dp[i-1])
		if ans == dp[i+k-1]-dp[i-1] { // sum of elements from i to next consecutive k elements.
			pos = i
		}
	}
	printf("%d\n", pos)
}

package main

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

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	hn := make([]int, n, n)
	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		bs.Scan()
		hn[i], _ = strconv.Atoi(bs.Text())
	}

	cur := 0
	for j := 0; j < k; j++ {
		cur += hn[j]
	}

	sum, ans := cur, 1
	for i := 1; i <= n-k; i++ {
		cur -= hn[i-1]
		cur += hn[i+k-1]
		if cur < sum {
			sum = cur
			ans = i + 1
		}
	}

	fmt.Println(ans)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func readIntArray(line string) []int {

	numStrings := strings.Split(strings.TrimSpace(string(line)), " ")

	numbers := make([]int, 0)

	for _, v := range numStrings {
		var converted int

		fmt.Sscanf(v, "%d", &converted)
		numbers = append(numbers, converted)
	}

	return numbers
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	line, _ := Readln(reader)
	params := readIntArray(string(line))
	consItems := params[1]

	line, _ = Readln(reader)
	itemLengths := readIntArray(line)

	newLength := 0
	for j := 0; j < consItems; j++ {
		newLength += itemLengths[j]
	}
	res := 0
	minLength := math.MaxInt32
	for i := 1; i <= len(itemLengths)-consItems; i++ {

		if minLength > newLength {
			minLength = newLength
			res = i - 1
		}

		newLength += itemLengths[i+consItems-1]
		newLength -= itemLengths[i-1]
	}

	if minLength > newLength {
		if minLength != math.MaxInt32 {
			res++
		}
	}

	fmt.Println(res + 1)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	var n, k int
	fmt.Fscan(reader, &n, &k)

	dp := make([]int, n+1)
	dp[0] = 0

	for i := 1; i <= n; i++ {
		var x int
		fmt.Fscan(reader, &x)
		dp[i] += dp[i-1] + x
	}

	mx := math.MaxInt32
	var pos int
	for i := 1; i <= n-k+1; i++ {
		if mx > dp[i+k-1]-dp[i-1] {
			mx = dp[i+k-1] - dp[i-1]
			pos = i
		}
	}

	fmt.Println(pos)
}

// 363B-mic
package main

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

func main() {
    z := bufio.NewReader(os.Stdin)
    var n, k int
    var sum, num, a [200005]int
    fmt.Scan(&n, &k)
    for i := 0; i < n; i++ {
        sum[0] = 0
        for i := 1; i <= n; i++ {
            fmt.Fscan(z, &num[i])
            sum[i] = sum[i-1] + num[i]
        }
        for i := 1; i <= n-k+1; i++ {
            a[i] = sum[i+k-1] - sum[i-1]
        }
        id := 0
        var sma int64
        sma = 2000000000000
        for i := 1; i <= n-k+1; i++ {
            if sma > int64(a[i]) {
                id = i
                sma = int64(a[i])
            }
        }
        fmt.Println(id)
        return
    }
}

package main

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

func main() {
	var n, k int
	if _, err := fmt.Scanf("%d %d\n", &n, &k); err != nil {
		return
	}

	var min_k_height int64 = 0
	var min_k_index int = 1

	fences := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan(); i++ {
		h, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		fences[i] = h
		if i < k {
			min_k_height += int64(fences[i])
		} else {
			height := min_k_height - int64(fences[i-k]-fences[i])
			if height < min_k_height {
				min_k_height = height
				min_k_index = i - k + 2
			}
		}
	}

	fmt.Println(min_k_index)
}

package main

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

func main() {
	var n, k int
	if _, err := fmt.Scanf("%d %d\n", &n, &k); err != nil {
		return
	}

	var min_k_height int = 0
	var min_k_index int = 1

	fences := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan(); i++ {
		h, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		fences[i] = h
		if i < k {
			min_k_height += fences[i]
		} else {
			height := min_k_height - fences[i-k] + fences[i]
			if height < min_k_height {
				min_k_height = height
				min_k_index = i - k + 2
			}
		}
	}

	fmt.Println(min_k_index)
}

package main

import (
	"fmt"
  "math"
)

const N = 200000

func main() {
  var n, k int
  fmt.Scan(&n, &k)
  fmt.Println(n, k)
  var height [N]int
  for i := 0; i < n; i++ {
    fmt.Scan(&height[i])
  }

  sum, index, min_seq := 0, -1, math.MaxInt32
  for i := 0; i < n; i++ {
    sum += height[i]
    if i >= k {
      sum -= height[i - k]
    }
    if sum < min_seq && i >= k - 1 {
      min_seq, index = sum, i
    }
  }
  fmt.Println(index + 2 - k)
}

package main

import (
	"fmt"
  "math"
)

const N = 200000

func main() {
  var n, k int
  fmt.Scan(&n, &k)
  fmt.Println(n, k)
  var height [N]int
  for i := 0; i < n; i++ {
    fmt.Scan(&height[i])
  }

  sum, index, min_seq := 0, -1, math.MaxInt32
  for i := 0; i < n; i++ {
    sum += height[i]
    if i >= k {
      sum -= height[i - k]
    }
    if sum < min_seq && i >= k - 1 {
      min_seq, index = sum, i
      fmt.Println(sum, i)
    }
  }
  fmt.Println(index + 2 - k)
}

package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, k int
	_, err := fmt.Scanf("%d %d", &n, &k)
	if err != nil {
		// do something
	}
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d", &a[i])
		if err != nil {

		}
	}
	var dp = make([]int, n+1)
	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = dp[i-1] + a[i-1]
	}
	var ans int = 1e9
	var pos int
	for i := 1; i <= n-k+1; i++ {
		ans = min(ans, dp[i+k-1]-dp[i-1])
		if ans == dp[i+k-1]-dp[i-1] {
			pos = i
		}
	}
	fmt.Println(pos)
}

package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, k int
	_, err := fmt.Scanf("%d", &n)
	_, err = fmt.Scanf("%d", &k)
	if err != nil {
		// do something
	}
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d", &a[i])
		if err != nil {

		}
	}
	fmt.Println(a)
	var dp = make([]int, n+1)
	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = dp[i-1] + a[i-1]
	}
	var ans int = 1e9
	var pos = -1
	for i := 1; i <= n-k+1; i++ {
		ans = min(ans, dp[i+k-1]-dp[i-1])
		if ans == dp[i+k-1]-dp[i-1] { // sum of elements from i to next consecutive k elements.
			pos = i
			fmt.Println(dp[i+k-1] - dp[i-1])
		}
	}
	fmt.Println(pos)
}

package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, k int
	_, err := fmt.Scanf("%d %d", &n, &k)
	if err != nil {
		// do something
	}
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d", &a[i])
		if err != nil {

		}
	}
	fmt.Println(a)
	var dp = make([]int, n+1)
	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = dp[i-1] + a[i-1]
	}
	var ans int = 1e9
	var pos = -1
	for i := 1; i <= n-k+1; i++ {
		ans = min(ans, dp[i+k-1]-dp[i-1])
		if ans == dp[i+k-1]-dp[i-1] { // sum of elements from i to next consecutive k elements.
			pos = i
			fmt.Println(dp[i+k-1] - dp[i-1])
		}
	}
	fmt.Println(pos)
}

package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, k int
	_, err := fmt.Scanf("%d %d", &n, &k)
	if err != nil {
		// do something
	}
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d", &a[i])
		if err != nil {

		}
	}
	var dp = make([]int, n+1)
	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = dp[i-1] + a[i-1]
	}
	var ans int = 1e9
	var pos = -1
	for i := 1; i <= n-k+1; i++ {
		ans = min(ans, dp[i+k-1]-dp[i-1])
		if ans == dp[i+k-1]-dp[i-1] { // sum of elements from i to next consecutive k elements.
			pos = i
		}
	}
	fmt.Println(pos)
}

package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, k int
	_, err := fmt.Scanf("%d %d", &n, &k)
	if err != nil {
		// do something
	}
	fmt.Println(n, k)
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scan("%d", &a[i])
		if err != nil {

		}
	}
	fmt.Println(a)
	var dp = make([]int, n+1)
	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = dp[i-1] + a[i-1]
	}
	var ans int = 1e9
	var pos = -1
	for i := 1; i <= n-k+1; i++ {
		ans = min(ans, dp[i+k-1]-dp[i-1])
		if ans == dp[i+k-1]-dp[i-1] { // sum of elements from i to next consecutive k elements.
			pos = i
			fmt.Println(dp[i+k-1] - dp[i-1])
		}
	}
	fmt.Println(pos)
}

package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, k int
	_, err := fmt.Scanf("%d %d", &n, &k)
	if err != nil {
		// do something
	}
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d", &a[i])
		if err != nil {

		}
	}
	var dp = make([]int, n+1)
	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = dp[i-1] + a[i-1]
	}
	var ans int = 1e9
	var pos int
	for i := 1; i <= n-k+1; i++ {
		ans = min(ans, dp[i+k-1]-dp[i-1])
		if ans == dp[i+k-1]-dp[i-1] { // sum of elements from i to next consecutive k elements.
			pos = i
		}
	}
	fmt.Println(pos)
}

package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, k int
	_, err := fmt.Scanf("%d %d", &n, &k)
	if err != nil {
		// do something
	}
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d", &a[i])
		if err != nil {

		}
	}
	var dp = make([]int, n+1)
	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = dp[i-1] + a[i-1]
	}
	var ans int = 1e9
	var pos = -1
	for i := 1; i <= n-k+1; i++ {
		ans = min(ans, dp[i+k-1]-dp[i-1])
		if ans == dp[i+k-1]-dp[i-1] { // sum of elements from i to next consecutive k elements.
			pos = i
			fmt.Println(dp[i+k-1] - dp[i-1])
		}
	}
	fmt.Println(pos)
}

package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, k int
	_, err := fmt.Scanf("%d %d", &n, &k)
	if err != nil {
		// do something
	}
	fmt.Println(n, k)
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d", &a[i])
		if err != nil {

		}
	}
	fmt.Println(a)
	var dp = make([]int, n+1)
	dp[0] = 0
	for i := 1; i <= n; i++ {
		dp[i] = dp[i-1] + a[i-1]
	}
	var ans int = 1e9
	var pos = -1
	for i := 1; i <= n-k+1; i++ {
		ans = min(ans, dp[i+k-1]-dp[i-1])
		if ans == dp[i+k-1]-dp[i-1] { // sum of elements from i to next consecutive k elements.
			pos = i
			fmt.Println(dp[i+k-1] - dp[i-1])
		}
	}
	fmt.Println(pos)
}

package main

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

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	hn := make([]int, n, n)
	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		bs.Scan()
		hn[i], _ = strconv.Atoi(bs.Text())
	}

	cur := 0
	for j := 0; j < k; j++ {
		cur += hn[j]
	}

	sum, ans := cur, 0
	for i := 1; i <= n-k; i++ {
		cur -= hn[i-1]
		cur += hn[i+k-1]
		if cur < sum {
			sum = cur
			ans = i + 1
		}
	}

	fmt.Println(ans)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func readIntArray(line string) []int {

	numStrings := strings.Split(strings.TrimSpace(string(line)), " ")

	numbers := make([]int, 0)

	for _, v := range numStrings {
		var converted int

		fmt.Sscanf(v, "%d", &converted)
		numbers = append(numbers, converted)
	}

	return numbers
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	line, _ := Readln(reader)
	params := readIntArray(string(line))
	consItems := params[1]

	line, _ = Readln(reader)
	itemLengths := readIntArray(line)

	newLength := 0
	for j := 0; j < consItems; j++ {
		newLength += itemLengths[j]
	}
	res := 0
	minLength := math.MaxInt32
	for i := 1; i < len(itemLengths)-consItems; i++ {

		if minLength > newLength {
			minLength = newLength
			res = i - 1
		}

		newLength += itemLengths[i+consItems-1]
		newLength -= itemLengths[i-1]
	}

	fmt.Println(res + 1)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func readIntArray(line string) []int {

	numStrings := strings.Split(strings.TrimSpace(string(line)), " ")

	numbers := make([]int, 0)

	for _, v := range numStrings {
		var converted int

		fmt.Sscanf(v, "%d", &converted)
		numbers = append(numbers, converted)
	}

	return numbers
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	line, _ := Readln(reader)
	params := readIntArray(string(line))
	consItems := params[1]

	line, _ = Readln(reader)
	itemLengths := readIntArray(line)

	newLength := 0
	for j := 0; j < consItems; j++ {
		newLength += itemLengths[j]
	}
	res := 0
	minLength := math.MaxInt32
	for i := consItems; i < len(itemLengths)-consItems; i++ {

		if minLength > newLength {
			minLength = newLength
			res = i - 1
		}

		newLength += itemLengths[i]
		newLength -= itemLengths[i-1]
	}

	fmt.Println(res + 1)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func readIntArray(line string) []int {

	numStrings := strings.Split(strings.TrimSpace(string(line)), " ")

	numbers := make([]int, 0)

	for _, v := range numStrings {
		var converted int

		fmt.Sscanf(v, "%d", &converted)
		numbers = append(numbers, converted)
	}

	return numbers
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	line, _ := Readln(reader)
	params := readIntArray(string(line))
	consItems := params[1]

	line, _ = Readln(reader)
	itemLengths := readIntArray(line)

	newLength := 0
	for j := 0; j < consItems; j++ {
		newLength += itemLengths[j]
	}
	res := 0
	minLength := math.MaxInt32
	for i := 1; i <= len(itemLengths)-consItems; i++ {

		if minLength > newLength {
			minLength = newLength
			res = i - 1
		}

		newLength += itemLengths[i+consItems-1]
		newLength -= itemLengths[i-1]
	}

	if minLength > newLength {
		res++
	}

	fmt.Println(res + 1)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func readIntArray(line string) []int {

	numStrings := strings.Split(strings.TrimSpace(string(line)), " ")

	numbers := make([]int, 0)

	for _, v := range numStrings {
		var converted int

		fmt.Sscanf(v, "%d", &converted)
		numbers = append(numbers, converted)
	}

	return numbers
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	line, _ := Readln(reader)
	params := readIntArray(string(line))
	consItems := params[1]

	line, _ = Readln(reader)
	itemLengths := readIntArray(line)

	newLength := 0
	for j := 0; j < consItems; j++ {
		newLength += itemLengths[j]
	}
	res := 0
	minLength := math.MaxInt32
	for i := 1; i < len(itemLengths)-consItems; i++ {

		if minLength > newLength {
			minLength = newLength
			res = i
		}

		newLength += itemLengths[i]
		newLength -= itemLengths[i-1]
	}

	fmt.Println(res + 1)
}

// 363B-mic
package main

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

func main() {
    z := bufio.NewReader(os.Stdin)
    var n, k int
    var sum, num, a [200005]int
    fmt.Scan(&n, &k)
    for i := 0; i < n; i++ {
        sum[0] = 0
        for i := 1; i <= n; i++ {
            fmt.Fscan(z, &num[i])
            sum[i] = sum[i-1] + num[i]
        }
        for i := 1; i <= n-k+1; i++ {
            a[i] = sum[i+k-1] - sum[i-1]
        }
        id := 0
        sma := 2000000
        for i := 1; i <= n-k+1; i++ {
            if sma > a[i] {
                id = i
                sma = a[i]
            }
        }
        fmt.Println(id)
        return
    }
}

// 363B-mic
package main

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

func main() {
    z := bufio.NewReader(os.Stdin)
    var n, k int
    var sum, num, a [200005]int
    fmt.Scan(&n, &k)
    for i := 0; i < n; i++ {
        sum[0] = 0
        for i := 1; i <= n; i++ {
            fmt.Fscan(z, &num[i])
            sum[i] = sum[i-1] + num[i]
        }
        for i := 1; i <= n-k+1; i++ {
            a[i] = sum[i+k-1] - sum[i-1]
        }
        id := 0
        sma := 2000000
        for i := 1; i <= n-k+1; i++ {
            if sma > a[i] {
                id = i
                sma = a[i]
            }
        }
        fmt.Println(id)
    }
    return
}


Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The right shift is forbidden if it cuts off some ones. So, in fact, in one operation, you can multiply or divide your number by $$$2$$$, $$$4$$$ or $$$8$$$, and division is only allowed if the number is divisible by the chosen divisor. Formally, if the register contains a positive integer $$$x$$$, in one operation it can be replaced by one of the following:   $$$x \cdot 2$$$  $$$x \cdot 4$$$  $$$x \cdot 8$$$  $$$x / 2$$$, if $$$x$$$ is divisible by $$$2$$$  $$$x / 4$$$, if $$$x$$$ is divisible by $$$4$$$  $$$x / 8$$$, if $$$x$$$ is divisible by $$$8$$$ For example, if $$$x = 6$$$, in one operation it can be replaced by $$$12$$$, $$$24$$$, $$$48$$$ or $$$3$$$. Value $$$6$$$ isn't divisible by $$$4$$$ or $$$8$$$, so there're only four variants of replacement.Now Johnny wonders how many operations he needs to perform if he puts $$$a$$$ in the register and wants to get $$$b$$$ at the end.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The following $$$t$$$ lines contain a description of test cases. The first and only line in each test case contains integers $$$a$$$ and $$$b$$$ ($$$1 \leq a, b \leq 10^{18}$$$) — the initial and target value of the variable, respectively.

Output $$$t$$$ lines, each line should contain one integer denoting the minimum number of operations Johnny needs to perform. If Johnny cannot get $$$b$$$ at the end, then write $$$-1$$$.

NoteIn the first test case, Johnny can reach $$$5$$$ from $$$10$$$ by using the shift to the right by one (i.e. divide by $$$2$$$).In the second test case, Johnny can reach $$$44$$$ from $$$11$$$ by using the shift to the left by two (i.e. multiply by $$$4$$$).In the third test case, it is impossible for Johnny to reach $$$21$$$ from $$$17$$$.In the fourth test case, initial and target values are equal, so Johnny has to do $$$0$$$ operations.In the fifth test case, Johnny can reach $$$3$$$ from $$$96$$$ by using two shifts to the right: one by $$$2$$$, and another by $$$3$$$ (i.e. divide by $$$4$$$ and by $$$8$$$).

package main

import "fmt"

func main() {
	var test_case int
	fmt.Scan(&test_case)

	for t := 0; t < test_case; t++ {
		cnt := 0
		var n, m int64
		fmt.Scan(&n, &m)

		if n > m {
			for n > m {
				if n % 8 == 0 && n/8 >= m {
					n /= 8
					cnt++
				} else if n % 4 == 0 && n/4 >= m {
					n /= 4
					cnt++
				} else if n % 2 == 0 && n/2 >= m {
					n /= 2
					cnt++
				} else {
					break
				}
			}
		} else {
			for n < m {
				if n*8 <= m {
					n *= 8
					cnt++
				} else if n*4 <= m {
					n *= 4
					cnt++
				} else if n*2 <= m {
					n *= 2
					cnt++
				} else {
					break
				}
			}
		}

		if n == m {
			fmt.Println(cnt)
		} else {
			fmt.Println("-1")
		}
	}
}

package main

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

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		var a, b uint64
		s, _ := reader.ReadBytes('\n')
		pos := readUint64(s, 0, &a)
		readUint64(s, pos+1, &b)
		fmt.Println(solve(a, b))
	}
}

func solve(a, b uint64) int {
	if a == 0 {
		if b == 0 {
			return 0
		}
		return -1
	}

	if b == 0 {
		return -1
	}

	x, y := a, b
	var d int
	for x&1 != 1 {
		x >>= 1
		d--
	}
	for y&1 != 1 {
		y >>= 1
		d++
	}

	if x != y {
		return -1
	}
	if d < 0 {
		d = -d
	}
	res := d / 3
	d %= 3
	res += d / 2
	d %= 2
	res += d
	return res
}

package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var a, b int64
	fmt.Fscan(input, &a, &b)
	if a < b {
		a, b = b, a
	}

	c1, c2 := 0, 0
	for a > b {

		if a % 2 == 0 {
			c1++
			a >>= 1
		} else {
			c2++
			b <<= 1
		}
	}

	if a != b {
		fmt.Println(-1)
	} else {
		ans := c1 / 3
		c1 %= 3
		ans += c1 / 2
		c1 %= 2
		ans += c1
		ans += c2 / 3
		c2 %= 3
		ans += c2 / 2
		c2 %= 2
		ans += c2
		fmt.Println(ans)
	}
}

package main

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

func main() {
	var t = nextInt()
	for i := int64(0); i < t; i++ {
		var a, b int64
		a = nextInt()
		b = nextInt()
		fmt.Println(solve(a, b))
	}
}

func solve(a, b int64) int64 {
	if a > b {
		a, b = b, a
	}
	if b%a != 0 {
		return -1
	}

	div := b / a
	if div == 1 {
		return 0
	}

	var c int64
	for div&1 == 0 {
		c++
		div /= 2
	}
	if div>>1 > 0 {
		return -1
	}

	var ans int64
	ans += c / 3
	c = c % 3
	ans += c / 2
	c = c % 2
	ans += c
	return ans
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

/*
URL:
https://codeforces.com/contest/1362/problem/A
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	a, b int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		a, b = ReadInt64_2()

		solve()
	}
}

func solve() {
	if a == b {
		fmt.Println(0)
		return
	} else if a < b {
		if b%a != 0 {
			fmt.Println(-1)
			return
		}

		q := b / a

		var e int64
		e = -1
		for i := 0; i <= 60; i++ {
			var beki int64
			beki = 1 << uint(i)
			if q == beki {
				e = int64(i)
				break
			}
		}

		if e == -1 {
			fmt.Println(-1)
			return
		}

		num := int64(0)
		num += e / 3
		e %= 3
		num += e / 2
		e %= 2
		num += e
		fmt.Println(num)
	} else {
		if a%b != 0 {
			fmt.Println(-1)
			return
		}

		q := a / b

		var e int64
		e = -1
		for i := 0; i <= 60; i++ {
			var beki int64
			beki = 1 << uint(i)
			if q == beki {
				e = int64(i)
				break
			}
		}

		if e == -1 {
			fmt.Println(-1)
			return
		}

		num := int64(0)
		num += e / 3
		e %= 3
		num += e / 2
		e %= 2
		num += e
		fmt.Println(num)
	}
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*
URL:
https://codeforces.com/contest/1362/problem/A
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	a, b int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		a, b = ReadInt64_2()

		solve()
	}
}

func solve() {
	if a == b {
		fmt.Println(0)
		return
	} else if a < b {
		if b%a != 0 {
			fmt.Println(-1)
			return
		}

		q := b / a

		var e int64
		e = -1
		for i := 0; i <= 60; i++ {
			var beki int64
			beki = 1 << uint(i)
			if q == beki {
				e = int64(i)
				break
			}
		}

		num := int64(0)
		num += e / 3
		e %= 3
		num += e / 2
		e %= 2
		num += e
		fmt.Println(num)
	} else {
		if a%b != 0 {
			fmt.Println(-1)
			return
		}

		q := a / b

		var e int64
		e = -1
		for i := 0; i <= 60; i++ {
			var beki int64
			beki = 1 << uint(i)
			if q == beki {
				e = int64(i)
				break
			}
		}

		num := int64(0)
		num += e / 3
		e %= 3
		num += e / 2
		e %= 2
		num += e
		fmt.Println(num)
	}
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import "fmt"

var nTest int
var a, b int64

func main() {
	fmt.Scanf("%d\n", &nTest)

	for i := 0; i < nTest; i++ {
		fmt.Scanf("%d %d\n", &a, &b)

		nOperation := 0
		if a > b {
			a, b = b, a
		}

		for a < b {
			if a*8 <= b {
				a *= 8
			} else if a*4 <= b {
				a *= 4
			} else if a*2 <= b {
				a *= 2
			} else {
				nOperation = -1
				break
			}
			nOperation++
		}

		fmt.Println(nOperation)
	}
}

package main

import "fmt"

var nTest int
var a, b int64

func main() {
	fmt.Scanf("%d\n", &nTest)

	for i := 0; i < nTest; i++ {
		fmt.Scanf("%d %d\n", &a, &b)

		nOperation := 0
		if a > b {
			a, b = b, a
		}

		for a < b {
			if a*8 <= b {
				a *= 8
			} else if a*4 <= b {
				a *= 4
			} else if a*2 <= b {
				a *= 2
			} else {
				nOperation = -1
				break
			}
			nOperation++
		}

		if a != b {
			fmt.Println(-1)
			continue
		}
		fmt.Println(nOperation)
	}
}

package main

import "fmt"

func main() {
	var test, a, b int64
	var count int64
	var i int64

	fmt.Scanln(&test)

	for i = 0; i < test; i++ {
		fmt.Scanf("%d%d\n", &a, &b)
		count = 0
		for a != b {
			if b > a {
				if a*8 <= b {
					a = a*8
					count++
				} else if a*4 <= b {
					a = a*4
					count++
				} else if a*2 <= b {
					a = a*2
					count++
				} else {
					count = -1
					break
				}
			}
			if a > b {
				if a%8 == 0 && a/8 >= b {
					a = a/8
					count++
				} else if a%4 == 0 && a/4 >= b {
					a = a/4
					count++
				} else if a%2 == 0 && a/2 >= b {
					a = a/2
					count++
				} else {
					count = -1
					break
				}
			}
		}
		fmt.Println(count)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	defer out.Flush()
	for t := ScanInt(); t > 0; t-- {
		a, b := ScanInt64(), ScanInt64()
		P(solve(a, b))
	}
}

func solve(a, b int64) int {
	lastOneA, aStripped := lastOne(a)
	lastOneB, bStripped := lastOne(b)

	if aStripped != bStripped {
		return -1
	}

	dif := Abs(lastOneA - lastOneB)
	terms := dif / 3
	if dif%3 != 0 {
		terms++
	}
	return terms
}

func lastOne(x int64) (int, int64) {
	i := 0
	for x&1 == 0 {
		i++
		x = x >> 1
	}
	return i, x
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt64()
	}
	return a
}

/*********************** Utils int64 ***********************/
func MnMx64(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn64(args ...int64) int64 { mn, _ := MnMx64(args...); return mn }
func Mx64(args ...int64) int64 { _, mx := MnMx64(args...); return mx }
func LCM64(a, b int64) int64   { return a / GCD64(a, b) * b }
func GCD64(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD64(b%a, a)
}
func SortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func Abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

/*********************** Utils int ***********************/
func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func min(a, b int64) int64 {
	return int64(math.Min(float64(a), float64(b)))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%v\n", &t)
	for now := 0; now < t;now++{
		var a, b int64
		fmt.Fscanf(in, "%v %v\n", &a, &b)
		if a == b {
			fmt.Fprintln(out, 0)
			continue
		}
		if a > b {
			ans := 0
			for a > b{
				ans++
				if a % 2 != 0 {
					break
				}
				a /= 2
			}
			if a == b{
				fmt.Fprintln(out, int64((ans) / 3) + min(int64(ans % 3), int64(1)))
			} else {
				fmt.Fprintln(out, -1)
			}
		} else{
			a, b = b, a
			ans := 0
			for a > b{
				ans++
				if a % 2 != 0 {
					break
				}
				a /= 2
			}
			if a == b{
				fmt.Fprintln(out, int64((ans) / 3) + min(int64(ans % 3), int64(1)))
			} else {
				fmt.Fprintln(out, -1)
			}
		}

	}
	return
}

package main

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

func div(v int64) {
    var cnt int64 = 0
    for ; v > 1; {
        if v % 8 == 0 {
            v /= 8
            cnt++
        } else if v % 4 == 0 {
            v /= 4
            cnt++
        } else if v % 2 == 0 {
            v /= 2
            cnt++
        } else {
            cnt = -1
            break
        }
    }
    fmt.Println(cnt)
}
func main(){
    var t int
    var a, b int64

    in := bufio.NewReader(os.Stdin)
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        fmt.Fscan(in, &a, &b)
        if a == b {
            fmt.Println(0)
            continue
        } else if a > b {
            if a % b != 0 {
                fmt.Println(-1)
            } else {
                div(a/b)
            }
        } else {
            if b % a != 0 {
                fmt.Println(-1)
            } else {
                div(b/a)
            }
        }
    }
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
)

var (
	inn = bufio.NewScanner(os.Stdin)
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func main() {
	defer out.Flush()
	inn.Buffer([]byte{}, 10000000)
	inn.Split(bufio.ScanWords)

	for tt := rd(); tt > 0; tt-- {
		a, b := rdll(), rdll()
		cnt := 0
		if a < b {
			for a*8 <= b {
				a *= 8
				cnt++
			}
			for a*4 <= b {
				a *= 4
				cnt++
			}
			for a*2 <= b {
				a *= 2
				cnt++
			}
			if a != b {
				cnt = -1
			}
		} else {
			for a%8 == 0 && a/8 >= b {
				a /= 8
				cnt++
			}
			for a%4 == 0 && a/4 >= b {
				a /= 4
				cnt++
			}
			for a%2 == 0 && a/2 >= b {
				a /= 2
				cnt++
			}
			if a != b {
				cnt = -1
			}
		}
		Fprintln(out, cnt)

	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.Atoi(string(data))
	return x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.ParseInt(string(data), 10, 64)
	return x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}

package main

import (
  "fmt"
)

func main() {
  var t int
  var a, b int64

  fmt.Scan(&t)
  for ;t > 0; t-- {
    ans := 0
    fmt.Scan(&a, &b)
    for a * 8 <= b {
      a *= 8
      ans++
    }
    for a * 4 <= b {
      a *= 4
      ans++
    }
    for a * 2 <= b {
      a *= 2
      ans++
    }
   for a % 8 == 0 && a / 8 >= b {
      a /= 8
      ans++
    }
   for a % 4== 0 && a / 4 >= b {
      a /= 4
      ans++
    }
   for a % 2 == 0 && a / 2 >= b {
      a /= 2
      ans++
    }
    if a != b {
        ans = -1
    }
    fmt.Println(ans)
  }
}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

func fastGetInt64(b []byte) int64 {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	n = 0
	for _, v := range b {
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(a int64, b int64) {
	count := 0
	if a == b {
		count = 0
	} else if a%2 == 1 && b%2 == 1 {
		count = -1
	} else if a > b {
		for a > b {
			if a%8 == 0 && a/8 >= b {
				a /= 8
				count++
			} else if a%4 == 0 && a/4 >= b {
				a /= 4
				count++
			} else if a%2 == 0 && a/2 >= b {
				a /= 2
				count++
			} else if count == 0 {
				count = -1
				break
			} else {
				break
			}
		}
	} else {
		for a < b {
			if a*8 <= b {
				a *= 8
				count++
			} else if a*4 <= b {
				a *= 4
				count++
			} else if a*2 <= b {
				a *= 2
				count++
			} else if count == 0 {
				count = -1
				break
			} else {
				break
			}
		}
	}
	if a != b {
		count = -1
	}
	fmt.Println(count)
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var num int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	num = fastGetInt(scanner.Bytes())
	for x := 0; x < num; x++ {
		scanner.Scan()
		a := fastGetInt64(scanner.Bytes())
		scanner.Scan()
		b := fastGetInt64(scanner.Bytes())

		solution(a, b)
	}
	//======================================================

	//==================== OUTPUT ==========================

}

package main

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

func main() {
	var t = nextInt()
	for i := 0; i < t; i++ {
		var a, b int
		a = nextInt()
		b = nextInt()
		fmt.Println(solve(a, b))
	}
}

func solve(a, b int) int {
	if a > b {
		a, b = b, a
	}
	if b%a != 0 {
		return -1
	}

	div := b / a
	if div == 1 {
		return 0
	}

	c := 0
	for div&1 == 0 {
		c++
		div /= 2
	}
	if div>>1 > 0 {
		return -1
	}

	ans := 0
	ans += c / 3
	c = c % 3
	ans += c / 2
	c = c % 2
	ans += c
	return ans
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

package main

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

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		fmt.Println(solve(nextInt(), nextInt()))
	}
}

func solve(a, b int) int {
	if a > b {
		a, b = b, a
	}
	if b%a != 0 {
		return -1
	}

	div := b / a
	if div == 1 {
		return 0
	}

	c := 0
	for div&1 == 0 {
		c++
		div /= 2
	}
	if div>>1 > 0 {
		return -1
	}

	ans := 0
	ans += c / 3
	c = c % 3
	ans += c / 2
	c = c % 2
	ans += c
	return ans
}

func max(xs ...int) int {
	ret := xs[0]
	for _, x := range xs[1:] {
		if ret < x {
			ret = x
		}
	}
	return ret
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

package main

import "fmt"

var nTest, a, b int

func main() {
	fmt.Scanf("%d\n", &nTest)

	for i := 0; i < nTest; i++ {
		fmt.Scanf("%d %d\n", &a, &b)

		nOperation := 0
		if a > b {
			a, b = b, a
		}

		for a < b {
			if a*8 <= b {
				a *= 8
			} else if a*4 <= b {
				a *= 4
			} else if a*2 <= b {
				a *= 2
			} else {
				nOperation = -1
				break
			}
			nOperation++
		}

		if a != b {
			fmt.Println(-1)
			continue
		}
		fmt.Println(nOperation)
	}
}

package main

import "fmt"

func main() {
	var test, a, b int64
	var count int64
	var i int64

	fmt.Scanln(&test)

	for i = 0; i < test; i++ {
		fmt.Scanf("%d%d\n", &a, &b)
		count = 0
		for a != b {
			if b > a {
				if a*8 <= b {
					a = a*8
					count++
				} else if a*4 <= b {
					a = a*4
					count++
				} else if a*2 <= b {
					a = a*2
					count++
				} else {
					count = -1
					break
				}
			}
			if a > b {
				if a%8 == 0 {
					a = a/8
					count++
				} else if a%4 == 0 {
					a = a/4
					count++
				} else if a%2 == 0 {
					a = a/2
					count++
				} else {
					count = -1
					break
				}
			}
		}
		fmt.Println(count)
	}
}

package main

import "fmt"

func main() {
	var test, a, b int
	var count int

	fmt.Scanln(&test)

	for i := 0; i < test; i++ {
		fmt.Scanf("%d%d\n", &a, &b)
		count = 0
		for a != b {
			if b > a {
				if a*8 <= b {
					a = a*8
					count++
				} else if a*4 <= b {
					a = a*4
					count++
				} else if a*2 <= b {
					a = a*2
					count++
				} else {
					count = -1
					break
				}
			}
			if a > b {
				if a%8 == 0 {
					a = a/8
					count++
				} else if a%4 == 0 {
					a = a/4
					count++
				} else if a%2 == 0 {
					a = a/2
					count++
				} else {
					count = -1
					break
				}
			}
		}
		fmt.Println(count)
	}
}

package main

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

func min(a, b int64) int64 {
	return int64(math.Min(float64(a), float64(b)))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%v\n", &t)
	for now := 0; now < t;now++{
		var a, b int64
		fmt.Fscanf(in, "%v %v\n", &a, &b)
		if a == b {
			fmt.Fprintln(out, 0)
			continue
		}
		if a > b {
			ans := 0
			for a >= b{
				ans++
				a /= 2
			}
			if a != b{
				fmt.Fprintln(out, int64((ans) / 3) + min(int64(ans % 3), int64(1)))
			} else {
				fmt.Fprintln(out, -1)
			}
		} else{
			a, b = b, a
			ans := 0
			for a >= b{
				ans++
				a /= 2
			}
			if a != b{
				fmt.Fprintln(out, int64((ans) / 3) + min(int64(ans % 3), int64(1)))
			} else {
				fmt.Fprintln(out, -1)
			}
		}

	}
	return
}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

func fastGetInt64(b []byte) int64 {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	n = 0
	for _, v := range b {
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(a int64, b int64) {
	count := 0
	if a == b {
		count = 0
	} else if a > b {
		for a > b {
			if a%8 == 0 && a/8 >= b {
				a /= 8
				count++
			} else if a%4 == 0 && a/4 >= b {
				a /= 4
				count++
			} else if a%2 == 0 && a/2 >= b {
				a /= 2
				count++
			} else if count == 0 {
				count = -1
				break
			} else {
				break
			}
		}
	} else {
		for a < b {
			if a*8 <= b {
				a *= 8
				count++
			} else if a*4 <= b {
				a *= 4
				count++
			} else if a*2 <= b {
				a *= 2
				count++
			} else if count == 0 {
				count = -1
				break
			} else {
				break
			}
		}
	}
	fmt.Println(count)
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var num int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	num = fastGetInt(scanner.Bytes())
	for x := 0; x < num; x++ {
		scanner.Scan()
		a := fastGetInt64(scanner.Bytes())
		scanner.Scan()
		b := fastGetInt64(scanner.Bytes())

		solution(a, b)
	}
	//======================================================

	//==================== OUTPUT ==========================

}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

func fastGetInt64(b []byte) int64 {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	n = 0
	for _, v := range b {
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(a int64, b int64) {
	count := 0
	if a == b {
		count = 0
	} else if a%2 == 1 && b%2 == 1 {
		count = -1
	} else if a > b {
		for a > b {
			if a%8 == 0 && a/8 >= b {
				a /= 8
				count++
			} else if a%4 == 0 && a/4 >= b {
				a /= 4
				count++
			} else if a%2 == 0 && a/2 >= b {
				a /= 2
				count++
			} else if count == 0 {
				count = -1
				break
			} else {
				break
			}
		}
	} else {
		for a < b {
			if a*8 <= b {
				a *= 8
				count++
			} else if a*4 <= b {
				a *= 4
				count++
			} else if a*2 <= b {
				a *= 2
				count++
			} else if count == 0 {
				count = -1
				break
			} else {
				break
			}
		}
	}
	fmt.Println(count)
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var num int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	num = fastGetInt(scanner.Bytes())
	for x := 0; x < num; x++ {
		scanner.Scan()
		a := fastGetInt64(scanner.Bytes())
		scanner.Scan()
		b := fastGetInt64(scanner.Bytes())

		solution(a, b)
	}
	//======================================================

	//==================== OUTPUT ==========================

}


Artem is building a new robot. He has a matrix $$$a$$$ consisting of $$$n$$$ rows and $$$m$$$ columns. The cell located on the $$$i$$$-th row from the top and the $$$j$$$-th column from the left has a value $$$a_{i,j}$$$ written in it. If two adjacent cells contain the same value, the robot will break. A matrix is called good if no two adjacent cells contain the same value, where two cells are called adjacent if they share a side. Artem wants to increment the values in some cells by one to make $$$a$$$ good.More formally, find a good matrix $$$b$$$ that satisfies the following condition —   For all valid ($$$i,j$$$), either $$$b_{i,j} = a_{i,j}$$$ or $$$b_{i,j} = a_{i,j}+1$$$. For the constraints of this problem, it can be shown that such a matrix $$$b$$$ always exists. If there are several such tables, you can output any of them. Please note that you do not have to minimize the number of increments.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n, m$$$ ($$$1 \le n \le 100$$$, $$$1 \le m \le 100$$$)  — the number of rows and columns, respectively. The following $$$n$$$ lines each contain $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$a_{i,j}$$$ ($$$1 \leq a_{i,j} \leq 10^9$$$).

For each case, output $$$n$$$ lines each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$b_{i,j}$$$.

NoteIn all the cases, you can verify that no two adjacent cells have the same value and that $$$b$$$ is the same as $$$a$$$ with some values incremented by one.

// Written by : Syed Mujtaba
// Seek knowledge from the cradle to the grave
package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
  defer writer.Flush()
  var t int
  fmt.Scanf("%d\n", &t)

  for T := 0; T < t; T++ {
  	var n, m int
  	scanf("%d %d\n", &n, &m)
  	var arr [102][102]int
  	for i := 1; i <= n; i++ {
  		for j := 1; j <= m; j++ {
  			scanf("%d", &arr[i][j])
  			if j != m {
  				scanf(" ")
  			} else {
  				scanf("\n")
  			}
  			if (arr[i][j] + i + j) % 2 == 1 {
  				arr[i][j] = arr[i][j] + 1
  			}
  			printf("%d ", arr[i][j])
  		}
  		printf("\n")
  	}
  }
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func solveA() {
	n := 0
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		printf("1 ")
	}
	printf("\n")
}

func solveB() {
	n := 0
	scanf("%d\n", &n)
	d := make(map[int]int)
	ans := "NO"
	for k, i := 0, 0; i < n; i++ {
		if i + 1 == n {
			scanf("%d\n", &k)
		} else {
			scanf("%d ", &k)
		}
		d[k]++
		if d[k] > 1 {
			ans = "YES"
		}
	}
	printf(ans + "\n")
}

func solveC() {
	n, m := 0, 0
	scanf("%d %d\n", &n, &m)
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, m)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if j + 1 == m {
				scanf("%d\n", &g[i][j])
			} else {
				scanf("%d ", &g[i][j])
			}
			if g[i][j] % 2 != (i + j) % 2 {
				g[i][j]++
			}
		}
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			printf("%d ", g[i][j])
		}
		printf("\n")
	}
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solveC()
	}
}

/*
URL:
https://codeforces.com/contest/1438/problem/C
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	t int

	n, m int
	A    [][]int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n, m = readi2()
		A = [][]int{}
		for i := 0; i < n; i++ {
			row := readis(m)
			A = append(A, row)
		}

		solve()
	}
}

func solve() {
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			sum := i + j
			if (sum % 2) != (A[i][j] % 2) {
				A[i][j]++
			}
		}
	}

	for i := 0; i < n; i++ {
		printf("%s\n", PrintIntsLine(A[i]...))
	}
}

/*******************************************************************/

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

// abs is integer version of math.Abs
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// Printf is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func printf(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*********** Debugging ***********/

// debugf is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func debugf(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	type data struct{ x, y int }
	solve := func(Case int) {
		var n, m int
		Fscan(in, &n, &m)
		a := make([][]int, n)
		for i := range a {
			a[i] = make([]int, m)
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
		}
		for s := 0; s < n+m-1; s++ {
			l := max(0, s-n+1)
			r := min(m-1, s)
			for j := l; j <= r; j++ {
				i := s-j
				if s&1==0 {
					if a[i][j]&1==1 {
						a[i][j]++
					}
				} else {
					if a[i][j]&1==0 {
						a[i][j]++
					}
				}
			}
		}
		for _, r := range a {
			for _, v := range r {
				Fprint(out, v, " ")
			}
			Fprintln(out)
		}
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, m int
	var a [][]int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)
		a = make([][]int, n)
		for i := range a {
			a[i] = make([]int, m)
			for j := range a[i] {
				fmt.Fscan(in, &a[i][j])
				if (i+j)%2 != a[i][j]%2 {
					a[i][j]++
				}
			}
		}
		for i := range a {
			for j := range a[i] {
				fmt.Printf("%d ", a[i][j])
			}
			fmt.Println()
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

	for i := 0; i < t; i++ {
		var n, m int
		fmt.Fscan(reader, &n, &m)

		matrix := make([][]int, n)
		for j := 0; j < n; j++ {
			matrix[j] = make([]int, m)
			for k := 0; k < m; k++ {
				fmt.Fscan(reader, &matrix[j][k])
			}
		}

		for j := 0; j < n; j++ {
			mod := j % 2

			for k := 0; k < m; k++ {
				if matrix[j][k]%2 == (mod+1)%2 {
					matrix[j][k]++
				}

				mod = (mod + 1) % 2
			}
		}

		for j := 0; j < n; j++ {
			for k := 0; k < m; k++ {
				fmt.Printf("%d ", matrix[j][k])
			}
			fmt.Println()
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
3
3 2
1 2
4 5
7 8
2 2
1 1
3 3
2 2
1 3
2 2

1 2
5 6
7 8
2 1
4 3
2 4
3 2
*/

func EngineerArtem(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, rows, columns, target int64
	var result [][]int64

	for Fscan(in, &T); T > int64(0); T-- {
		Fscan(in, &rows)
		Fscan(in, &columns)
		result = make([][]int64, rows)
		for i := int64(0); i < rows; i++ {
			result[i] = make([]int64, columns)
		}

		for i := int64(0); i < rows; i++ {
			for j := int64(0); j < columns; j++ {
				Fscan(in, &target)
				result[i][j] = target
			}
		}

		for i := 0; i < len(result); i++ {
			for j := 0; j < len(result[i]); j++ {
				if (i+j)%2 == 0 {
					if result[i][j]%2 != 0 {
						result[i][j]++
					}
				} else {
					if result[i][j]%2 == 0 {
						result[i][j]++
					}
				}
			}
		}

		for i := 0; i < len(result); i++ {
			for j := 0; j < len(result[i]); j++ {
				Fprintf(out, "%d ", result[i][j])
			}
			Fprintf(out, "\n")
		}

	}

}

func main() {
	EngineerArtem(os.Stdin, os.Stdout)
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n, m := sint64(), sint64()
		in := make([][]int64, n)
		for i := range in {
			in[i] = make([]int64, m)
		}
		for i := range in {
			for j := range in[i] {
				in[i][j] = sint64()
			}
		}
		ans := sol(in)
		for i := range ans {
			for j := range ans[i] {
				printf("%d ", ans[i][j])
			}
			printf("\n")
		}
	}
}

func sol(in [][]int64) [][]int64 {
	for i := range in {
		for j := range in[i] {
			if (i + j) & 1 == 0 && in[i][j] & 1 == 0 {
				in[i][j]++
			}
			if (i + j) & 1 == 1 && in[i][j] & 1 == 1 {
				in[i][j]++
			}
		}
	}
	return in
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	type pair struct{ x, y int }
	dir4 := []pair{{-1, 0}, {1, 0}, {0, -1}, {0, 1}} // 上下左右

	solve := func(Case int) {
		var n, m int
		Fscan(in, &n, &m)
		a := make([][]int, n)
		for i := range a {
			a[i] = make([]int, m)
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
		}
		for s := 0; s < n+m-1; s++ {
			l := max(0, s-n+1)
			r := min(m-1, s)
			o:
			for j := l; j <= r; j++ {
				i := s - j
				for _, d := range dir4 {
					if xx, yy := i+d.x, j+d.y; 0 <= xx && xx < n && 0 <= yy && yy < m  {
						if a[i][j] +1 == a[xx][yy] {
							continue o
						}
					}
				}
				a[i][j]++
			}
		}
		for _, r := range a {
			for _, v := range r {
				Fprint(out, v, " ")
			}
			Fprintln(out)
		}
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n, m := sint64(), sint64()
		in := make([][]int64, n)
		for i := range in {
			in[i] = make([]int64, m)
		}
		for i := range in {
			for j := range in[i] {
				in[i][j] = sint64()
			}
		}
		ans := sol(in)
		for i := range ans {
			for j := range ans[i] {
				printf("%d ", ans[i][j])
			}
			printf("\n")
		}
	}
}

func sol(in [][]int64) [][]int64 {
	explored := map[[2]int64]bool{}
	var explore func(int64, int64)
	explore = func(i, j int64) {
		if explored[[2]int64{i, j}] {
			return
		}
		explored[[2]int64{i, j}] = true
		if i+1 < int64(len(in)) && j+1 < int64(len(in[i])) {
			addi := false
			addj := false
			if in[i+1][j] == in[i][j] {
				in[i+1][j]++
				addi = true
			}
			if in[i][j+1] == in[i][j] {
				in[i][j+1]++
				addj = true
			}
			// make sure bot and right are the same or 2 apart
			// this ensures that the btm right number always has a way to
			// be valid
			if abs(in[i+1][j]-in[i][j+1]) == 1 {
				if !addi {
					in[i+1][j]++
				} else if !addj {
					in[i][j+1]++
				} else {
					panic("should not happen")
				}
			}
			explore(i+1, j)
			explore(i, j+1)
			return
		}
		if i+1 < int64(len(in)) {
			if in[i+1][j] == in[i][j] {
				in[i+1][j]++
			}
			explore(i+1, j)
			return
		}
		if j+1 < int64(len(in[0])) {
			if in[i][j+1] == in[i][j] {
				in[i][j+1]++
			}
			explore(i, j+1)
			return
		}
	}
	explore(0, 0)
	return in
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n, m := sint64(), sint64()
		in := make([][]int64, n)
		for i := range in {
			in[i] = make([]int64, m)
		}
		for i := range in {
			for j := range in[i] {
				in[i][j] = sint64()
			}
		}
		ans := sol(in)
		for i := range ans {
			for j := range ans[i] {
				printf("%d ", ans[i][j])
			}
			printf("\n")
		}
	}
}

func sol(in [][]int64) [][]int64 {
	explored := map[[2]int64]bool{}
	var explore func(int64, int64)
	explore = func(i, j int64) {
		if explored[[2]int64{i, j}] {
			return
		}
		explored[[2]int64{i, j}] = true
		if i+1 < int64(len(in)) && j+1 < int64(len(in[i])) {
			if in[i+1][j] == in[i][j] {
				in[i+1][j]++
			}
			if in[i][j+1] == in[i][j] {
				in[i][j+1]++
			}
			if in[i+1][j]-in[i][j+1] == 1 {
				in[i][j+1]++
			}
			if in[i][j+1]-in[i+1][j] == 1 {
				in[i+1][j]++
			}
			explore(i+1, j)
			explore(i, j+1)
			return
		}
		if i+1 < int64(len(in)) {
			if in[i+1][j] == in[i][j] {
				in[i+1][j]++
			}
			explore(i+1, j)
			return
		}
		if j+1 < int64(len(in[0])) {
			if in[i][j+1] == in[i][j] {
				in[i][j+1]++
			}
			explore(i, j+1)
			return
		}
	}
	explore(0, 0)
	return in
}