Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), " ")
		s, _ := strconv.Atoi(input[0])
		e, _ := strconv.Atoi(input[1])
		a := make([]int, 0)
		if s <= 5 {
			if s > e {
				for j := s; j > e-1; j-- {
					a = append(a, j)
				}
			} else {
				for j := s; j < e+1; j++ {
					a = append(a, j)
				}
			}
		} else if s < e {
			for j := s; j < 10; j++ {
				a = append(a, j)
			}
		} else {
			for j := s; j < 10; j++ {
				a = append(a, j)
			}
			if e <= 5 {
				for j := 5; j > e-1; j-- {
					a = append(a, j)
				}
			} else {
				for j := 5; j > 0; j-- {
					a = append(a, j)
				}
				for j := 0; j < e+1; j++ {
					a = append(a, j)
				}
			}
		}
		for i, v := range a {
			if i != len(a)-1 {
				fmt.Printf("%d ", v)
			} else {
				fmt.Println(v)
			}
		}
	}
}

Python: dic = {}
for i in range(10):
  for j in range(10):
    if i < j:
      dic[(i, j)] = list(range(i, j + 1))
    elif i > j:
      if i <= 5:
        dic[(i, j)] = list(range(i, j - 1, -1))
      elif j <= 5:
        dic[(i, j)] = list(range(i, 10)) + list(range(5, j - 1, -1))
      else:
        dic[(i, j)] = list(range(i, 10)) + list(range(5, -1, -1)) + list(range(1, j + 1))


n = int(input())
for _ in range(n):
  s, g = map(int, input().split())
  print(*dic[(s, g)])

Python: A = "012345678954321012345678"
B = "6789543210123456789"
n = int(input())
for i in range(n):
    a, b = input().split()
    if int(a) < int(b):
        print(" ".join(A[A.index(a):A.index(b,A.index(a))+1]))
    else:
        print(" ".join(B[B.index(a):B.index(b,B.index(a))+1]))

Python: for i in range(int(input())):
    s, e = map(int, input().split())
    a = []
    if s <= 5:
        if s > e:
            [a.append(i) for i in range(s, e - 1, -1)]
        else:
            [a.append(i) for i in range(s, e + 1)]
    elif s < e:
        [a.append(i) for i in range(s, e + 1)]
    else:
        [a.append(i) for i in range(s, 10)]
        if e <= 5:
            [a.append(i) for i in range(5, e - 1, -1)]
        else:
            [a.append(i) for i in range(5, 0, -1)]
            [a.append(i) for i in range(0, e + 1)]
    print(*a)

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0140

"""
import sys
from sys import stdin
from enum import Enum
input = stdin.readline


class Graph(object):
    """ single source shortest path """
    class Status(Enum):
        """ ?????????????¨??????¶??? """
        white = 1  # ????¨????
        gray = 2  # ?¨???????
        black = 3  #?¨???????

    def __init__(self, data):
        num_of_nodes = len(data)
        self.color = [Graph.Status.white] * num_of_nodes  # ????????????????¨??????¶???
        self.M = [[float('inf')] * num_of_nodes for _ in range(num_of_nodes)]
        self._make_matrix(data)  # data????????????????????£??\??????(?????\?¶???¨???????????????????????§????????????)
        self.d = [float('inf')] * num_of_nodes  # ?§???????????????????(?????????)
        self.p = [-1] * num_of_nodes  # ????????????????????????????¨?????????????????????????

    def _make_matrix(self, data):
        for f, t, c in data:
            self.M[f][t] = c


    def dijkstra(self, start):
        self.d[start] = 0
        self.p[start] = -1

        while True:
            mincost = float('inf')
            # ??\??????????????§??????????????¨?????????????????????u???????????????
            for i in range(len(self.d)):
                if self.color[i] != Graph.Status.black and self.d[i] < mincost:  # S????±???????????????????S??¨??\?¶?????????????????????????????????????????°???????????????????
                    mincost = self.d[i]
                    u = i  # u??????????????????ID

            if mincost == float('inf'):
                break

            self.color[u] = Graph.Status.black  # ?????????u???S????±???????????????´???

            for v in range(len(self.d)):
                if self.color[v] != Graph.Status.black and self.M[u][v] != float('inf'):
                    # v????????????????????????????????°??????S???????????£???u????????????????????????????????????????????°??????????????±??§??´??°??????
                    if self.d[u] + self.M[u][v] < self.d[v]:
                        self.d[v] = self.d[u] + self.M[u][v]
                        self.p[v] = u
                        self.color[v] = Graph.Status.gray


def main(args):
    data = []
    # from, to, cost
    data.append([0, 1, 10])
    data.append([1, 2, 10])
    data.append([2, 3, 10])
    data.append([3, 4, 10])
    data.append([4, 5, 10])
    data.append([5, 6, 10])
    data.append([6, 7, 10])
    data.append([7, 8, 10])
    data.append([8, 9, 10])
    data.append([9, 5, 10])
    data.append([5, 4, 10])
    data.append([4, 3, 10])
    data.append([3, 2, 10])
    data.append([2, 1, 10])
    data.append([1, 0, 10])

    n = int(input())
    for _ in range(n):
        start, goal = map(int, input().split())
        g = Graph(data)

        g.dijkstra(start)

        path = [goal]
        u = goal
        while g.p[u] != start:
            path.append(g.p[u])
            u = g.p[u]
        path.append(start)
        path.reverse()

        print(' '.join(map(str, path)))


if __name__ == '__main__':
    main(sys.argv[1:])

Python: # -*- coding: utf-8 -*-

import sys
import os

N = int(input())

for i in range(N):
    a, b = map(int, input().split())
    if a < b:
        lst = [j for j in range(a, b+1)]
        print(*lst)

    # a > b
    else:
        # easy
        if a <= 5:
            lst = [j for j in range(a, b - 1, -1)]
        else:
            lst = [j for j in range(a, 9+1)] + [j for j in range(5, b - 1, -1)]
        print(*lst)

Python: def printAns(ans):
    for i in range(len(ans)):
        if i == 0:
            print(ans[i], end="")
        else:
            print(" ", end="")
            print(ans[i], end="")
    print("")

N = int(input())

for l in range(N):
    a,b = [int(i) for i in input().split()]

    ans = []
    if a < b:
        for i in range(a, b+1):
            ans.append(i)
    else: # a > b
        if a <= 5:
            for i in range(a, b-1, -1):
                ans.append(i)
        else:
            if b <= 5:
                for i in range(a, 10):
                    ans.append(i)
                for i in range(5, b-1, -1):
                    ans.append(i)
            else:
                for i in range(a, 10):
                    ans.append(i)
                for i in range(5, 0, -1):
                    ans.append(i)
                for i in range(b+1):
                    ans.append(i)

    printAns(ans)

Python: # AOJ 0140 Bus Line
# Python3 2018.6.23 bal4u

for i in range(int(input())):
	s, e = map(int, input().split())
	if s <= 5:
		if s > e: [print(i, end=' ') for i in range(s,e-1,-1)]
		else: [print(i, end=' ') for i in range(s,e+1)]
	elif s < e: [print(i, end=' ') for i in range(s,e+1)]
	else:
		ans = []
		for j in range(s, 10): ans.append(j)
		if e <= 5:
			for j in range(5, e-1, -1): ans.append(j)
		else:
			for j in range(5, 0, -1): ans.append(j)
			for j in range(0, e+1): ans.append(j)
		print(*ans, end='')
	print()