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

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;


//??????
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int p = 1; p < N; p++) cout << ", " << v[p]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()

// time, num
typedef pair<int, int> pii;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int s, t;
		cin >> s >> t;

		vector<int> ans;
		if (s <= 5 && t <= 5) {
			if (s < t) {
				for (int j = s; j <= t; j++) ans.push_back(j);
			}
			else {
				for (int j = s; j >= t; j--) ans.push_back(j);
			}
		}
		if (s <= 5 && t > 5) {
			for (int j = s; j <= t; j++) ans.push_back(j);
		}
		if (s > 5 && t <= 5) {
			for (int j = s; j <= 9; j++) ans.push_back(j);
			for (int j = 5; j >= t; j--) ans.push_back(j);
		}
		if (s > 5 && t > 5) {
			if (s < t) {
				for (int j = s; j <= t; j++) ans.push_back(j);
			}
			else {
				for (int j = s; j <= 9; j++) ans.push_back(j);
				for (int j = 5; j >= 0; j--) ans.push_back(j);
				for (int j = 1; j <= t; j++) ans.push_back(j);
			}
		}

		cout << ans[0];
		for (int j = 1; j < ans.size(); j++) {
			cout << " " << ans[j];
		}
		cout << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	int n, s, t;
	int r[] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
	cin >> n;
	rep(i,n) {
		cin >> s >> t;
		if(s<=5&&t<=5&&s>t) {
			for(int i=s;i>t;--i) cout << i << " ";
			cout << t << endl;
		} else {
			rep(i,15) {
				if(r[i]==s) {
					rep(j,15) {
						if(r[(i+j)%15]==t) break;
						cout << r[(i+j)%15] << " ";
					}
					cout << t << endl;
					break;
				}
			}
		}
	}
	return 0;
}

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

int main(){
	int n,s,g;
	int seq[]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
	cin >> n;
	
	while(n--){
		cin >> s >> g;
		for(int i=0;i<32;i++){
			if(s<=5 && s>g){
				if(seq[10+i]==s){
					for(int j=10+i;j<32;j++){
						if(j!=10+i)cout << " ";
						cout << seq[j];
						if(seq[j]==g)break;
					}
					cout << endl;
					break;
				}
			}else{
				if(seq[i]==s){
					for(int j=i;j<32;j++){
						if(j!=i)cout << " ";
						cout << seq[j];
						if(seq[j]==g)break;
					}
					cout << endl;
					break;
				}
			}
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;

string nor = "6 7 8 9 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9";
string rev = "9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 9 8 7 6";
int n;
string getstr(string str, char s, char d){
	int i,j;
	for(i=0;str[i]!=s;i++);
	for(j=i;str[j]!=d;j++) if(str[j]==s) i=j;
	return str.substr(i, j-i+1);
}
main(){
	int n,a,b;
	cin >> n;
	while(n--){
		string ret1, ret2;
		cin >> a >> b;
		ret1 = getstr(nor, a+'0', b+'0');
		ret2 = getstr(rev, a+'0', b+'0');
		cout << (ret1.size()<ret2.size()?ret1:ret2) << endl;
	}
	return 0;
}

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

#define rep(i, n)for((i) = 0;(i) < (n);++(i))

string x = "0 1 2 3 4 5 6 7 8 9 5 4 3 2 1 ";

int main(void){
	x += x;
	int n, i, s, t, l, r;
	pair<int,string> res;
	scanf("%d", &n);
	for(;n--;){
		res.first = 12345;
		scanf("%d %d", &s, &t);
		rep(l, x.size())if(x[l] == '0' + s){
			for(r = l + 1;r < x.size();++r)if(x[r] == '0' + t)break;
			if(r < x.size() && res.first > r - l){
				res.first = r - l + 1;
				res.second = x.substr(l, r - l + 1);
			}
		}
		cout << res.second << endl;
	}
	return 0;
}

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

int main(void){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		printf("%d",f);
		if(f<=5){
			if(t>f){
				while(f!=t){
					f++;
					printf(" %d",f);
				}
			}
			if(t<f){
				while(f!=t){
					f--;
					printf(" %d",f);
				}
			}
		}
		if(f>5){
			if(f<t && t<=9){
				while(f!=t){
					f++;
					printf(" %d",f);
				}
			}else if(t==5){
				while(f!=9){
					f++;
					printf(" %d",f);
				}
				f=5;
				printf(" %d",f);
			}else{
				while(f!=9){
					f++;
					printf(" %d",f);
				}
				f=5;
				printf(" %d",f);
				if(t<5){
					while(f!=t){
						f--;
						printf(" %d",f);
					}
				}else{
					while(f!=0){
						f--;
						printf(" %d",f);
					}
					while(f!=t){
						f++;
						printf(" %d",f);
					}
				}
			}
		}
		printf("\n");
	}
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF (1<20)
int G[20];
int search(int s,int f){
  if(s==-1) return INF;
  int count;
  for(int i=0;i<15;i++){
    int ind = (i+s)%15;
    //   printf("%d\n",G[ind]);
    if(G[ind] == f){
      count = i;
      break;
    }
  }
  return count;
}
void printans(int s,int f){
  for(int i=0;i<15;i++){
    int ind = (i+s)%15;
    printf("%d",G[ind]);
    if(G[ind] == f){
      break;
    }
    printf(" ");
  }
  puts("");
}
int main(){
  int n;
  for(int i=0;i<10;i++) G[i]=i;
  for(int i=10,j=5;i<15;i++,j--) G[i]=j;
  scanf("%d\n",&n);
  for(int i=0;i<n;i++){
    int s,f;
    scanf("%d %d",&s,&f);
    int count = 0;
    int st=-1;
    count = search(s,f);
    for(int i=10;i<15;i++){
      if(G[i]==s){ 
	st = i;
      }
    }
    if(st>0){
      if(count < search(st,f)){
	printans(s,f);
      }else{
	printans(st,f);
      }
    }else{
      printans(s,f);
    }
  }
}