package main

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

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

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		if n%7 != 0 {
			top := (n/10 + 1) * 10
			bottom := (n / 10) * 10
			for i := n; i < top; i++ {
				if i%7 == 0 {
					n = i
					break
				}
			}

			for i := n; i >= bottom; i-- {
				if i%7 == 0 {
					n = i
					break
				}
			}
		}
		fmt.Fprintln(out, n)
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i:=0; i < n; i++ {
		x:=0
		for x == 0 {
			fmt.Scanf("%d", &x)
		}
		if x % 7 != 0 {
			x -= x % 10
			for j:= 1; j < 10; j++ {
				if (x + j) % 7 == 0 {
					x += j
					break
				}
			}
		}
		fmt.Printf("%d\n", x)
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Scan(&x)
		if x%7 == 0 {
			fmt.Println(x)
		} else {
			x= (x/10)*10
			for j:=0;j<10;j++{
				if (x+j)%7 == 0 {
					fmt.Println(x+j)
					break
				}
			}
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var n, x int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x)
		if x % 7 != 0 {
			x /= 10
			x *= 10
			x += 9
			x -= x % 7
		}
		fmt.Println(x)
	}
}

// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools

// To modify the template, go to Preferences -> Editor -> File and Code Templates -> Other

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var num int
		fmt.Scan(&num)
		if num%7 == 0 {
			fmt.Println(num)
			continue
		}
		n := num / 7
		result := n * 7
		if result/10 == num/10 {
			fmt.Println(result)
		} else {
			fmt.Println(result + 7)
		}
	}
}

package main

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

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

	round := 0
	target := 0
	rem := 0

	Fscan(in, &round)

	for i := 1; i <= round; i++ {
		Fscan(in, &target)
		rem = target % 7
		if rem == 0 {
			Fprintln(out, target)
			continue
		}
		if target%10-rem >= 0 {
			Fprintln(out, target-rem)
		} else {
			Fprintln(out, target+7-rem)
		}
	}
}
func main() { helper(os.Stdin, os.Stdout) }

package main

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

type CF1633A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1633A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1633A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1633A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1633A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1633A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1633A
Date: 7/02/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1633/A
Problem: CF1633A
**/
func (in *CF1633A) Run() {
	for t := in.NextInt(); t > 0; t-- {

		n := in.NextInt()
		ans := -1
		diff := 100000
		for i := n; i > 9; i-- {
			if i%7 == 0 {
				if ans != -1 {
					if diff > dif(fmt.Sprintf("%d", i), fmt.Sprintf("%d", n)) {
						diff = dif(fmt.Sprintf("%d", i), fmt.Sprintf("%d", n))
						ans = i
					}
				} else {
					diff = dif(fmt.Sprintf("%d", i), fmt.Sprintf("%d", n))
					ans = i
				}
			}
		}

		for i := n + 1; i < 5000; i++ {
			if i%7 == 0 {
				if ans != -1 {
					if diff > dif(fmt.Sprintf("%d", i), fmt.Sprintf("%d", n)) {
						diff = dif(fmt.Sprintf("%d", i), fmt.Sprintf("%d", n))
						ans = i
					}
				} else {
					diff = dif(fmt.Sprintf("%d", i), fmt.Sprintf("%d", n))
					ans = i
				}

			}
		}
		fmt.Println(ans)
	}
}

func dif(a, b string) int {
	ans := 0

	for i := 0; i < int(math.Min(float64(len(a)), float64(len(b)))); i++ {
		if a[i] != b[i] {
			ans++
		}
	}

	if len(a)-len(b) != 0 {
		ans += int(math.Abs(float64(len(a) - len(b))))
	}

	return ans
}

func NewCF1633A(r *bufio.Reader) *CF1633A {
	return &CF1633A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1633A(bufio.NewReader(os.Stdin)).Run()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	b := strings.Builder{}
	for i := 0; i < t; i++ {
		b.WriteString(solve(in) + "\n")
	}
	fmt.Println(b.String())
}

func solve(in *bufio.Reader) string {
	n := readInt(in)
	mod := n % 7
	if mod == 0 {
		return strconv.Itoa(n)
	} else {
		r := n % 10
		if r + 7 - mod < 10 {
			return strconv.Itoa(n + 7 - mod)
		} else {
			return strconv.Itoa(n - mod)
		}
	}
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

package main

import "fmt"

func main() {
	var testCases int
	fmt.Scanln(&testCases)
	for testCase := 0; testCase < testCases; testCase++ {
		var n int
		fmt.Scanln(&n)
		m7 := n % 7
		m10 := n % 10
		if m7 <= m10 {
			fmt.Println(n - m7)
		} else {
			fmt.Println(n - m7 + 7)
		}
	}
}

package main

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

/*
1
10
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	var t = 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		if n%7 == 0 {
			fmt.Fprintln(writer, n)
		} else {
			base := n / 10 * 10
			for i := 0; i < 10; i++ {
				num := base + i
				if num%7 == 0 {
					fmt.Fprintln(writer, num)
					break
				}
			}
		}
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

func digits(a int) int {
	if a <= 9 {
		return 1
	}
	return 1 + digits(a/10)
}

func diff(a, b int) int {
	ans := 0
	if a%10 != b%10 {
		ans++
	}
	a /= 10
	b /= 10
	if a%10 != b%10 {
		ans++
	}
	a /= 10
	b /= 10
	if a%10 != b%10 {
		ans++
	}
	return ans
}

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var n int
		scan(&n)

		ans := 0
		ansDiff := 1000
		digitsn := digits(n)

		for x := 7; x <= 999; x += 7 {
			xDiff := diff(x, n)
			if digits(x) == digitsn && xDiff < ansDiff {
				ansDiff = xDiff
				ans = x
			}
		}
		printf("%d\n", ans)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		if n%7 == 0 {
			fmt.Println(n)
		} else {
			if n%10 > n%7 {
				fmt.Println(n - n%7)
			} else {
				fmt.Println(n + 7 - n%7)
			}
		}
	}
}

//nolint
package main

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

//{
var reader = bufio.NewReader(os.Stdin)
var 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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

//}

func Solve() {
	var n int
	scan(&n)
	tp := n % 7
	if tp == 0 {
		println(n)
		return
	}
	lastDigit := n % 10
	if lastDigit-tp > 0 {
		println(n - tp)
		return
	}
	println(n + (7 - tp))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var a []int
	a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i := 0; i < n; i++ {
		if a[i]%7 == 0 {
			fmt.Println(a[i])
		} else {
			a[i] = a[i] / 10 * 10
		qq:
			if a[i]%7 != 0 {
				a[i]++
				goto qq
			} else {
				fmt.Println(a[i])
			}
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var tests int
	fmt.Fscan(in, &tests)
	for t := 0; t < tests; t++ {
		var n int
		fmt.Fscan(in, &n)
		if n%7 == 0 {
			fmt.Println(n)
			continue
		}
		ans := -1
		for j := 0; j < 10; j++ {
			if (n-n%10+j)%7 == 0 {
				ans = n - n%10 + j
			}
		}
		fmt.Println(ans)
	}
}

package main

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

var (
    cin *Scanner
)

type Scanner struct {
    scanner *bufio.Scanner
}

func (s *Scanner)nextInt() int {
    s.scanner.Scan()
    t := s.scanner.Text()
    i, _ := strconv.Atoi(t)
    return i
}

func init() {
    cin = &Scanner{scanner: bufio.NewScanner(os.Stdin)}
    cin.scanner.Split(bufio.ScanWords)
}

func main() {
    t := cin.nextInt()
    for t > 0 {
        n := cin.nextInt()
        if n % 7 == 0 {
            fmt.Println(n)
        } else {
            n = n / 10 * 10
            for n % 7 != 0 {
                n++
            }
            fmt.Println(n)
        }

        t--
    }
}

package main

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

// rolling hash (must do right to left because from left to right you must do division and division + modulo will cause trouble)
//func subStrHash(s string, power int, modulo int, k int, hashValue int) string {
//	left := 0
//	right := 0
//	cur := int64(0)
//	l := len(s)
//
//	for right < l {
//		if right-left < k {
//			val := int64((s[right] - 'a') + 1)
//			cur += val * int64(math.Pow(float64(power), float64(right-left)))
//		} else {
//			leftVal := int64(s[left] - 'a' + 1)
//			rightVal := int64(s[right] - 'a' + 1)
//			cur -= leftVal
//			left++
//			cur /= int64(power)
//			cur += rightVal * int64(math.Pow(float64(power), float64(k-1)))
//
//			if cur%int64(modulo) == int64(hashValue) {
//				return s[left : right+1]
//			}
//		}
//
//		right++
//		cur %= int64(modulo)
//	}
//	return ""
//}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())

	for i := 0; i < t; i++ {
		scanner.Scan()
		s := scanner.Text()
		var ans int
		l, min := len(s), len(s)
		lowerBound := int(math.Pow(float64(10), float64(l-1)))
		upperBound := int(math.Pow(float64(10), float64(l)))
		for j := lowerBound / 7; j <= upperBound/7; j++ {
			cur := j * 7
			diff := 0
			if cur >= lowerBound && cur < upperBound {
				st := strconv.Itoa(cur)
				for k := range st {
					if st[k] != s[k] {
						diff++
					}
				}
			} else {
				continue
			}
			if diff < min {
				min = diff
				ans = cur
			}
		}
		fmt.Println(ans)

	}
}

package main

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

func main() {

	reader := bufio.NewReader(os.Stdin)
	writter := bufio.NewWriter(os.Stdout)
	defer writter.Flush()

	t := 0
	fmt.Fscan(reader, &t)

	for t > 0 {
		n := ""
		fmt.Fscan(reader, &n)
		fmt.Fprintln(writter, solve(n))

		t--
	}

	// n := "377"
	// fmt.Println(solve(n))

}

func solve(s string) int {

	num := strToint(s)

	for num%7 != 0 {

		num++

		if num%10 == 0 {
			num -= 10
		}

	}

	return num
}

func arraySum(array []int) int {
	sum := 0

	for i := range array {
		sum += array[i]
	}

	return sum
}

func numSum(num int) int {
	sum := 0

	for i := num; i > 0; i-- {
		sum += i
	}

	return sum
}

func strToint(str string) int {
	num, _ := strconv.Atoi(str)
	return num
}

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

	return b
}

func getFactor(num int) []int {
	result := []int{}

	for i := 1; i <= int(math.Sqrt(float64(num))); i++ {
		if num%i == 0 {
			result = append(result, i)
			result = append(result, num/i)
		}
	}

	return result
}

func gcd(a, b int) int {
	if a == 0 {
		return b
	}

	return gcd(b%a, a)
}

func printMatrix(matrix [][]int) {

	for i := range matrix {

		for j := range matrix[i] {
			fmt.Printf("%d ", matrix[i][j])
		}

		fmt.Println()

	}

}

func checkPrime(num int) bool {

	if num < 2 {
		return false
	}

	for i := 2; i <= int(math.Sqrt(float64(num))); i++ {
		if num%i == 0 {
			return false
		}
	}

	return true
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	f := func(x int) int {
		n := n
		if x%7 != 0 {
			return 1e9
		}
		res := 0
		for i := 0; i < 3; i++ {
			if n%10 != x%10 {
				res++
			}
			n /= 10
			x /= 10
		}
		return res
	}
	from, to := 10, 99
	if n >= 100 {
		from, to = 100, 999
	}
	x, ansx := -1, int(1e9)
	for i := from; i <= to; i++ {
		if ansx > f(i) {
			x, ansx = i, f(i)
		}
	}
	printf("%v\n", x)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n int
	fmt.Sscanf(scanner.Text(), "%d", &n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		var n int
		fmt.Sscanf(scanner.Text(), "%d", &n)
		if n%7 != 0 {
			n /= 10
			n *= 10
			n += 9
			n -= n % 7
		}
		fmt.Println(n)
	}
}

package main

import "fmt"

func main() {

	var testCases, n, i, j, k int
	fmt.Scan(&testCases)
	for x := 0; x < testCases; x++ {

		fmt.Scan(&n)
		j = n % 7
		i = (7 - j) % 7
		k = n % 10
		if i != 0 {
			if i+k < 10 {
				n += i
			} else {
				n -= j

			}
		}
		fmt.Println(n)
	}

}

package main

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

)

/*

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

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(){

		var n int

		fmt.Fscan(in , &n)

		arr  := make([]int,n)

		for i := 0 ; i < n ; i++{
			fmt.Fscan(in , &arr[i])

			num  :=  DivisionOfSeven(arr[i])

			fmt.Fprintln(out ,num)

		}

		//count := 0

	}

	T := 1

	//fmt.Fscan(in ,&T)

	for o := 0 ; o < T ; o++{
		solve()
	}
}

func DivisionOfSeven(num int)int{

	//n := len(arr)

if num % 7 == 0{

	num =  num
}else{

	for j := 0 ; j < 10 ; j++{

		if (num -  num % 10 + j) % 7 == 0{
			num =  num  - num % 10 + j
		}

	}
}

return num

}

/*

func DivisionOfSeven(arr []int)[]int{

	n := len(arr)

	var status int =  0
	//fmt.Fprintln(arr)
for i := 0 ; i < n ; i++{

	if arr[i] % 7 == 0{

		status = 1
	}else if arr[i] > 7  && status == 0{

		arr[i] = arr[i] + ((7 - (arr[i] % 7)) % 7)
	}

		}

	return arr

}

func ArrayReorder(arr []int)[]int{

 sort.Slice(arr , func(a , b int) bool{

 	return arr[a] & 1 == 0   // even and odd sort
 })
 	return arr
}

func GCD(a , b int)int{

	for a != 0{
		a , b = b % a , a
	}

	return b
}

*/

func main(){

	run(os.Stdin , os.Stdout)
}

package main
import."fmt"

// github.com/EndlessCheng/codeforces-go
func main(){
	T,n:=0,0
	for Scan(&T);T>0;T--{
		if Scan(&n);n%7 > 0 {
			n -= n % 10
			n += 7 - n%7
		}
		Println(n)
	}
}

package main

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

var n int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n)

		ans := solve()

		fmt.Println(ans)
	}
}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve() int {
	if n % 7 == 0{
		return n
	}

	if n < 7 {
		return 7
	}

	r := n % 7

	d1 := n - r
	d2 := n + (7 - r)

	last := n % 10

	if last <= r {
		return d2
	}
	return d1

}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

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

func f(x int) (res [10]int) {
	j := 0
	for i := x; i < 10; i++ {
		res[j] = i
	}
	for i := 0; i < x; i++ {
		res[j] = i
	}
	return
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		var n string
		fmt.Fscan(in, &n)

		ar := make([]int, len(n))
		ress := make([]string, 0, 50)
		for i := range f(ar[0]) {
			for j := range f(ar[1]) {
				if len(n) > 2 {
					for k := range f(ar[2]) {
						x := i*100 + j*10 + k
						if x%7 == 0 && i != 0 {
							ress = append(ress, strconv.Itoa(x))
						}
					}
				} else {
					x := i*10 + j
					if x%7 == 0 && i != 0 {
						ress = append(ress, strconv.Itoa(x))
					}
				}
			}
		}

		sort.Slice(ress, func(i, j int) bool {
			diff1 := 0
			for k := range ress[i] {
				if ress[i][k] != n[k] {
					diff1++
				}
			}
			diff2 := 0
			for k := range ress[j] {
				if ress[j][k] != n[k] {
					diff2++
				}
			}
			return diff1 < diff2
		})

		fmt.Fprintln(out, ress[0])
	}
}

package main

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

func diff(a, b string) int {
	tot := 0
	for i := 0; i < len(a); i++ {
		if string(a[i]) != string(b[i]) {
			tot++
		}
	}
	return tot
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		if n%7 == 0 {
			fmt.Fprintln(w, n)
		} else {
			s := strconv.Itoa(n)
			o := []string{}
			for i := 10; i < 1000; i++ {
				if i%7 == 0 {
					a := strconv.Itoa(i)
					o = append(o, a)
				}
			}
			mn, ans := 1000, ""
			for i := 0; i < len(o); i++ {
				p := 0
				if len(o[i]) == len(s) {
					p = diff(o[i], s)
				} else {
					continue
				}
				if p < mn {
					mn, ans = p, o[i]
				}
			}
			fmt.Fprintln(w, ans)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import "fmt"

func differentBetweenString(a, b string) int {
	var count int
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			count++
		}
	}
	return count
}

func main() {
	var N int
	fmt.Scanln(&N)
	for i := 0; i < N; i++ {
		var a int
		fmt.Scanln(&a)
		if a%7 == 0 {
			fmt.Println(a)
		} else {
			max := 4
			result := 0
			diff := 0
			if a/10 < 1 {
				fmt.Println(7)
			} else if a/10 < 10 {
				for j := 10; j < 100; j++ {
					diff = differentBetweenString(fmt.Sprintf("%d", j), fmt.Sprintf("%d", a))
					if j%7 == 0 && diff < max {
						max = diff
						result = j
					}
				}
			} else {
				for j := 100; j < 1000; j++ {
					diff = differentBetweenString(fmt.Sprintf("%d", j), fmt.Sprintf("%d", a))
					if j%7 == 0 && diff < max {
						max = diff
						result = j
					}
				}
			}
			fmt.Println(result)
		}
	}

}

// generated by 1e9y at 31-01-2022
// template version: 2022-01-11

package main

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

// 0000.A
func solve(n int) int {
	if n%7 == 0 {
		return n
	}
	start := n / 10
	for i := start * 10; i < start*10+10; i++ {
		if i%7 == 0 {
			return i
		}
	}
	panic("no solution")
}

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

	t := ReadInt(in)
	for i := 0; i < t; i++ {
		n := ReadInt(in)
		Output(solve(n))
	}
}

// helpers for convenient input reading

func ReadInt(in *bufio.Reader) int {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	n, _ := strconv.Atoi(line)
	return n
}

func ReadLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	return line
}

func ReadLineParts(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	parts := strings.Split(line, " ")
	return parts
}

func ReadIntSlice(in *bufio.Reader) []int {
	parts := ReadLineParts(in)
	slice := make([]int, len(parts))
	for i, n := range parts {
		slice[i] = MustAtoi(n)
	}
	return slice
}

func ReadInt64Slice(in *bufio.Reader) []int64 {
	parts := ReadLineParts(in)
	slice := make([]int64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseInt(n, 10, 64)
	}
	return slice
}

func ReadUint64Slice(in *bufio.Reader) []uint64 {
	parts := ReadLineParts(in)
	slice := make([]uint64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseUint(n, 10, 64)
	}
	return slice
}

func MustAtoi(s string) int {
	v, _ := strconv.Atoi(s)
	return v
}

func MustParseInt(s string, base, bitSize int) int64 {
	v, _ := strconv.ParseInt(s, base, bitSize)
	return v
}

func MustParseUint(s string, base, bitSize int) uint64 {
	v, _ := strconv.ParseUint(s, base, bitSize)
	return v
}

func SkipLine(in *bufio.Reader) {
	_, _ = in.ReadString('\n')
}

// helper for convenient answer output

func Output(v interface{}) {
	switch v.(type) {
	case bool:
		if v == true {
			Println("YES")
		} else {
			Println("NO")
		}
	default:
		Println(v)
	}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{

		reminder=inputs[i]%7
		if inputs[i]%10<reminder {
			outputs[i]=inputs[i]-reminder+7
		} else{

		outputs[i]=inputs[i]-reminder
		}

		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{

		reminder=inputs[i]%7
		if reminder>3 {
			outputs[i]=inputs[i]-reminder+7
		} else{

		outputs[i]=inputs[i]-reminder
		}

		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{

		reminder=inputs[i]%7
		upper:=inputs[i]-reminder+7
		lower:=inputs[i]-reminder
		if inputs[i]-lower>upper-inputs[i] {
			outputs[i]=inputs[i]-reminder+7
		} else{

		outputs[i]=inputs[i]-reminder
		}

		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{

		reminder=inputs[i]%7
		if reminder >=4{
			outputs[i]=inputs[i]-reminder+7
		} else{

		outputs[i]=inputs[i]-reminder
		}

		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{
		reminder=inputs[i]%7

		outputs[i]=inputs[i]-reminder

		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{
		reminder=inputs[i]%7

		outputs[i]=inputs[i]-reminder+7

		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{
		reminder=inputs[i]%7

		outputs[i]=inputs[i]-reminder+7

		if outputs[i]%11==0{
			outputs[i]=outputs[i]-7
		}
		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{
		reminder=inputs[i]%7

		outputs[i]=inputs[i]-reminder+7

		if outputs[i]%11==0{
			outputs[i]=outputs[i]+7
		}
		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{
		reminder=inputs[i]%7

		outputs[i]=inputs[i]+reminder

		if outputs[i]%11==0{
			outputs[i]=outputs[i]+7
		}
		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{
		reminder=inputs[i]%7

		outputs[i]=inputs[i]-reminder

		if outputs[i]%11==0{
			outputs[i]=outputs[i]+7

		}
		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{
		reminder=inputs[i]%7

		outputs[i]=inputs[i]-reminder

		if outputs[i]%11==0{
			outputs[i]=outputs[i]+7

		}
		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{
		reminder=inputs[i]%7

		outputs[i]=inputs[i]-reminder

		if outputs[i]%11==0{
			outputs[i]=outputs[i]+7

		}
		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d\n",&inputs[i])

	}
	fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{
		reminder=inputs[i]%7

		outputs[i]=inputs[i]-reminder

		if outputs[i]%11==0{
			outputs[i]=outputs[i]+7

		}
		}

}
for _,value :=range outputs{
	fmt.Printf("%d",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d",&inputs[i])

	}
	fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{
		reminder=inputs[i]%7

		outputs[i]=inputs[i]-reminder

		if outputs[i]%11==0{
			outputs[i]=outputs[i]+7

		}
		}

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d",&inputs[i])

	}
	fmt.Scanf("\n")
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{
		reminder=inputs[i]%7

		outputs[i]=inputs[i]-reminder

		if outputs[i]%11==0{
			outputs[i]=outputs[i]+7

		}
		}

}
for _,value :=range outputs{
	fmt.Println(value)
}
}

package main

import (
	"fmt"
)

func main() {

	var size int

	fmt.Scanf("%d",&size)
	outputs:=make([]int ,size)

	inputs:=make([]int ,size)

	for i:=0;i<size;i++{

		fmt.Scanf("%d",&inputs[i])

	}
	for i:=0;i<size;i++{
		var reminder int
		if inputs[i]%7==0{
			outputs[i]=inputs[i]
		}else{
		reminder=inputs[i]%7

		outputs[i]=inputs[i]-reminder

		if outputs[i]%11==0{
			outputs[i]=outputs[i]+7

		}
		}

}
for _,value :=range outputs{
	fmt.Println(value)
}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i:=0; i < n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		fmt.Printf("%d\n", x)
		if x % 7 != 0 {
			x -= x % 10
			for j:= 1; j < 10; j++ {
				if (x + j) % 7 == 0 {
					x += j
					break
				}
			}
		}
		fmt.Printf("%d\n", x)
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i:=0; i < n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		if x % 7 != 0 {
			x -= x % 10
			for j:= 1; j < 10; j++ {
				if (x + j) % 7 == 0 {
					x += j
					break
				}
			}
		}
		// fmt.Printf("%d\n", x)
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i:=0; i < n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		if x % 7 != 0 {
			x -= x % 10
			for j:= 1; j < 10; j++ {
				if (x + j) % 7 == 0 {
					x += j
					break
				}
			}
		}
		fmt.Printf("%d\n", x)
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i:=0; i < n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		if x % 7 != 0 {
			x -= x % 10
			for j:= 1; j < 10; j++ {
				if (x + j) % 7 == 0 {
					x += j
					break
				}
			}
		}
		fmt.Println(x)
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i:=0; i < n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		if x % 7 != 0 {
			x -= x % 10
			for j:= 1; j < 10; j++ {
				if (x + j) % 7 != 0 {
					x += j
					break
				}
			}
		}
		fmt.Println(x)
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i:=0; i < n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		if x % 7 != 0 {
			x -= x % 10
			for j:= 0; j < 10; j++ {
				if (x + j) % 7 != 0 {
					break;
				}
			}
		}
		fmt.Print("%d\n", x)
	}
}

package main
import(
    "fmt"
    "strconv"
    "math"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Scan(&x)
		if x%7 == 0 {
			fmt.Println(x)
		} else {
			len:= len(strconv.Itoa(x))
			x-= (x/x_power_y(10,len-1))
			for j:=0;j<10;j++{
				if (x+j)%7 == 0 {
					fmt.Println(x+j)
					break
				}
			}
		}
	}
}
func x_power_y(x,y int) int {
	//dependencies math
	return int(math.Pow(float64(x),float64(y)))
}

package main
import(
    "fmt"
    "strconv"
    "math"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Scan(&x)
		if x%7 == 0 {
			fmt.Println(x)
			continue
		} else {
			len:= len(strconv.Itoa(x))
			x-= (x/x_power_y(10,len-1))
			for j:=0;j<10;j++{
				if (x+j)%7 == 0 {
					fmt.Println(x+j)
					continue
				}
			}
		}
	}
}
func x_power_y(x,y int) int {
	//dependencies math
	return int(math.Pow(float64(x),float64(y)))
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Scan(&x)
		if x%7 == 0 {
			fmt.Println(x)
			continue
		} else {
			x=((x/7)+1)*7
		}
		fmt.Println(x)
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Scan(&x)
		if x%7 == 0 {
			fmt.Println(x)
			break
		} else {
			x=((x/7)+1)*7
		}
		fmt.Println(x)
	}
}

package main

import (
	"fmt"
)

func main() {
	var n, x int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x)
		if x%7 == 0 {
			fmt.Println(x)
		} else {
			fmt.Println((x/7 + 1) * 7)
		}
	}
}

// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools

// To modify the template, go to Preferences -> Editor -> File and Code Templates -> Other

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var num int
		fmt.Scan(&num)
		if num%7 == 0 {
			fmt.Println(num)
			continue
		}
		n := num / 7
		result := n * 7
		if result%10 == num%10 {
			fmt.Println(result)
		} else {
			fmt.Println(result + 7)
		}
	}
}

package main

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

type CF1633A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1633A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1633A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1633A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1633A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1633A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1633A
Date: 7/02/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1633/A
Problem: CF1633A
**/
func (in *CF1633A) Run() {
	for t := in.NextInt(); t > 0; t-- {

		n := in.NextInt()
		ans := -1
		diff := 100000
		for i := n; i > 9; i-- {
			if i%7 == 0 {
				if ans != -1 {
					if diff > dif(fmt.Sprintf("%d", i), fmt.Sprintf("%d", ans)) {
						diff = dif(fmt.Sprintf("%d", i), fmt.Sprintf("%d", ans))
						ans = i
					}
				} else {
					diff = dif(fmt.Sprintf("%d", i), fmt.Sprintf("%d", n))
					ans = i
				}
			}
		}

		for i := n + 1; i < 5000; i++ {
			if i%7 == 0 {
				if ans != -1 {
					if diff > dif(fmt.Sprintf("%d", i), fmt.Sprintf("%d", ans)) {
						diff = dif(fmt.Sprintf("%d", i), fmt.Sprintf("%d", ans))
						ans = i
					}
				} else {
					diff = dif(fmt.Sprintf("%d", i), fmt.Sprintf("%d", n))
					ans = i
				}

			}
		}
		fmt.Println(ans)
	}
}

func dif(a, b string) int {
	ans := 0

	for i := 0; i < int(math.Min(float64(len(a)), float64(len(b)))); i++ {
		if a[i] != b[i] {
			ans++
		}
	}

	if len(a)-len(b) != 0 {
		ans += int(math.Abs(float64(len(a) - len(b))))
	}

	return ans
}

func NewCF1633A(r *bufio.Reader) *CF1633A {
	return &CF1633A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1633A(bufio.NewReader(os.Stdin)).Run()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	b := strings.Builder{}
	for i := 0; i < t; i++ {
		b.WriteString(solve(in) + "\n")
	}
	fmt.Println(b.String())
}

func solve(in *bufio.Reader) string {
	n := readInt(in)
	mod := n % 7
	if mod == 0 {
		return strconv.Itoa(n)
	} else {
		r := n % 10
		if r + 7 - mod < 10 {
			return strconv.Itoa(n + 7 - mod)
		} else {
			return strconv.Itoa(n + mod - 7)
		}
	}
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

package main

import "fmt"

func main() {
	var testCases int
	fmt.Scanln(&testCases)
	for testCase := 0; testCase < testCases; testCase++ {
		var n int
		fmt.Scanln(&n)
		m7 := n % 7
		m10 := n % 10
		if m7 < m10 {
			fmt.Println(n - m7)
		} else {
			fmt.Println(n - m7 + 7)
		}
	}
}

package main

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

/*
241
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	var t = 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		if n%7 == 0 {
			fmt.Fprintln(writer, n)
		} else {
			base := n / 10 * 10
			for i := 0; i < 10; i++ {
				num := base + 1
				if num%7 == 0 {
					fmt.Fprintln(writer, num)
					break
				}
			}
		}
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

func digits(a int) int {
	if a <= 9 {
		return 1
	}
	return 1 + digits(a/10)
}

func diff(a, b int) int {
	ans := 0
	if a%10 != b%10 {
		ans++
	}
	a /= 10
	b /= 10
	if a%10 != b%10 {
		ans++
	}
	a /= 10
	b /= 10
	if a%10 != b%10 {
		ans++
	}
	return ans
}

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var n int
		scan(&n)

		ans := 7
		ansDiff := diff(n, 7)
		digitsn := digits(n)

		for x := 7; x <= 999; x += 7 {
			xDiff := diff(x, n)
			if digits(x) == digitsn && xDiff < ansDiff {
				ansDiff = xDiff
				ans = x
			}
		}
		printf("%d\n", ans)
	}
}