Go: package main

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

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: def line(i,j):
    retval=[]
    if i<=5 and j<=5:
        if i<j:
            for k in range(i,j+1):
                retval.append(k)
        else:
            for k in range(i,j-1,-1):
                retval.append(k)

    elif i<=5 and j>5:
        for k in range(i,j+1):
            retval.append(k)

    elif i>5 and j>5:
        if i<j:
            for k in range(i,j+1):
                retval.append(k)
        else:
            for k in range(i,10):
                retval.append(k)
            retval+=[5,4,3,2,1,0,1,2,3,4,5]
            for k in range(6,j+1):
                retval.append(k)
    else:
        for k in range(i,10):
            retval.append(k)
        for k in range(5,j-1,-1):
            retval.append(k)


    return " ".join([str(i) for i in retval])

N=int(input())
for i in range(N):
    print(line(*[int(j) for j in input().split(" ")]))

Python: RIGHT_DIRECT = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
LEFT_DIRECT = [6, 7, 8, 9, 5, 4, 3, 2, 1, 0]
ROTATE_DIRECT = [5, 6, 7, 8, 9, 5, 6, 7, 8, 9]

for _ in range(int(input())):

    begin_number, end_number = [int(item) for item in input().split(" ")]

    output = []

    if 5 <= begin_number <= 9 and 5 <= end_number <= 9:

        index = ROTATE_DIRECT.index(begin_number)

        while ROTATE_DIRECT[index] != end_number:
            output.append(ROTATE_DIRECT[index])
            index += 1
        output.append(ROTATE_DIRECT[index])

    elif begin_number < end_number:

        begin_index = RIGHT_DIRECT.index(begin_number)
        end_index = RIGHT_DIRECT.index(end_number)

        for item in RIGHT_DIRECT[begin_index:end_index + 1]:
            output.append(item)

    else:

        begin_index = LEFT_DIRECT.index(begin_number)
        end_index = LEFT_DIRECT.index(end_number)

        for item in LEFT_DIRECT[begin_index:end_index + 1]:
            output.append(item)

    output = [str(item) for item in output]
    print(" ".join(output))

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)]
        elif b <= 5:
            lst = [j for j in range(a, 9+1)] + [j for j in range(5, b - 1, -1)]

        # i.e. 7 -> 6
        else:
            lst = [j for j in range(a, 9 + 1)] + [j for j in range(5, b - 1, -1)] + list(range(0, b+1))
        print(*lst)

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

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



def solve(path, start, goal):
    path_a = [0]*100            #  ???????????????????????????
    path_b = [0]*100

    # ?????????????????¨??????????????????????????????????????°?????§??????????????¢???
    try:
        path_a = path[start][0][:path[start][0].index(goal)+1]
    except ValueError:
        pass
    try:
        path_b = path[start][1][:path[start][1].index(goal)+1]
    except ValueError:
        pass

    # ??????????????????????±???????????????????????????§???start??????goal?????§????????????????????§1??????????????????
    if len(path_a) < len(path_b):
        return ' '.join(map(str, path_a))
    else:
        return ' '.join(map(str, path_b))


def main(args):
    path = []                   #  ?????????n???????????????????????????????????????
    # ?????????[n]???????????????????????????????????????????????¨????????´?????¨??????????????????????????¨????????´????????°??????
    path.append([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], []])                #  0????????????
    path.append([[1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [1, 0]])   #  1
    path.append([[2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [2, 1, 0]])   #  2
    path.append([[3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [3, 2, 1, 0]])   #  3
    path.append([[4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [4, 3, 2, 1, 0]])   #  4
    path.append([[5, 6, 7, 8, 9, 5, 4, 3, 2], [5, 4, 3, 2, 1, 0]])   #  5
    path.append([[6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5], []]) #  6
    path.append([[7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6], []]) #  7
    path.append([[8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7], []]) #  8
    path.append([[9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8], []]) #  9

    n = int(input())
    for _ in range(n):
        start, goal = map(int, input().split())
        result = solve(path, start, goal)
        print(result)


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

Python: n = int(input())

for _ in range(n):
    start, end = map(int, input().split())

    anslist = []
    if start <= 5:
        if start > end:
            [anslist.append(i) for i in range(start, end-1, -1)]
        else:
            [anslist.append(i) for i in range(start, end+1)]
    elif start < end:
        [anslist.append(i) for i in range(start, end+1)]
    else:
        [anslist.append(i) for i in range(start, 10)]
        if end <= 5:
            [anslist.append(i) for i in range(5, end-1, -1)]
        else:
            [anslist.append(i) for i in range(5, 0, -1)]
            [anslist.append(i) for i in range(0, end+1)]

    print(' '.join(str(ans) for ans in anslist))

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

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



def solve(start, goal):
    path = []                   #  ?????????n???????????????????????????????????????
    # ????????????????????¨????????´?????¨????????????????????¨????????´????????°??????
    path.append([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], []])
    path.append([[1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [1, 0]])
    path.append([[2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [2, 1, 0]])
    path.append([[3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [3, 2, 1, 0]])
    path.append([[4, 5, 6, 7, 8, 9, 5, 4, 3, 2], [4, 3, 2, 1, 0]])
    path.append([[5, 6, 7, 8, 9, 5, 4, 3, 2], [5, 4, 3, 2, 1, 0]])
    path.append([[6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5], []])
    path.append([[7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6], []])
    path.append([[8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7], []])
    path.append([[9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8], []])

    path_a = [0]*100            #  ???????????????????????????
    path_b = [0]*100
    try:
        path_a = path[start][0][:path[start][0].index(goal)+1]
    except ValueError:
        pass
    try:
        path_b = path[start][1][:path[start][1].index(goal)+1]
    except ValueError:
        pass

    if len(path_a) < len(path_b):
        return ' '.join(map(str, path_a))
    else:
        return ' '.join(map(str, path_b))


def main(args):
    n = int(input())
    for _ in range(n):
        start, goal = map(int, input().split())
        result = solve(start, goal)
        print(result)






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