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

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 <= 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>
#include<cstdio>
#include<string>
using namespace std;
string tmp="012345678954321012345678954";
int main(){
  int n;
  char a,b;
  int min,mini,k,flg;
  for(cin >> n;n;n--){
    cin >> a >> b;
    min=1000000;
    for(int i=0,l=tmp.size();i<l;i++){
      if(a==tmp[i]){
	flg=0;
	for(int j=i+1;j<l;j++){
	  if(b==tmp[j]){
	    k=j;
	    flg=1;
	    break;
	  }
	}
	if(flg==1 && k-i<min){
	  min = k-i;
	  mini = i;
	}
      }
    }
    for(int i=mini;tmp[i]!=b;i++){
      cout << tmp[i] << " ";
    }
    cout << b;
    puts("");
  }
}

C++: #include <iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		for(int i=0;i<n;++i){
			int from,to;
			cin>>from>>to;
			if(from<to)for(int i=from;i<=to;++i)cout<<i<<((i==to)?"":" ");
			else if(from<=5)for(int i=from;i>=to;--i)cout<<i<<((i==to)?"":" ");
			else if(to<=5){
				for(int i=from;i<=9;++i)cout<<i<<((i==9)?"":" ");
				for(int i=5;i>=to;--i)cout<<" "<<i;
			}else{
				for(int i=from;i<=9;++i)cout<<i<<((i==9)?"":" ");
				for(int i=6;i<=to;++i)cout<<" "<<i;
			}
			cout<<"\n";
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        int s,g;
        scanf("%d%d",&s,&g);
        int pos=s;
        printf("%d",s);
        while(pos!=g){
            if(pos>5){
                if(pos==9)pos=5;
                else pos++;
            }
            else{
                if(pos>g)pos--;
                else pos++;
            }
            printf(" %d",pos);
        }
        puts("");
        }
    return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

#define INF 1000010

using namespace std;

int busstop[] = {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};

int main(){
    int n;
    cin >> n;
    for(int k=0; k < n; k++){

        int e1,e2;
        bool isFirst = false;
        cin >> e1 >> e2;

        if(e1 > e2) isFirst = true;

        for(int i=0;; i++){
            if(busstop[i] == e1){
                if(isFirst){
                    isFirst = !isFirst;
                    continue;
                }
                for(int j=i; ; j++){
                    if(busstop[j] == e2){
                        cout << " " << busstop[j];
                        goto end_state;
                    }
                    else {
                        if(j == i) cout << busstop[j];
                        else cout << " " << busstop[j];
                    }
                }
            }
        }
end_state:
        cout << endl;
    }
}

C++: #include<iostream>
#include<queue>
using namespace std;
int main()
{
	int n;

	cin >> n;
	for(int X = 0; X < n; ++X){
		int st, ed;
		queue<int> q;
		cin>>st>>ed;

		if( st == ed ){
			cout << "\n";
			continue;
		}

		if( ed <= 5 ){
			if( st > 5 ){
				for(int i = st; i <= 9; ++i) q.push( i ); 
				for(int i = 5; i >= ed; --i) q.push( i );
			}else{
				if( st > ed )
					for(int i = st; i >= ed; --i) q.push( i );
				else
					for(int i = st; i <= ed; ++i) q.push( i );
			}
		}else{
			if( st < ed ){
				for(int i = st; i <= ed; ++i) q.push( i );
			}else{
				for(int i = st; i <= 9; ++i) q.push( i );
				for(int i = 5; i >= 0; --i) q.push( i );
				for(int i = 1; i <= ed; ++i) q.push( i );
			}
		}
		cout << q.front();
		q.pop();
		while( !q.empty() ){
			cout << ' ' << q.front();
			q.pop();
		}
		cout << '\n';
	}
	return 0;
}