A sequence of round and square brackets is given. You can change the sequence by performing the following operations:  change the direction of a bracket from opening to closing and vice versa without changing the form of the bracket: i.e. you can change '(' to ')' and ')' to '('; you can change '[' to ']' and ']' to '['. The operation costs $$$0$$$ burles. change any square bracket to round bracket having the same direction: i.e. you can change '[' to '(' but not from '(' to '['; similarly, you can change ']' to ')' but not from ')' to ']'. The operation costs $$$1$$$ burle. The operations can be performed in any order any number of times.You are given a string $$$s$$$ of the length $$$n$$$ and $$$q$$$ queries of the type "l r" where $$$1 \le l < r \le n$$$. For every substring $$$s[l \dots r]$$$, find the minimum cost to pay to make it a correct bracket sequence. It is guaranteed that the substring $$$s[l \dots r]$$$ has an even length.The queries must be processed independently, i.e. the changes made in the string for the answer to a question $$$i$$$ don't affect the queries $$$j$$$ ($$$j > i$$$). In other words, for every query, the substring $$$s[l \dots r]$$$ is given from the initially given string $$$s$$$.A correct bracket sequence is a sequence that can be built according the following rules:  an empty sequence is a correct bracket sequence;  if "s" is a correct bracket sequence, the sequences "(s)" and "[s]" are correct bracket sequences.  if "s" and "t" are correct bracket sequences, the sequence "st" (the concatenation of the sequences) is a correct bracket sequence. E.g. the sequences "", "(()[])", "[()()]()" and "(())()" are correct bracket sequences whereas "(", "[(])" and ")))" are not.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. For each test case, the first line contains a non-empty string $$$s$$$ containing only round ('(', ')') and square ('[', ']') brackets. The length of the string doesn't exceed $$$10^6$$$. The string contains at least $$$2$$$ characters. The second line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ lines follow, each of them contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le n$$$ where $$$n$$$ is the length of $$$s$$$). It is guaranteed that the substring $$$s[l \dots r]$$$ has even length. It is guaranteed that the sum of the lengths of all strings given in all test cases doesn't exceed $$$10^6$$$. The sum of all $$$q$$$ given in all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case output in a separate line for each query one integer $$$x$$$ ($$$x \ge 0$$$) — the minimum cost to pay to make the given substring a correct bracket sequence.

NoteConsider the first test case. The first query describes the whole given string, the string can be turned into the following correct bracket sequence: "([()])()[[]]". The forms of the brackets aren't changed so the cost of changing is $$$0$$$.The second query describes the substring ")[)()]". It may be turned into "(()())", the cost is equal to $$$2$$$.The third query describes the substring "))[)". It may be turned into "()()", the cost is equal to $$$1$$$.The substrings of the second test case contain only round brackets. It's possible to prove that any sequence of round brackets having an even length may be turned into a correct bracket sequence for the cost of $$$0$$$ burles.In the third test case, the single query describes the string "[]" that is already a correct bracket sequence.

package main

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

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

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

  var t int
  for fmt.Fscan(reader, &t); t > 0; t-- {
    var s string
    fmt.Fscan(reader, &s)
    n := len(s)
    pref := make([]int, n+1)
    pref[0] = 0;
    for i:= 0; i < n; i++ {
      pref[i+1] = pref[i]
      if s[i] == '[' || s[i] == ']' {
        if i&1 > 0 {
          pref[i+1]++
        } else {
          pref[i+1]--
        }
      }
    }
    var q int
    fmt.Fscan(reader, &q)
    for ; q > 0; q-- {
      var l, r int
      fmt.Fscan(reader, &l, &r)
      fmt.Fprint(writer, abs(pref[r]-pref[l-1]), "\n")
    }
  }
}

package main

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

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

	var T, q, l, r int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &s, &q)
		sum := make([]int, len(s)+1)
		for i, b := range s {
			sum[i+1] = sum[i]
			if b < 42 {
				sum[i+1] += i&1<<1 - 1
			}
		}
		for ; q > 0; q-- {
			Fscan(in, &l, &r)
			Fprintln(out, abs(sum[r]-sum[l-1]))
		}
	}
}

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

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


Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.

The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets.

Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.

package main
import (
	"fmt"
	"sort"
)
func main() {
	var n,m int
	a:=0
	fmt.Scan(&n,&m)
	v:=make([]int,n)
	for i:=0;i<n;i++ {
		fmt.Scan(&v[i])
	}
	sort.Ints(v)
	for i:=0;i<m && v[i]<0;i++ {
		a-=v[i]
	}
	fmt.Println(a)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	inputs := make([]int, n)
	for i:=0; i<n; i++ {
		fmt.Scan(&inputs[i])
	}
	sort.Ints(inputs)
	ans := 0
	for i:=0; i<m; i++ {
		if inputs[i] < 0 {
			ans -= inputs[i]
		} else {
			break
		}
	}
	fmt.Println(ans)
}

package main

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

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

	array := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan() && i < n; i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		array[i] = a
	}

	merge_sort(array, 0, n-1)

	earn := 0
	for i := 0; i < m; i++ {
		if array[i] < 0 {
			earn -= array[i]
		} else {
			break
		}
	}

	fmt.Println(earn)
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] <= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var n,m int
    fmt.Scan(&n,&m)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    sort.Ints(a)
    ans := 0
    for i := 0; (i < n) && (a[i] < 0) && (m > 0); i++ {
        ans += (-a[i])
        m--
    }
    fmt.Println(ans)
}

package main

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

func getInput() (int, int, []int) {
  scanner := bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  scanner.Scan()
  n, _ := strconv.Atoi(scanner.Text())
  scanner.Scan()
  m, _ := strconv.Atoi(scanner.Text())
  arr := make([]int,n);
  for i:=0; i<n; i++ {
    scanner.Scan()
    v, _ := strconv.Atoi(scanner.Text());
    arr[i] = v
  }
  return  n, m, arr
}

func main() {
 _, m, arr := getInput()
 sort.Ints(arr)
 sum := 0;
 for i:=0; i<m && arr[i]<0 ; i++ {
    sum += arr[i];
 }
 fmt.Println(-sum)
}

package main

import (
	"fmt"
	"math"
	"sort"
)

func main(){
	var n,m int
	fmt.Scanf("%d %d\n",&n,&m)
	a := make([]int,n)
	for i:= range a{
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	var earn int
	for i:=0;i<m;i++{
		if a[i]<0{
			earn+=a[i]
		}
	}
	fmt.Println(math.Abs(float64(earn)))
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t, m int
	fmt.Scan(&t, &m)

	tvArray := make([]int, t)
	for i := 0; i < t; i++ {
		fmt.Scan(&tvArray[i])
	}

	sort.Ints(tvArray)
	counter := 0
	money := 0
	for ; m > 0; m-- {
		if tvArray[counter] <= 0 {
			money += tvArray[counter]
		}
		counter++
	}

	if money > 0 {
		fmt.Print(0)
	} else {
		fmt.Print(-money)
	}

}

// 34B-mic
package main

import (
    "fmt"
    "sort"
)

func main() {
    var n, m int
    a := make([]int, 1001)
    fmt.Scan(&n, &m)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    sum := 0
    sort.Sort(sort.IntSlice(a))
    for j := 0; j < m; j++ {
        if a[j] >= 0 {
            break
        }
        sum += a[j]
    }
    fmt.Println(-1 * sum)
}

// cf34b project main.go
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	sort.Ints(a)
	s := 0
	for i := 0; i < m && a[i] < 0; i++ {
		s += a[i] * (-1)
	}
	fmt.Println(s)
}

package main

import (
	"fmt"
	"math"
	"sort"
)

func main(){
	var n,m int
	fmt.Scanf("%d %d\n",&n,&m)
	a := make([]int,n)
	for i:= range a{
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	var earn int
	for i:=0;i<m;i++{
		earn+=a[i]
	}
	fmt.Println(math.Abs(float64(earn)))
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	var a []int
	for i := 0; i < n; i++ {
		var ai int
		fmt.Scanf("%d", &ai)
		a = append(a, ai)
	}
	sort.Ints(a)
	s := 0
	for i := 0; i < m && a[i] < 0; i++ {
		s += a[i] * (-1)
	}
	fmt.Println(s)
}

package main

import (
	"fmt"
)

func main() {
	var n, m, s int
	fmt.Scan(&n, &m)
	var a []int
	for i := 0; i < n; i++ {
		var ai int
		fmt.Scanf("%d", &ai)
		a = append(a, ai)
	}
	for i := n - 1; i >= 0; i-- {
		for j := 0; j < i; j++ {
			if a[j] > a[j+1] {
				a[j], a[j+1] = a[j+1], a[j]
			}
		}
	}

	for i := 0; i < m && a[i] < 0; i++ {
		s += a[i]
	}
	fmt.Println(s)
}

// cf34b project main.go
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	var a []int
	for i := 0; i < n; i++ {
		var ai int
		fmt.Scanf("%d", &ai)
		a = append(a, ai)
	}
	for i := n - 1; i >= 0; i-- {
		for j := 0; j < i; j++ {
			if a[j] > a[j+1] {
				tmp := a[j]
				a[j] = a[j+1]
				a[j+1] = tmp
			}
		}
	}
	s := 0
	for i := 0; i < m && a[i] < 0; i++ {
		s += a[i] * (-1)
	}
	fmt.Println(s)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	var a []int
	for i := 0; i < n; i++ {
		var ai int
		fmt.Scanf("%d", &ai)
		a = append(a, ai)
	}
	for i := n - 1; i >= 0; i-- {
		for j := 0; j < i; j++ {
			if a[j] > a[j+1] {
				a[j], a[j+1] = a[j+1], a[j]
			}
		}
	}
	s := 0
	for i := 0; i < m && a[i] < 0; i++ {
		s += a[i] * (-1)
		if a[i] == 7 {
			fmt.Println(a)
		}
	}
	fmt.Println(s)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var a []int
	for i := 0; i < n; i++ {
		var ai int
		fmt.Scanf("%d", &ai)
		a = append(a, ai)
	}
	fmt.Println(a)
	for i := n - 1; i >= 0; i-- {
		for j := 0; j < i; j++ {
			if a[j] > a[j+1] {
				a[j], a[j+1] = a[j+1], a[j]
			}
		}
	}
	s := 0
	for i := 0; i < m && a[i] < 0; i++ {
		s += a[i] * (-1)
	}
	fmt.Println(s)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	var a []int
	for i := 0; i < n; i++ {
		var ai int
		fmt.Scanf("%d", &ai)
		a = append(a, ai)
	}
	for i := n - 1; i >= 0; i-- {
		for j := 0; j < i; j++ {
			if a[j] > a[j+1] {
				a[j], a[j+1] = a[j+1], a[j]
			}
		}
	}
	s := 0
	for i := 0; i < m && a[i] < 0; i++ {
		s += a[i] * (-1)
	}
	fmt.Println(s, a)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	var a []int
	for i := 0; i < n; i++ {
		var ai int
		fmt.Scanf("%d", &ai)
		a = append(a, ai)
	}
	for i := n - 1; i >= 0; i-- {
		for j := 0; j < i; j++ {
			if a[j] > a[j+1] {
				a[j], a[j+1] = a[j+1], a[j]
			}
		}
	}
	s := 0
	for i := 0; i < m && a[i] < 0; i++ {
		s += a[i] * (-1)
	}
	fmt.Println(s)
}

// cf34b project main.go
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	var a []int
	for i := 0; i < n; i++ {
		var ai int
		fmt.Scanf("%d", &ai)
		a = append(a, ai)
	}
	for i := n - 1; i >= 0; i-- {
		for j := 0; j < i; j++ {
			if a[j] > a[j+1] {
				a[j], a[j+1] = a[j+1], a[j]
			}
		}
	}
	s := 0
	if m == 2 {
		fmt.Println(a)
	}
	for i := 0; i < m && a[i] < 0; i++ {
		s += a[i] * (-1)
	}
	fmt.Println(s)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var a []int
	for i := 0; i < n; i++ {
		var ai int
		fmt.Scanf("%d", &ai)
		a = append(a, ai)
	}
	for i := n - 1; i >= 0; i-- {
		for j := 0; j < i; j++ {
			if a[j] > a[j+1] {
				a[j], a[j+1] = a[j+1], a[j]
			}
		}
	}
	s := 0
	for i := 0; i < m && a[i] < 0; i++ {
		s += a[i] * (-1)
	}
	fmt.Println(s)
}

package main

import (
	"fmt"
)

func main() {
	var n, m, s int
	fmt.Scan(&n, &m)
	var a []int
	for i := 0; i < n; i++ {
		var ai int
		fmt.Scanf("%d", &ai)
		a = append(a, ai)
	}
	for i := n - 1; i >= 0; i-- {
		for j := 0; j < i; j++ {
			if a[j] > a[j+1] {
				a[j], a[j+1] = a[j+1], a[j]
			}
		}
	}

	for i := 0; i < m && a[i] < 0; i++ {
		s += a[i] * (-1)
	}
	fmt.Println(s)
}


You have a large electronic screen which can display up to $$$998244353$$$ decimal digits. The digits are displayed in the same way as on different electronic alarm clocks: each place for a digit consists of $$$7$$$ segments which can be turned on and off to compose different digits. The following picture describes how you can display all $$$10$$$ decimal digits:As you can see, different digits may require different number of segments to be turned on. For example, if you want to display $$$1$$$, you have to turn on $$$2$$$ segments of the screen, and if you want to display $$$8$$$, all $$$7$$$ segments of some place to display a digit should be turned on.You want to display a really large integer on the screen. Unfortunately, the screen is bugged: no more than $$$n$$$ segments can be turned on simultaneously. So now you wonder what is the greatest integer that can be displayed by turning on no more than $$$n$$$ segments.Your program should be able to process $$$t$$$ different test cases.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow, each of them is represented by a separate line containing one integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the maximum number of segments that can be turned on in the corresponding testcase. It is guaranteed that the sum of $$$n$$$ over all test cases in the input does not exceed $$$10^5$$$.

For each test case, print the greatest integer that can be displayed by turning on no more than $$$n$$$ segments of the screen. Note that the answer may not fit in the standard $$$32$$$-bit or $$$64$$$-bit integral data type.

package main

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

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	t := scanInt()

	for i := 0; i < t; i++ {
		n := scanInt()
		if n>2 && n%2==1 {
			fmt.Fprint(wr,"7")
			n-=3
		}
		for j := 0; j < n/2; j++ {
			fmt.Fprint(wr,"1")
		}
		fmt.Fprintln(wr)
		wr.Flush()
	}
}

package main

import (
	"fmt"
	"strings"
)

func FindNumber(segments int32) string {
	res := make([]string, 0, 100)
	ones := int(segments) / 2
	sevens := int(segments) % 2

	if sevens == 1 {
		ones -= 1
	}

	for i := 0; i < sevens; i++ {
		res = append(res, "7")
	}

	for i := 0; i < ones; i++ {
		res = append(res, "1")
	}

	return strings.Join(res, "")
}

func main() {
	var t, n int32

	fmt.Scanf("%d\n", &t)

	for i := int32(0); i < t; i++ {
		fmt.Scanf("%v\n", &n)
		fmt.Printf("%v\n", FindNumber(n))
	}
}

package main

import (
	"fmt"
	"strings"
)

type pair struct {
	s, o int
}

func main() {
	var t int
	fmt.Scan(&t)
	ans := make([]pair, 0)
	for i := 0; i < t; i++ {
		var n int
		var p pair
		fmt.Scan(&n)
		if n == 2 {
			p.o = 1
		} else if n == 3 {
			p.s = 1
		} else {
			p.o = 1
			n -= 2
			for n >= 2 {
				// fmt.Println("n", n)
				if n == 3 {
					p.s = 1
				} else {
					p.o++
				}
				n -= 2
			}
		}
		ans = append(ans, p)
	}
	for i := 0; i < len(ans); i++ {
		fmt.Println(strings.Repeat("7", ans[i].s) + strings.Repeat("1", ans[i].o))
	}
}

package main

import "fmt"

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

	for i := 0; i < q; i++ {
		var n int
		fmt.Scan(&n)

		ones := n / 2

		if n%2 == 1 {
			fmt.Print("7")
			ones--
		}

		for j := 0; j < ones; j++ {
			fmt.Print("1")
		}

		fmt.Println()
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t, n int
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscanln(reader, &n)
		var result strings.Builder
		ones_count := n / 2
		if n%2 == 1 {
			result.WriteString("7")
			ones_count -= 1
		}
		for ; ones_count > 0; ones_count-- {
			result.WriteString("1")
		}
		fmt.Fprintln(writer, result.String())
	}
}

package main

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

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

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		if n&1 == 0 {
			Fprintln(out, Repeat("1", n/2))
		} else {
			Fprintln(out, "7"+Repeat("1", (n-3)/2))
		}
	}
}

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

package main

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

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		n := readi()
		println(solve(n))
	}

}

func solve(n int) string {
	res := make([]byte, 0, n/2)
	if n%2 == 1 {
		res = append(res, '7')
		n -= 3
	}
	for i := 0; i < n/2; i++ {
		res = append(res, '1')
	}
	return string(res)
}

package main

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

const (
	MX_INT int64 = math.MaxInt64
	MN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		r := []rune{}

		if n % 2 != 0 {
		    r = append(r, '7')
		    for i := int64(1); i < n/2; i++ {
    		    r = append(r, '1')
    		}
		} else {
		    for i := int64(0); i < n/2; i++ {
		         r = append(r, '1')
		    }
		}

        O <- string(r)
	}
	close(O)
	oWg.Wait()
}

func IsPrime(value int) bool {
	for i := 2; i <= int(math.Floor(float64(value)/2)); i++ {
		if value%i == 0 {
			return false
		}
	}
	return value > 1
}

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

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

func init() {
	Pl = fmt.Println

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

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

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

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

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

func ScanStringSlice(n int64) []string {
	length := int(n)
	s := make([]string, n)
	for i := 0; i < length; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt() int {
	intStr := ScanWord()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int64) []int64 {
	length := int(n)
	arr := make([]int64, n)
	for i := 0; i < length; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func Mx(args ...int64) int64 {
	maxVal := MN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Mn(args ...int64) int64 {
	minVal := MX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

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 S(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    noEx := 0
    fmt.Fscan(in, &noEx)
    for ; noEx>0; noEx-- {
        n := 0
        fmt.Fscan(in, &n)
        var s []string
        for n > 0 {
            if n == 2 {s = append(s, "1"); break}
            if n == 3 {s = append(s, "7"); break}
            s = append(s, "1")
            n -= 2
        }
        for lo,hi:=0,len(s)-1; lo<hi; lo++ {
            s[lo], s[hi] = s[hi], s[lo]
            hi--
        }
        fmt.Fprint(out, strings.Join(s, "") + "\n")
    }
}

package main

import "fmt"

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

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

func main() {
	var t int
	fmt.Scanln(&t)
	for i := 0;i<t ; i++ {
		var n int
		fmt.Scanln(&n)
		if n%2 > 0 {
			fmt.Print("7")
			n -= 3
		}
		for j:=0;j<n/2 ; j++ {
			fmt.Print("1")
		}
		fmt.Println()
	}
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t int
	fmt.Fscan(r, &t)
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		if n%2 == 0 {
			ans[i] = strings.Repeat("1", n/2)
		} else {
			ans[i] = "7" + strings.Repeat("1", (n-3)/2)
		}
	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

// For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the 𝑛 days of summer. On the 𝑖-th day, 𝑎𝑖 millimeters of rain will fall. All values 𝑎𝑖 are distinct.

// The mayor knows that citizens will watch the weather 𝑥 days before the celebration and 𝑦 days after. Because of that, he says that a day 𝑑 is not-so-rainy if 𝑎𝑑 is smaller than rain amounts at each of 𝑥 days before day 𝑑 and and each of 𝑦 days after day 𝑑. In other words, 𝑎𝑑<𝑎𝑗 should hold for all 𝑑−𝑥≤𝑗<𝑑 and 𝑑<𝑗≤𝑑+𝑦. Citizens only watch the weather during summer, so we only consider such 𝑗 that 1≤𝑗≤𝑛.

// Help mayor find the earliest not-so-rainy day of summer.

// Input
// The first line contains three integers 𝑛, 𝑥 and 𝑦 (1≤𝑛≤100000, 0≤𝑥,𝑦≤7) — the number of days in summer, the number of days citizens watch the weather before the celebration and the number of days they do that after.

// The second line contains 𝑛 distinct integers 𝑎1, 𝑎2, ..., 𝑎𝑛 (1≤𝑎𝑖≤109), where 𝑎𝑖 denotes the rain amount on the 𝑖-th day.

// Output
// Print a single integer — the index of the earliest not-so-rainy day of summer. We can show that the answer always exists.

package main

import(
	"fmt"
)

func main() {
	var t int
	var n int
	fmt.Scanf("%d", &t)
	for i := 0; i < t;  i++ {
	fmt.Scanf("\n")
		fmt.Scanf("%d", &n)
		var maxNo = n/2
		var remaining = n%2
		var first int
		if remaining == 1 {
			first = 7
		}else {
			first = 1
		}
		fmt.Print(first)
		for i := 0; i < maxNo - 1; i++ {
			fmt.Print(1)
		}
		fmt.Println()
	}
}

package main

import (
	"fmt"
	"strings"
)

func FindNumber(segments int32) string {
	res := make([]string, 0, 100)
	ones := int(segments) / 2
	sevens := int(segments) % 2

	if sevens == 1 {
		ones -= 1
	}

	for i := 0; i < ones; i++ {
		res = append(res, "1")
	}

	for i := 0; i < sevens; i++ {
		res = append(res, "7")
	}

	return strings.Join(res, "")
}

func main() {
	var t, n int32

	fmt.Scanf("%d\n", &t)

	for i := int32(0); i < t; i++ {
		fmt.Scanf("%v\n", &n)
		fmt.Printf("%v\n", FindNumber(n))
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	ans := make([]int, 0)
	for i := 0; i < t; i++ {
		var n, a int
		fmt.Scan(&n)
		if n == 2 {
			a = 1
		} else if n == 3 {
			a = 7
		} else {
			a = 1
			n -= 2
			for n >= 2 {
				// fmt.Println("n", n)
				if n == 3 {
					a = a*10 + 7
				} else {
					a = a*10 + 1
				}
				n -= 2
			}
		}
		ans = append(ans, a)
	}
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}

package main

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

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

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		if n&1 == 0 {
			Fprintln(out, Repeat("1", n/2))
		} else {
			Fprintln(out, Repeat("1", (n-3)/2)+"7")
		}
	}
}

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

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    noEx := 0
    fmt.Fscan(in, &noEx)
    for ; noEx>0; noEx-- {
        n := 0
        fmt.Fscan(in, &n)
        var s []string
        for n > 0 {
            if n == 2 {s = append(s, "1"); break}
            if n == 3 {s = append(s, "7"); break}
            s = append(s, "1")
            n -= 2
        }
        fmt.Fprint(out, strings.Join(s, "") + "\n")
    }
}

package main

import "fmt"

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

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

func main() {
	var t int
	fmt.Scanln(&t)
	for i := 0;i<t ; i++ {
		var n int
		fmt.Scanln(&n)
		if n <= 20{
			if n%2 > 0 {
				fmt.Print("7")
				n -= 3
			}
			for j:=0;j<n/2 ; j++ {
				fmt.Print("1")
			}
			fmt.Println()
		} else if n >20 && n <60{
			m := (n-24)/4
			for j:=0;j<m ;j++  {
				fmt.Print("9")
			}
			k := (n-24)%4
			for j:=0;j<k ;j++  {
				fmt.Print("7")
			}
			for j:=0;j<n-m-k ;j++  {
				fmt.Print("1")
			}
			fmt.Println()
		} else{
			for j:=0;j<10;j++  {
				fmt.Print("9")
			}
			fmt.Println()
		}
	}
}

// For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the 𝑛 days of summer. On the 𝑖-th day, 𝑎𝑖 millimeters of rain will fall. All values 𝑎𝑖 are distinct.

// The mayor knows that citizens will watch the weather 𝑥 days before the celebration and 𝑦 days after. Because of that, he says that a day 𝑑 is not-so-rainy if 𝑎𝑑 is smaller than rain amounts at each of 𝑥 days before day 𝑑 and and each of 𝑦 days after day 𝑑. In other words, 𝑎𝑑<𝑎𝑗 should hold for all 𝑑−𝑥≤𝑗<𝑑 and 𝑑<𝑗≤𝑑+𝑦. Citizens only watch the weather during summer, so we only consider such 𝑗 that 1≤𝑗≤𝑛.

// Help mayor find the earliest not-so-rainy day of summer.

// Input
// The first line contains three integers 𝑛, 𝑥 and 𝑦 (1≤𝑛≤100000, 0≤𝑥,𝑦≤7) — the number of days in summer, the number of days citizens watch the weather before the celebration and the number of days they do that after.

// The second line contains 𝑛 distinct integers 𝑎1, 𝑎2, ..., 𝑎𝑛 (1≤𝑎𝑖≤109), where 𝑎𝑖 denotes the rain amount on the 𝑖-th day.

// Output
// Print a single integer — the index of the earliest not-so-rainy day of summer. We can show that the answer always exists.

package main

import(
	"fmt"
)

func main() {
	var t int
	var n int
	fmt.Scanf("%d", &t)
	for i := 0; i < t;  i++ {
	fmt.Scanf("\n")
		fmt.Scanf("%d", &n)
		var maxNo = n/2
		var remaining = n%2
		var first int
		if remaining == 1 {
			first = 7
		}else {
			first = 1
		}
		fmt.Print(first)
		for i := 0; i < maxNo - 1; i++ {
			fmt.Print(1)
		}
	}
}

// For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the 𝑛 days of summer. On the 𝑖-th day, 𝑎𝑖 millimeters of rain will fall. All values 𝑎𝑖 are distinct.

// The mayor knows that citizens will watch the weather 𝑥 days before the celebration and 𝑦 days after. Because of that, he says that a day 𝑑 is not-so-rainy if 𝑎𝑑 is smaller than rain amounts at each of 𝑥 days before day 𝑑 and and each of 𝑦 days after day 𝑑. In other words, 𝑎𝑑<𝑎𝑗 should hold for all 𝑑−𝑥≤𝑗<𝑑 and 𝑑<𝑗≤𝑑+𝑦. Citizens only watch the weather during summer, so we only consider such 𝑗 that 1≤𝑗≤𝑛.

// Help mayor find the earliest not-so-rainy day of summer.

// Input
// The first line contains three integers 𝑛, 𝑥 and 𝑦 (1≤𝑛≤100000, 0≤𝑥,𝑦≤7) — the number of days in summer, the number of days citizens watch the weather before the celebration and the number of days they do that after.

// The second line contains 𝑛 distinct integers 𝑎1, 𝑎2, ..., 𝑎𝑛 (1≤𝑎𝑖≤109), where 𝑎𝑖 denotes the rain amount on the 𝑖-th day.

// Output
// Print a single integer — the index of the earliest not-so-rainy day of summer. We can show that the answer always exists.

package main

import(
	"fmt"
)

func main() {
	var t int
	var n int
	fmt.Scanf("%d", &t)
	for i := 0; i < t;  i++ {
		fmt.Scanf("%d", &n)
		var maxNo = n/2
		var remaining = n%2
		var first int
		if remaining == 1 {
			first = 7
		}else {
			first = 1
		}
		fmt.Print(first)
		for i := 0; i < maxNo - 1; i++ {
			fmt.Print(1)
		}
	}
}


You are given an integer $$$n$$$. You have to change the minimum number of digits in it in such a way that the resulting number does not have any leading zeroes and is divisible by $$$7$$$.If there are multiple ways to do it, print any of them. If the given number is already divisible by $$$7$$$, leave it unchanged.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 990$$$) — the number of test cases. Then the test cases follow, each test case consists of one line containing one integer $$$n$$$ ($$$10 \le n \le 999$$$).

For each test case, print one integer without any leading zeroes — the result of your changes (i. e. the integer that is divisible by $$$7$$$ and can be obtained by changing the minimum possible number of digits in $$$n$$$). If there are multiple ways to apply changes, print any resulting number. If the given number is already divisible by $$$7$$$, just print it.

NoteIn the first test case of the example, $$$42$$$ is already divisible by $$$7$$$, so there's no need to change it.In the second test case of the example, there are multiple answers — $$$28$$$, $$$21$$$ or $$$63$$$.In the third test case of the example, other possible answers are $$$357$$$, $$$371$$$ and $$$378$$$. Note that you cannot print $$$077$$$ or $$$77$$$.

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

}

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

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