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: # Aizu Problem 00140: Bus Line
#
import sys, math, os, copy

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def bus_line(a, b):
    line = []
    if max(a, b) <= 5:
        if a < b:
            return list(range(a, b + 1))
        else:
            return list(range(a, b - 1, -1))
    if a <= 5:
        # stop must be in circle:
        return list(range(a, b + 1))
    if b <= 5:
        # start must be in circle:
        return list(range(a, 10)) + list(range(5, b - 1, -1))
    # at this point both start and stop are in circle:
    if a < b:
        return list(range(a, b + 1))
    else:
        return list(range(a, 10)) + [5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5] + \
               list(range(6, b + 1))

    
n = int(input())
for __ in range(n):
    a, b = [int(_) for _ in input().split()]
    print(' '.join([str(_) for _ in bus_line(a, b)]))

Python: # pythonっぽくなくてダサい
stops=[0,1,2,3,4,5,6,7,8,9,5,4,3,2,1]
istops=[[0],[1,14],[2,13],[3,12],[4,11],[5,10],[6],[7],[8],[9]]

def asloop(cur, end):
	result=[]
	for i in range(cur, cur+len(stops)):
		x=stops[i%len(stops)]
		result.append(x)
		if x==end:
			return	result

def asrecurse(cur, end, result=None):
	if result is None:
		result=[]
	x=stops[cur]
	result.append(x)
	next=(cur+1)%len(stops)
	if x==end:
		return	result
	return asrecurse(next, end, result)

def loop(start, end):
	result=[i for i in range(len(stops)+1)]
	for i in istops[start]:
		a=asloop(i, end)
		if len(a) < len(result):
			result=a
	return	result

nloop=int(input())
for i in range(nloop):
	inputs=input().split()
	result=loop(int(inputs[0]), int(inputs[1]))
	print(' '.join([str(x) for x in result]))

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: # -*- 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 = list(range(a, b - 1, -1))
        elif b <= 5:
            lst = list(range(a, 10)) + list(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, 0, -1)] + list(range(0, b+1))
        print(*lst)

Python: w = [list(range(i, 6)) for i in range(5)] + [[]] + [[6, 5], [7, 6, 5], [8, 9, 5], [9, 5]]
def unique(l):
    nl = []
    for x in l:
        if x not in nl:
            nl.append(x)
    return nl

n = input()
s = []
for i in range(n):
    a, b = map(int, raw_input().split())
    if a < 5 and b < 5:
        s = list(range(a, b + 1) if a < b else range(b, a + 1))
    elif a < 5 or b < 5:
        s = w[a] + list(reversed(w[b]))
    else:
        if max(a, b) - min(a, b) < min(a, b) - max(a, b) + 5:
            x = 1 if a < b else -1
            s = list(range(a, b + x, x))
        else:
            s = w[a] + list(reversed(w[b]))
    print(' '.join(map(str, unique(s))))

Python: w = [list(range(i, 6)) for i in range(5)] + [[]] + [[6, 5], [7, 6, 5], [8, 9, 5], [9, 5]]
def unique(l):
    nl = []
    for x in l:
        if x not in nl:
            nl.append(x)
    return nl

n = input()
s = []
for i in range(n):
    a, b = map(int, raw_input().split())
    if a < 5 and b < 5:
        x = 1 if a < b else -1
        s = list(range(a, b + x, x))
    elif a < 5 or b < 5:
        s = w[a] + list(reversed(w[b]))
    else:
        if max(a, b) - min(a, b) < min(a, b) - max(a, b) + 5:
            x = 1 if a < b else -1
            s = list(range(a, b + x, x))
        else:
            s = w[a] + list(reversed(w[b]))
    print(' '.join(map(str, unique(s))))

Python: # AOJ 0140 Bus Line
# Python3 2018.6.23 bal4u

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)

C++: #include<iostream>
using namespace std;
int main(){
	int a[16]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
        int n;
	cin>>n;
        int x,y;
        for(int i=0;i<n;i++){
		cin>>x>>y;
		int l,m;
             if(x<y){
                for(int j=0;j<10;j++)
                        if(a[j]==x) l=j;
	        for(int k=l;k<10;k++)
			if(a[k]==y) m=k;
		for(int p=l;p<m;p++){
		    cout<<a[p]<<" ";
                }
                cout<<a[m]<<endl;
              }else if(x>y){
		for(int j=0;j<16;j++)
                        if(a[j]==x) l=j;
	        for(int k=l;k<16;k++)
			if(a[k]==y) m=k;
		for(int p=l;p<m;p++){
		    cout<<a[p]<<" ";
                }
                cout<<a[m]<<endl;
              }else return 0;
        }
}

C++: #include<iostream>
#include<vector>
using namespace std;

main(){
  int tcase; cin >> tcase;
  int s, t;
  
  for ( int i = 0; i < tcase; i++ ){
    cin >> s >> t;
    vector<int> v;
    if ( s < t ){
      for ( int i = s; i <= t; i++ ) v.push_back(i);
    } else if ( s > t ){
      if ( s <= 5 ){
	for ( int i = s; i >= t; i-- ) v.push_back(i);
      } else if ( s >= 6 ){
	for ( int i = s; i <= 9; i++ ) v.push_back(i);
	if ( t <= 5 ){
	  for ( int i = 5; i >= t; i-- ) v.push_back(i);
	} else if ( t >= 6 ){
	  for ( int i = 5; i >= 0; i-- ) v.push_back(i);
	  for ( int i = 1; i <= t; i++ ) v.push_back(i);
	}
      }
    }
    for ( int i = 0; i < v.size(); i++ ){
      if ( i ) cout << " ";
      cout << v[i];
    }
    cout << endl;
  }
}