package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return 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
}

func ReadStringSlice(n int) []string {
	b := make([]string, n)
	for i := 0; i < n; i++ {
		b[i] = ReadString()
		fMap[b[i]]++
	}
	return b
}

var t int
var n int
var arr []string
var fMap map[string]int
var output strings.Builder

func main() {
	t = ReadInt()

	for ; t > 0; t-- {
		n = ReadInt()
		fMap = nil
		fMap = make(map[string]int)

		arr = ReadStringSlice(n)

		solve()
	}
}

func solve() {
	output.Reset()
	output.Grow(10 * n)

	changeCount := 0
	for _, v := range fMap {
		changeCount += (v - 1)
	}
	output.WriteString(strconv.Itoa(changeCount) + "\n")

	// changed pin
	visited := make(map[string]bool)
	for i := 0; i < n; i++ {
		if !visited[arr[i]] {
			output.WriteString(arr[i] + "\n")
			visited[arr[i]] = true
		} else {
			newPin := arr[i]
			for fMap[newPin] > 0 {
				firstDigit, _ := strconv.Atoi(string(newPin[0]))
				firstDigit = (firstDigit + 1) % 10
				newPin = strconv.Itoa(firstDigit) + newPin[1:]
			}
			fMap[newPin]++
			output.WriteString(newPin + "\n")
		}
	}
	fmt.Println(output.String())
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

// 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
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// 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
}

// 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
}

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

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

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(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 := PowInt(a, halfE)
		return half * half
	}

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

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// 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)
}

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n int
var P [][]rune

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n = ReadInt()

		P = [][]rune{}
		for i := 0; i < n; i++ {
			row := ReadRuneSlice()
			P = append(P, row)
		}

		solve()
	}
}

var used [10]int

func solve() {
	num := 0
	used = [10]int{}

	for i := 0; i < n; i++ {
		used[P[i][3]-'0'] = 1
	}

	for i := 0; i < n; i++ {
		A := P[i]
		// 直前のものすべてと比較する
		// OUTER:
		for j := 0; j < i; j++ {
			B := P[j]
			// 等しいものがあればAの最上位桁を未使用のものに変更
			if isEqual(A, B) {
				// for i := 0; i < 10; i++ {
				// 	// 未使用のものを選ぶ
				// 	if used[i] == 0 {
				// 		A[3] = rune(i) + '0'
				// 		num++
				// 		used[i] = 1 // 使用済み
				// 		// break OUTER
				// 		break
				// 	}
				// }
				u := findMinUnused()
				A[3] = rune(u) + '0'
				num++
				used[u] = 1
				break
			} else {
				// 前のものと異なるなら何もしなくて良い
				continue
			}
		}

		// ループを抜けたときのAの最上位桁は必ず使用済み
		used[A[3]-'0'] = 1
	}

	fmt.Println(num)
	for i := 0; i < n; i++ {
		fmt.Println(string(P[i]))
	}
}

func findMinUnused() int {
	for i := 0; i < 10; i++ {
		if used[i] == 0 {
			return i
		}
	}
	return -1
}

func isEqual(a, b []rune) bool {
	for i := 0; i < 4; i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

// 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
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// 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
}

// 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
}

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

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

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(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 := PowInt(a, halfE)
		return half * half
	}

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

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// 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)
}

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n int
var P [][]rune

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n = ReadInt()

		P = [][]rune{}
		for i := 0; i < n; i++ {
			row := ReadRuneSlice()
			P = append(P, row)
		}

		solve()
	}
}

var used [10]int

func solve() {
	num := 0
	used = [10]int{}

	for i := 0; i < n; i++ {
		used[P[i][3]-'0'] = 1
	}

	for i := 0; i < n; i++ {
		A := P[i]
		// 直前のものすべてと比較する
		// OUTER:
		for j := 0; j < i; j++ {
			B := P[j]
			// 等しいものがあればAの最上位桁を未使用のものに変更
			if isEqual(A, B) {
				// for i := 0; i < 10; i++ {
				// 	// 未使用のものを選ぶ
				// 	if used[i] == 0 {
				// 		A[3] = rune(i) + '0'
				// 		num++
				// 		used[i] = 1 // 使用済み
				// 		// break OUTER
				// 		break
				// 	}
				// }
				u := findMinUnused()
				A[3] = rune(u) + '0'
				num++
				used[u] = 1
				break
			} else {
				// 前のものと異なるなら何もしなくて良い
				continue
			}
		}

		// ループを抜けたときのAの最上位桁は必ず使用済み
		// used[A[3]-'0'] = 1
	}

	fmt.Println(num)
	for i := 0; i < n; i++ {
		fmt.Println(string(P[i]))
	}
}

func findMinUnused() int {
	for i := 0; i < 10; i++ {
		if used[i] == 0 {
			return i
		}
	}
	return -1
}

func isEqual(a, b []rune) bool {
	for i := 0; i < 4; i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

package main

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

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

	testCount := 0
	fmt.Fscanf(in, "%d\n", &testCount)

	for ; testCount > 0; testCount-- {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)

		fMap := make(map[string]int, n)
		arr := make([]string, n)

		for t := 0; t < n; t++ {
			pin := ""
			fmt.Fscanf(in, "%s\n", &pin)

			arr[t] = pin
			fMap[pin]++
		}

		PINCodes(arr, fMap)
	}
}

func PINCodes(arr []string, fMap map[string]int) {
	// print sum
	changeCount := 0
	for _, v := range fMap {
		changeCount += (v - 1)
	}
	fmt.Println(changeCount)

	// changed pin
	visited := make(map[string]bool)
	for i := 0; i < len(arr); i++ {
		if !visited[arr[i]] {
			fmt.Println(arr[i])
			visited[arr[i]] = true
		} else {
			newPin := arr[i]
			for fMap[newPin] > 0 {
				firstDigit, _ := strconv.Atoi(string(newPin[0]))
				firstDigit = (firstDigit + 1) % 10
				newPin = strconv.Itoa(firstDigit) + newPin[1:]
			}
			fMap[newPin]++
			fmt.Println(newPin)

		}
		//fMap[arr[i]]--
	}
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"sync"
)

func main() {
	for t := ReadInt(); t > 0; t-- {
		n := ReadInt()
		fMap := make(map[string]int, n)
		arr := ReadStringSlice(n)
		for i := 0; i < n; i++ {
			fMap[arr[i]]++
		}
		solve(fMap, arr)

	}

	close(out)
	outWg.Wait()
}

func solve(fMap map[string]int, arr []string) {

	changeCount := 0
	for _, v := range fMap {
		changeCount += (v - 1)
	}
	out <- strconv.Itoa(changeCount)

	// changed pin
	visited := make(map[string]bool)
	for i := 0; i < len(arr); i++ {
		if !visited[arr[i]] {
			out <- arr[i]
			visited[arr[i]] = true
		} else {
			newPin := arr[i]
			for fMap[newPin] > 0 {
				firstDigit, _ := strconv.Atoi(string(newPin[0]))
				firstDigit = (firstDigit + 1) % 10
				newPin = strconv.Itoa(firstDigit) + newPin[1:]
			}
			fMap[newPin]++
			out <- newPin
		}
	}
}

/*********************** utility ***********************/

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	// set output
	out = make(chan string, 1024)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

		for line := range out {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ReadString() string {
	in.Scan()
	return in.Text()
}

func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}

func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.Atoi(intStr)
	return i
}

func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i], _ = strconv.Atoi(ReadString())
	}
	return arr
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

// 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
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// 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
}

// 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
}

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

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

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(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 := PowInt(a, halfE)
		return half * half
	}

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

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// 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)
}

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n int
var P [][]rune

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n = ReadInt()

		P = [][]rune{}
		for i := 0; i < n; i++ {
			row := ReadRuneSlice()
			P = append(P, row)
		}

		solve()
	}
}

func solve() {
	num := 0
	used := [10]int{}

	// used[P[0][3]-'0'] = 1

	for i := 0; i < n; i++ {
		A := P[i]
		// 直前のものすべてと比較する
		// OUTER:
		for j := 0; j < i; j++ {
			B := P[j]
			// 等しいものがあればAの最上位桁を未使用のものに変更
			if isEqual(A, B) {
				for i := 0; i < 10; i++ {
					// 未使用のものを選ぶ
					if used[i] == 0 {
						A[3] = rune(i) + '0'
						num++
						used[i] = 1 // 使用済み
						// break OUTER
						break
					}
				}
				break
			} else {
				// 前のものと異なるなら何もしなくて良い
				continue
			}
		}

		// ループを抜けたときのAの最上位桁は必ず使用済み
		used[A[3]-'0'] = 1
	}

	fmt.Println(num)
	for i := 0; i < n; i++ {
		fmt.Println(string(P[i]))
	}
}

// func solve() {
// 	groups := make([]int, n)
// 	// 最初は自身が唯一のグループ
// 	for i := 0; i < n; i++ {
// 		groups[i] = i
// 	}
// 	for i := 0; i < n; i++ {
// 		for j := i + 1; j < n; j++ {
// 			if isEqual(P[i], P[j]) {
// 				groups[j] = groups[i]
// 			}
// 		}
// 	}
// 	// fmt.Println(groups)

// }

func isEqual(a, b []rune) bool {
	for i := 0; i < 4; i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

package main

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

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

	testCount := 0
	fmt.Fscanf(in, "%d\n", &testCount)

	for i := 0; i < testCount; i++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)

		fMap := make(map[string]int, n)
		arr := make([]string, n)

		for t := 0; t < n; t++ {
			pin := ""
			fmt.Fscanf(in, "%s\n", &pin)

			arr[t] = pin
			fMap[pin]++
		}

		PINCodes(arr, fMap)
	}
}

func PINCodes(arr []string, fMap map[string]int) {
	// print sum
	changeCount := 0
	for _, v := range fMap {
		changeCount += (v - 1)
	}
	fmt.Println(changeCount)

	// changed pin
	visited := make(map[string]bool)
	for i := 0; i < len(arr); i++ {
		if !visited[arr[i]] {
			fmt.Println(arr[i])
			visited[arr[i]] = true
		} else {
			newPin := arr[i]
			for fMap[newPin] > 0 {
				firstDigit, _ := strconv.Atoi(string(newPin[0]))
				firstDigit = (firstDigit + 1) % 10
				newPin = strconv.Itoa(firstDigit) + newPin[1:]
			}
			fMap[newPin]++
			fmt.Println(newPin)

		}
		fMap[arr[i]]--
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var rows int

	fmt.Fscanln(os.Stdin, &rows)

	for i := 0; i < rows; i++ {
		var n int
		fmt.Fscanln(os.Stdin, &n)

		m := map[[4]byte]struct{}{}
		r := make([][4]byte, 0, n)
		c := 0
		for j := 0; j < n; j++ {
			var b string

			fmt.Fscanln(os.Stdin, &b)

			pin := [4]byte{b[0] - 48, b[1] - 48, b[2] - 48, b[3] - 48}
			if _, ok := m[pin]; ok {
				p := pin
				for {
					p[0]++
					for w := 0; w < 4; w++ {
						if p[w] >= 10 {
							p[w] = 0

							if w < 3 {
								p[w+1]++
							}
						}
					}

					if _, ok1 := m[p]; !ok1 {
						m[p] = struct{}{}
						r = append(r, p)

						for w := 0; w < 4; w++ {
							if p[w] != pin[w] {
								c++
							}
						}
						break
					}
				}
			} else {
				m[pin] = struct{}{}
				r = append(r, pin)
			}
		}

		fmt.Fprintln(os.Stdout, c)
		for _, pin := range r {
			fmt.Fprintf(os.Stdout, "%d%d%d%d\n", pin[0], pin[1], pin[2], pin[3])
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var rows int

	fmt.Fscanln(os.Stdin, &rows)

	for i := 0; i < rows; i++ {
		var n int
		fmt.Fscanln(os.Stdin, &n)

		m := map[[4]byte]int{}
		in := make([][4]byte, 0, n)
		r := make([][4]byte, 0, n)
		c := 0
		for j := 0; j < n; j++ {
			var b string

			fmt.Fscanln(os.Stdin, &b)

			pin := [4]byte{b[0] - 48, b[1] - 48, b[2] - 48, b[3] - 48}
			in = append(in, pin)
			m[pin]++
		}

		for _, pin := range in {
			m[pin]--
			if m[pin] > 0 {
				p := pin
				for {
					p[0]++
					for w := 0; w < 4; w++ {
						if p[w] >= 10 {
							p[w] = 0

							if w < 3 {
								p[w+1]++
							}
						}
					}

					if _, ok1 := m[p]; !ok1 {
						m[p] = 0
						r = append(r, p)

						for w := 0; w < 4; w++ {
							if p[w] != pin[w] {
								c++
							}
						}
						break
					}
				}
			} else {
				r = append(r, pin)
			}
		}

		fmt.Fprintln(os.Stdout, c)
		for _, pin := range r {
			fmt.Fprintf(os.Stdout, "%d%d%d%d\n", pin[0], pin[1], pin[2], pin[3])
		}
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var rows int

	fmt.Fscanln(os.Stdin, &rows)

	for i := 0; i < rows; i++ {
		var n int
		fmt.Fscanln(os.Stdin, &n)

		m := map[[4]byte]int{}
		in := make([][4]byte, 0, n)
		r := make([][4]byte, 0, n)
		c := 0
		for j := 0; j < n; j++ {
			var b string

			fmt.Fscanln(os.Stdin, &b)

			pin := [4]byte{b[0] - 48, b[1] - 48, b[2] - 48, b[3] - 48}
			in = append(in, pin)
			m[pin]++
		}

		for _, pin := range in {
			m[pin]--
			if m[pin] > 0 {
				p := pin
				for {
					p[0]++
					for w := 0; w < 4; w++ {
						if p[w] >= 10 {
							p[w] = 0

							if w < 3 {
								p[w+1]++
							}
						}
					}

					if _, ok1 := m[p]; !ok1 {
						r = append(r, p)

						for w := 0; w < 4; w++ {
							if p[w] != pin[w] {
								c++
							}
						}
						break
					}
				}
			} else {
				r = append(r, pin)
			}
		}

		fmt.Fprintln(os.Stdout, c)
		for _, pin := range r {
			fmt.Fprintf(os.Stdout, "%d%d%d%d\n", pin[0], pin[1], pin[2], pin[3])
		}
	}
}


// У Алисии есть массив неотрицательных целых чисел a1,a2,…,an. Для всех 1≤i≤n, она нашла число xi=max(0,a1,…,ai−1).
// Обратите внимание, что для i=1, xi=0
// Например, если у Алисии был массив a={0,1,2,0,3}, то x={0,0,1,2,2}
// Затем она вычислила значения массива b1,b2,…,bn: bi=ai−xi.
// Например, если у Алисии был массив a={0,1,2,0,3}, то b={0−0,1−0,2−1,0−2,3−2}={0,1,1,−2,1}.
// Алисия дала вам массив b1,b2,…,bn и попросила восстановить массив a1,a2,…,an.
// Можете ли вы помочь ей с этой задачей?

// Входные данные
// В первой строке записано одно целое число n (3≤ n≤ 200000) — количество элементов в массиве Алисии.
// Во второй строке записаны n целых чисел, b1,b2,…,bn (−109≤bi≤109).
// Гарантируется, что для заданного массива b существует решение a1,a2,…,an, для всех элементов которого верно: 0≤ai≤109.

// Выходные данные
// Выведите n целых чисел, a1,a2,…,an (0≤ai≤109), таких, что если вы посчитаете x согласно условию, b1 будет равно
// a1−x1, b2 будет равно a2−x2, ..., и bn будет равно an−xn.
// Гарантируется, что на всех данных тестах есть хотя бы одно решение. Можно показать, что в таком случае решение единственно.
package main

import (
	"bufio"
	"flag"
	"fmt"
	"log"
	"os"
	"runtime/pprof"
)

type Decoder struct {
	maxItem int64
}

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func (d *Decoder) Decode(newItem int64) int64 {
	result := d.maxItem + newItem
	d.maxItem = max(d.maxItem, result)
	return result
}

var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}
	var n, i uint64
	var t int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	decoder := Decoder{}
	_, err := fmt.Scanf("%d\n", &n)
	if err != nil {
		fmt.Printf("err1: %v", err.Error())
		os.Exit(1)
	}
	for i = 0; i < n; i++ {
		_, err := fmt.Fscanf(reader, "%d", &t)
		if err != nil {
			fmt.Printf("err2: %v", err.Error())
			os.Exit(1)
		}

		fmt.Fprintf(writer, "%d ", decoder.Decode(t))
	}
	writer.Flush()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &b[i])
	}
	fmt.Fscanf(in, "\n")
	maxN := int64(0)
	a := make([]int64, n)
	a[0] = b[0]
	maxN = max(a[0], maxN)
	for i := 1; i < n; i++ {
		a[i] = b[i] + maxN
		maxN = max(maxN, a[i])
	}
	fmt.Fprintf(out, "%d", a[0])
	for i := 1; i < n; i++ {
		fmt.Fprintf(out, " %d", a[i])
	}
	fmt.Fprintf(out, "\n")
	return
}

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	n := NextInt()
	a := make([]int, n)
	curmax := 0
	for i := 0; i < n; i++ {
		b := NextInt()
		a[i] = b + curmax
		if a[i] > curmax {
			curmax = a[i]
		}
		fmt.Fprint(out, a[i], " ")
	}
}

package main

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

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

func scanf(format string, a ...interface{})  { fmt.Fscanf(in, format, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	defer out.Flush()
	var n int
	scanf("%d\n", &n)
	b := make([]int, n)
	for i := range b {
		scanf("%d", &b[i])
	}

	x := 0
	for i := 0; i < n; i++ {
		a := b[i] + x
		printf("%d ", a)
		x = max(x, a)
	}

}

package main

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

func main(){
	var n int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	 defer out.Flush()

	fmt.Fscanf(in,"%d\n",&n)

	a := make([]int ,n)

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

	b := make([]int,n)
	maxx := 0

	for i := 0 ; i < n ; i ++ {
		b[i] = maxx + a[i]
		if  maxx + a[i] > maxx{
			maxx = maxx + a[i]
		}
	}

	for i := 0 ; i < n ; i ++ {
		fmt.Fprintf(out,"%d ",b[i])
	}
	fmt.Fprintf(out,"\n")
}

package main

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

const (
	maxn = int(1e5 + 50)
	mod  = int(1e9 + 7)
	eps  = 1e-8
	inf  = int(0x3f3f3f3f)
)

var n int
var b []int
var a []int

func main() {
	scanInt(&n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		scanInt(&b[i])
	}
	a = make([]int, n)
	a[0] = b[0]
	mx := a[0]
	for i := 1; i < n; i++ {
		a[i] = mx + b[i]
		mx = max(mx, a[i])
	}
	printIntSlice(a, true)
	close(channelType)
	oWg.Wait()
	out.Flush()
}

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

var channelType chan string
var in *bufio.Scanner
var out = bufio.NewWriter(os.Stdout)
var oWg *sync.WaitGroup

// string and slice are the return value
func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)
	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			writer.WriteString(line + "\n")
		}
	}()
}
func scanString() string { in.Scan(); return in.Text() }
func scanInt(a *int)     { *a, _ = strconv.Atoi(scanString()) }
func scanInts(a ...*int) {
	for i := range a {
		*a[i], _ = strconv.Atoi(scanString())
	}
}
func scanInt64(a *int64) { *a, _ = strconv.ParseInt(scanString(), 10, 64) }
func scanInt64s(a ...*int64) {
	for i := range a {
		*a[i], _ = strconv.ParseInt(scanString(), 10, 64)
	}
}
func scanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = scanString()
	}
	return s
}
func scanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		scanInt(&arr[i])
	}
	return arr
}
func scanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		scanInt64(&arr[i])
	}
	return arr
}
func printlnInts(args ...int) {
	for _, x := range args {
		fmt.Fprint(out, x, " ")
	}
	fmt.Fprintln(out)
}
func printlnInt64s(args ...int64) {
	for _, x := range args {
		fmt.Fprint(out, x, " ")
	}
	fmt.Fprintln(out)
}
func printIntSlice(a []int, flag bool) {
	for _, x := range a {
		fmt.Fprint(out, x, " ")
	}
	if flag { fmt.Fprintln(out) }
}
func printInt64Slice(a []int64, flag bool) {
	for _, x := range a {
		fmt.Fprint(out, x, " ")
	}
	if flag { fmt.Fprintln(out) }
}
func printRuneSlice(a []rune, flag bool) {
	for _, x := range a {
		fmt.Fprintf(out, "%c", x)
	}
	if flag { fmt.Fprintln(out) }
}
func putchar(a ...rune) {
	for _, x := range a {
		fmt.Fprintf(out, "%c", x)
	}
}
func printString(s string) { fmt.Fprintln(out, s) }

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string { return fmt.Sprintf("%v", v) }
func spaceSeperatedStringFromArray(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func spaceSeperatedStringFromArray64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func minMaxFromArray(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 minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64         { return a / gcdCalculation(a, b) * b }
func gcdCalculation(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return gcdCalculation(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func absoluteValue(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}
func min(args ...int) int { mn, _ := minMaxFinder(args...); return mn }
func max(args ...int) int { _, mx := minMaxFinder(args...); return mx }
func minMaxFinder(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(math.MinInt32)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func same(x, y double) bool { return math.Abs(float64(x-y)) < eps }
func popcount(x int) (res int) {
	for i := 0; i < 32; i++ {
		if 1 == (1 & (x >> uint(i))) {
			res++
		}
	}
	return
}
func qp(a, n int64) (res int64) {
	for ; n > 0; n >>= 1 {
		if (n & 1) == 1 {
			res = res * a % int64(mod)
		}
		a = a * a % int64(mod)
	}
	return
}
func divUp(a, b int64) int64 {
	if a % b == 0 { return a / b } else { return a / b + 1 }
}
// [l, r)
func reverse(a *[]rune, l, r int) {
	for i, j := l, r - 1; i < j; i, j = i + 1, j - 1 {
		(*a)[i], (*a)[j] = (*a)[j], (*a)[i]
	}
}

/*********************** Structs ***********************/
type pair struct{ X, Y int }
type double float64
type pairSlice []pair

func (p pairSlice) Len() int { return len(p) }
func (p pairSlice) Less(i, j int) bool {
	if p[i].X != p[j].X {
		return p[i].X < p[j].X
	} else {
		return p[i].Y < p[j].Y
	}
}
func (p pairSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1326B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n, v, max int
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &v)
		v += max
		Fprint(out, v, " ")
		if v > max {
			max = v
		}
	}
}

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

package main

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

func main() {
	n := ScanInt()
	b := ScanIntSlice(n)

	mx := b[0]
	xi := mx
	O <- S(b[0]) + " "
	for i := 1; i < n; i++ {
		ai := b[i] + xi
		xi = Mx(xi, (ai))
		O <- S(ai) + " "
	}
	O <- "\n"

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line)
		}
	}()
}

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

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(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 int64) int64 { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

const N int = 200005

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 max(a,b int) int {
	if a <= b {
		return b
	} else {
		return a
	}
}

func main() {
	var a, b [N] int
	var n int
	//fmt.Scanf("%d\n", &n)
	scanf("%d\n",&n)
	for i:=0; i < n; i++ {
		//fmt.Scanf("%d", &b[i])
		scanf("%d ", &b[i])
	}
	var mx = 0
	a[0] = b[0] + mx
	fmt.Printf("%d",a[0])
	//printf("%d", a[0])
	for i:=1; i < n; i++ {
		mx = max(a[i-1], mx)
		a[i] = b[i] + mx
		//fmt.Printf("%d=%d+%d\n", a[i], b[i], mx)
		fmt.Printf(" %d",a[i])
		//printf(" %d", a[i])
	}
	fmt.Printf("\n")
	//printf("\n")
}

package main

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

func solve(b []int64) []int64 {
	var max int64
	for i := range b {
		b[i] += max
		if b[i] > max {
			max = b[i]
		}
	}
	return b
}

func main() {
	toInt := func(buf []byte) int64 {
		var n int64
		var d int64 = 1
		for _, v := range buf {
			if v == '-' {
				d = -1
				continue
			}
			n = n*10 + int64(v-'0')
		}
		return d * n
	}

	var n int64

	fmt.Scan(&n)
	b := make([]int64, n)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := range b {
		scanner.Scan()
		b[i] = toInt(scanner.Bytes())
	}

	a := solve(b)
	for _, x := range a {
		fmt.Print(x, " ")
	}
	fmt.Println()
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextInt64Array()
	B := make([]int64, N)

	B[0] = A[0]

	mx := max(0, A[0])
	for i := 1; i < N; i++ {
		mx = max(mx, B[i-1])
		B[i] = A[i] + mx
	}

	PrintI(B...)
}

func max(a int64, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func mapToString(arr []int64) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.FormatInt(arr[i], 10)
	}
	return ret
}

func PrintI(args ...int64) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main
import (
	"fmt"
	"bufio"
	"os"
)

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

	var n, max int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(r, &x)
		fmt.Fprintf(w, "%d ", x + max)
		if max + x > max {
			max += x
		}

	}
}

// У Алисии есть массив неотрицательных целых чисел a1,a2,…,an. Для всех 1≤i≤n, она нашла число xi=max(0,a1,…,ai−1).
// Обратите внимание, что для i=1, xi=0
// Например, если у Алисии был массив a={0,1,2,0,3}, то x={0,0,1,2,2}
// Затем она вычислила значения массива b1,b2,…,bn: bi=ai−xi.
// Например, если у Алисии был массив a={0,1,2,0,3}, то b={0−0,1−0,2−1,0−2,3−2}={0,1,1,−2,1}.
// Алисия дала вам массив b1,b2,…,bn и попросила восстановить массив a1,a2,…,an.
// Можете ли вы помочь ей с этой задачей?

// Входные данные
// В первой строке записано одно целое число n (3≤ n≤ 200000) — количество элементов в массиве Алисии.
// Во второй строке записаны n целых чисел, b1,b2,…,bn (−109≤bi≤109).
// Гарантируется, что для заданного массива b существует решение a1,a2,…,an, для всех элементов которого верно: 0≤ai≤109.

// Выходные данные
// Выведите n целых чисел, a1,a2,…,an (0≤ai≤109), таких, что если вы посчитаете x согласно условию, b1 будет равно
// a1−x1, b2 будет равно a2−x2, ..., и bn будет равно an−xn.
// Гарантируется, что на всех данных тестах есть хотя бы одно решение. Можно показать, что в таком случае решение единственно.
package main

import (
	"bufio"
	"flag"
	"fmt"
	"log"
	"os"
	"runtime/pprof"
)

type Decoder struct {
	maxItem int64
}

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func (d *Decoder) Decode(newItem int64) int64 {
	result := d.maxItem + newItem
	d.maxItem = max(d.maxItem, result)
	return result
}

var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}
	var n, i uint64
	var t int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriterSize(os.Stdout, 1024 * 1024 * 10)
	decoder := Decoder{}
	_, err := fmt.Scanf("%d\n", &n)
	if err != nil {
		fmt.Printf("err1: %v", err.Error())
		os.Exit(1)
	}
	for i = 0; i < n; i++ {
		_, err := fmt.Fscanf(reader, "%d", &t)
		if err != nil {
			fmt.Printf("err2: %v", err.Error())
			os.Exit(1)
		}

		fmt.Fprintf(writer, "%d ", decoder.Decode(t))
	}
	writer.Flush()
}

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type readerImpl struct {
	*bufio.Scanner
}

func NewReader() Reader {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &readerImpl{Scanner: s}
}

func (i *readerImpl) NextInt() int {
	i.Scan()
	ret, _ := strconv.Atoi(i.Text())
	return ret
}

func (i *readerImpl) NextInt64() int64 {
	i.Scan()
	ret, _ := strconv.ParseInt(i.Text(), 10, 64)
	return ret
}

func (i *readerImpl) NextString() string {
	i.Scan()
	return i.Text()
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

func (i *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(i.Writer, f, a...)
}

func (i *writerImpl) Flush() {
	i.Writer.Flush()
}

func main() {
	defer writer.Flush()
	n := reader.NextInt64()
	prevA := int64(0)
	prevX := int64(0)
	for ; n > 0; n-- {
		b := reader.NextInt64()
		x := max(prevA, prevX)
		a := x + b
		writer.Printf("%d ", a)
		prevA = a
		prevX = x
	}
}

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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') {
			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 fillNNums(bs []byte, n int, res []int) {
	x := 0
	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])
	}
}

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

	n := readNum(reader)

	s, _ := reader.ReadBytes('\n')

	B := make([]int, n)

	fillNNums(s, n, B)

	A := solve(n, B)

	for i := 0; i < n; i++ {
		if i < n-1 {
			fmt.Printf("%d ", A[i])
		} else {
			fmt.Printf("%d\n", A[i])
		}
	}
}

func solve(n int, B []int) []int {
	A := make([]int, n)

	A[0] = B[0]

	x := max(0, A[0])

	for i := 1; i < n; i++ {
		A[i] = B[i] + x
		x = max(x, A[i])
	}

	return A
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

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') {
			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 fillNNums(bs []byte, n int, res []int) {
	x := 0
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
}

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

	n := readNum(reader)

	s, _ := reader.ReadBytes('\n')

	B := make([]int, n)

	fillNNums(s, n, B)

	A := solve(n, B)

	for i := 0; i < n; i++ {
		if i < n-1 {
			fmt.Printf("%d ", A[i])
		} else {
			fmt.Printf("%d\n", A[i])
		}
	}
}

func solve(n int, B []int) []int {
	A := make([]int, n)

	A[0] = B[0]

	x := max(0, A[0])

	for i := 1; i < n; i++ {
		A[i] = B[i] + x
		x = max(x, A[i])
	}

	return A
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

package main

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

func main(){
	var n int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	 defer out.Flush()

	fmt.Fscanf(in,"%d\n",&n)

	a := make([]int ,n)

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

	b := make([]int,n)
	maxx := 0
	summ := 0
	for i := 0 ; i + 1 < n ; i ++ {
		summ += a[i]
		b[i] = summ
		if b[i] > maxx{
			maxx = b[i]
		}
	}

	b[n-1] = maxx + a[n-1]

	for i := 0 ; i < n ; i ++ {
		fmt.Fprintf(out,"%d ",b[i])
	}
	fmt.Fprintf(out,"\n")
}

package main

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

func main(){
	var n int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	 defer out.Flush()

	fmt.Fscanf(in,"%d\n",&n)

	a := make([]int ,n)

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

	b := make([]int,n)

	summ := 0
	for i := 0 ; i < n ; i ++ {
		summ += a[i]
		b[i] = summ
	}
	for i := 0 ; i < n ; i ++ {
		fmt.Fprintf(out,"%d ",b[i])
	}
	fmt.Fprintf(out,"\n")
}

package main

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

const N int = 200005

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 max(a,b int) int {
	if a <= b {
		return b
	} else {
		return a
	}
}

func main() {
	var a, b [N] int
	var n int
	//fmt.Scanf("%d\n", &n)
	scanf("%d\n",&n)
	for i:=0; i < n; i++ {
		//fmt.Scanf("%d", &b[i])
		scanf("%d ", &b[i])
	}
	var mx = 0
	a[0] = b[0] + mx
	//fmt.Printf("%d",a[0])
	printf("%d", a[0])
	for i:=1; i < n; i++ {
		mx = max(a[i-1], mx)
		a[i] = b[i] + mx
		//fmt.Printf("%d=%d+%d\n", a[i], b[i], mx)
		//fmt.Printf(" %d",a[i])
		printf(" %d", a[i])
	}
	//fmt.Printf("\n")
	printf("\n")
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextInt64Array()
	B := make([]int64, N)

	B[0] = A[0]

	for i := 1; i < N; i++ {
		B[i] = B[i-1] + A[i]
	}

	PrintI(B...)
}

func mapToString(arr []int64) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.FormatInt(arr[i], 10)
	}
	return ret
}

func PrintI(args ...int64) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	t := nextInt(sc)
	ans := make([]int, t)
	for i := 0; i < t; i++ {
		n := nextInt(sc)
		k := nextInt(sc)
		given := (n / k) * k
		given += min(k/2, n-given)
		ans[i] = given
	}
	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < t; i++ {
		fmt.Fprintln(wtr, ans[i])
	}
	wtr.Flush()
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

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

func main() {
	var inputLn int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d\n", &inputLn)
	candy := 0
	kids := 0
	newline := []byte{'\n'}
	for i := 0; i < inputLn; i++ {
		scanner.Scan()
		inputCase := scanner.Bytes()
		candy, kids = toInt(bytes.Split(inputCase, newline)[0])
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (modulus)) + (kids / 2))
		}
	}
}

func toInt(buf []byte) (int, int) {
	nn := bytes.Split(buf, []byte{' '})
	n, _ := strconv.Atoi(string(nn[0]))
	i, _ := strconv.Atoi(string(nn[1]))
	return n, i
}

/************************************/
/* Date		: 2020-01-17 10:17:27	*/
/* Author	: MiohitoKiri5474		*/
/* Email	: lltzpp@gmail.com		*/
/************************************/

// by. MiohitoKiri5474

package main

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

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

func main() {
	in := bufio.NewReader ( os.Stdin )
	var t, n, m int
	fmt.Fscan ( in, &t )
	for t > 0 {
		t--
		fmt.Fscan ( in, &n, &m )
		ans := ( n / m )
		ans *= m
		ans += min ( n % m, m / 2 )
		fmt.Println ( ans )
	}
}

package main

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

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    defer writer.Flush()
    var t, ans int
    fmt.Fscanln(reader, &t)
    for i := 0; i < t; i++ {
        var n, k int
        fmt.Fscanln(reader, &n, &k)
        var a = n / k
        ans = a * k
        if n % k > 0 {
            ans += min(k / 2, n % k)
        }
        fmt.Fprintln(writer, ans)
    }
}

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() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for i := 1; i <= t; i++ {
		var n, k int
		scanf("%d %d\n", &n, &k)
		printf("%d\n", n/k*k+min(n%k, k/2))
	}
}

package main

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

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

// D: Some formulas in the problem were written with typos. The correct formula is: the sum of values "the distance to the nearest Christmas tree" over all people.
func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024*1024)

	t, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	for ; t > 0; t-- {
		line := strings.Split(readLine(reader), " ")
		n, err := strconv.ParseInt(line[0], 10, 64)
		checkError(err)
		k, err := strconv.ParseInt(line[1], 10, 64)
		checkError(err)
		a := n / k
		fmt.Println(a*k + min(n%k, int64(math.Ceil(float64(k/2)))))
	}
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

package main

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

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	var tests int

	fmt.Fscanln(reader, &tests)
	for tests > 0 {
		tests--
		var n, k int
		fmt.Fscanln(reader, &n, &k)
		full := n / k
		ans := full * k + min(k / 2, n % k)
		fmt.Fprintln(writer, ans)
		writer.Flush()
	}
}

package main

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

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

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

	fmt.Fscanln(reader, &tests)
	for tests > 0 {
		tests--
		var n, k int
		fmt.Fscanln(reader, &n, &k)
		full := n / k
		ans := full * k + min(k / 2, n % k)
		fmt.Fprintln(writer, ans)
	}
}

package main

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

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	var tests int

	fmt.Fscanln(reader, &tests)
	for tests > 0 {
		tests--
		var n, k int
		fmt.Fscanln(reader, &n, &k)
		full := n / k
		ans := full * k + min(k / 2, n % k)
		fmt.Fprintln(writer, ans)
	}
	writer.Flush()
}

package main

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

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t int
	var n, k, candies int64
	fmt.Fscanln(reader, &t)
	for i := 0; i < t; i++ {
		fmt.Fscanln(reader, &n, &k)
		candies = (n / k) * k
		if n%k != 0 {
			candies += min((k / 2), n-candies)
		}
		fmt.Fprintln(writer, candies)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	input := scanner.Text()

	testCount, _ := strconv.Atoi(input)
	var inputList []string
	var candyCount, childCount int

	for i := 0; i < testCount; i++ {
		scanner.Scan()
		input = scanner.Text()

		inputList = strings.Split(input, " ")
		candyCount, _ = strconv.Atoi(inputList[0])
		childCount, _ = strconv.Atoi(inputList[1])

		candyDiff := candyCount % childCount;
		if candyDiff == 0 {
			fmt.Println(candyCount)
			continue
		}

		baseCandyCount := candyCount - candyDiff
		prevChildCount := childCount / 2

		fmt.Println(min(candyCount, baseCandyCount+prevChildCount))
	}
}

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

	return b
}

package main

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

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

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

	fmt.Fscanln(reader, &tests)
	for tests > 0 {
		tests--
		var n, k int
		fmt.Fscanln(reader, &n, &k)
		full := n / k
		ans := full * k + min(k / 2, n % k)
		fmt.Fprintln(writer, ans)
	}
}

package main

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

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	var tests int

	fmt.Fscanln(reader, &tests)
	for tests > 0 {
		tests--
		var n, k int
		fmt.Fscanln(reader, &n, &k)
		full := n / k
		ans := full * k + min(k / 2, n % k)
		fmt.Fprintln(writer, ans)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	input := scanner.Text()

	testCount, _ := strconv.Atoi(input)
	var inputList []string
	var candyCount, childCount int

	for i := 0; i < testCount; i++ {
		scanner.Scan()
		input = scanner.Text()

		inputList = strings.Split(input, " ")
		candyCount, _ = strconv.Atoi(inputList[0])
		childCount, _ = strconv.Atoi(inputList[1])

		candyDiff := candyCount % childCount;
		if candyDiff == 0 {
			fmt.Println(candyCount)
			continue
		}

		baseCandyCount := candyCount - candyDiff
		prevChildCount := childCount / 2

		fmt.Println(baseCandyCount + prevChildCount)
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

func divideTheCandy(cases [][]int) {
	for _, v := range cases {
		candy := v[0]
		kids := v[1]
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (candy % kids)) + (kids / 2))
		}
	}
	return
}

func main() {
	/*stdin, err := os.OpenFile("input.txt",
		os.O_RDONLY, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdin = stdin

	stdout, err := os.OpenFile("output.txt",
		os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdout = stdout*/
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	var cases [][]int
	for i := 0; i < inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil && err != io.EOF {
			log.Fatalln("Can't read input case!", err)
		}
		var caseStr []string
		caseStr = strings.Split(strings.TrimSuffix(string(input), "\n"), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = append(cases, []int{caseArg1, caseArg2})
	}
	divideTheCandy(cases)
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

func divideTheCandy(cases [][]int) {
	fmt.Println(cases)
	for _, v := range cases {
		candy := v[0]
		kids := v[1]
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (candy % kids)) + (kids / 2))
		}
	}
	return
}

func main() {
	/*stdin, err := os.OpenFile("input.txt",
		os.O_RDONLY, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdin = stdin

	stdout, err := os.OpenFile("output.txt",
		os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
	if err != nil {
		log.Fatal(err)
	}
	os.Stdout = stdout*/
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	var cases [][]int
	for i := 0; i < inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil && err != io.EOF {
			log.Fatalln("Can't read input case!", err)
		}
		var caseStr []string
		caseStr = strings.Split(strings.TrimSuffix(string(input), "\n"), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = append(cases, []int{caseArg1, caseArg2})
	}
	divideTheCandy(cases)
}

package main

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

func divideTheCandy(cases [][]int) {
	for _, v := range cases {
		candy := v[0]
		kids := v[1]
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Fprintf(os.Stdin, "%d\n", candy)
		} else if modulus > kids/2 {
			fmt.Fprintf(os.Stdin, "%d\n", (candy-(candy%kids))+(kids/2))
		}
	}
	return
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	var cases [][]int
	for i := 0; i < inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil {
			log.Fatalln("Can't read input case!", err)
		}
		caseStr := strings.Split(string(input[:len(input)-1]), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = append(cases, []int{caseArg1, caseArg2})
	}
	divideTheCandy(cases)
}

package main

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

func divideTheCandy(kids, candy int) {
	modulus := candy % kids
	if modulus >= 0 && modulus <= kids/2 {
		fmt.Println(candy)
		return
	} else if modulus > kids/2 {
		fmt.Println((candy - (candy % kids)) + (kids / 2))
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	cases := make([]int, 2)
	for i := 1; i <= inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil {
			log.Fatalln("Can't read input case!", err)
		}
		caseStr := strings.Split(string(input[:len(input)-1]), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = []int{caseArg1, caseArg2}
		divideTheCandy(cases[1], cases[0])
	}
}

package main

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

func divideTheCandy(cases [][]int) {
	for _, v := range cases {
		candy := v[0]
		kids := v[1]
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (candy % kids)) + (kids / 2))
		}
	}
	return
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	var cases [][]int
	for i := 1; i <= inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil {
			log.Fatalln("Can't read input case!", err)
		}
		caseStr := strings.Split(string(input[:len(input)-1]), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = append(cases, []int{caseArg1, caseArg2})
	}
	divideTheCandy(cases)
}

package main

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

func divideTheCandy(cases [][]int) {
	for _, v := range cases {
		candy := v[0]
		kids := v[1]
		modulus := candy % kids
		if modulus >= 0 && modulus <= kids/2 {
			fmt.Println(candy)
		} else if modulus > kids/2 {
			fmt.Println((candy - (candy % kids)) + (kids / 2))
		}
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	inputLength, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatalln("Can't read from input!", err)
	}
	inputLengthStr := strings.TrimSuffix(string(inputLength), "\n")
	inputLengthInt, _ := strconv.Atoi(inputLengthStr)
	var cases [][]int
	for i := 1; i <= inputLengthInt; i++ {
		input, err := reader.ReadBytes('\n')
		if err != nil {
			log.Fatalln("Can't read input case!", err)
		}
		caseStr := strings.Split(string(input[:len(input)-1]), " ")
		caseArg1, err := strconv.Atoi(caseStr[0])
		if err != nil {
			log.Fatalln("Can't convert the case argument one", err)
		}
		caseArg2, err := strconv.Atoi(caseStr[1])
		if err != nil {
			log.Fatalln("Can't convert the case argument two", err)
		}
		cases = append(cases, []int{caseArg1, caseArg2})
	}
	divideTheCandy(cases)
}