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++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;

    int buss[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};

    while(--n >= 0){
        int a, b;
        cin >> a >> b;

        int i[2], j[2];
        i[0] = find(buss, buss+15, a) - buss;
        i[1] = find(buss+i[0]+1, buss+15, a) - buss;
        j[0] = find(buss, buss+15, b) - buss;
        j[1] = find(buss+j[0]+1, buss+15, b) - buss;

        int x, y;
        int len = INT_MAX;
        for(int k=0; k<2; ++k){
            for(int l=0; l<2; ++l){
                if(i[k] == 15 || j[l] == 15)
                    continue;
                int tmp = (j[l] - i[k] + 15) % 15;
                if(tmp < len){
                    len = tmp;
                    x = i[k];
                    y = j[l];
                }
            }
        }

        cout << buss[x];
        do{
            ++ x;
            x %= 15;
            cout << ' ' << buss[x];
        }while(x != y);

        cout << endl;
    }

    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 < 100; i++){
            if(busstop[i] == e1){
                if(isFirst){
                    isFirst = !isFirst;
                    continue;
                }
                for(int j=i;j < 100 ; j++){
                    if(busstop[j] == e2){
                        cout << " " << busstop[j];
                        i = 1000; j = 1000;
                    }
                    else {
                        if(j == i) cout << busstop[j];
                        else cout << " " << busstop[j];
                    }
                }
            }
        }
end:
        cout << endl;
    }
}

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

int main(){
	int togo[10][2] = {{1,1},{0,2},{1,3},{2,4},{3,5},{4,6},{7,7},{8,8},{9,9},{5,5}};
	int a,b,n,l,r;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> a >> b;
		l = r = a;
		while(l != b && r != b){
			l = togo[l][0];
			r = togo[r][1];
		}
		cout << a;
		while(a != b){
			if(l == b) a = togo[a][0];
			else a = togo[a][1];
			cout << " " << a;
		}
		cout << endl;
	}
	return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename V>
constexpr string join(const V &v, const string &sep) {
  stringstream ss;
  if (v.size()) ss << v[0];
  loop(i, 1, v.size()) ss << sep << v[i];
  return ss.str();
}

void solve() {
  vi t = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0};
  int n;
  cin >> n;
  while (n--) {
    int a, b;
    cin >> a >> b;
    int i = distance(t.begin(), find(all(t), a));
    vi v;
    for (;;) {
      v.pb(t[i]);
      i++;
      if (t[i] == b) break;
      if (t[i] == a) v.clear();
    }
    v.pb(t[i]);
    cout << join(v, " ") << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

V ans;
ll pos, goal, n;

ll d[10][10];
bool used[10];

void solve(ll pos){
	ans.push_back(pos);
	if (pos == goal){
		REP(i, ans.size())cout << ans[i] << " ";
		cout << endl;
		return;
	}

	for (int i = 0; i < 10; i++){
		if (d[pos][i] == 1){
			if (used[i] == 0){
				used[i] = 1;
				solve(i);
				ans.pop_back();
				used[i] = 0;
			}
		}
	}
	return;
}

int main(){
	//REP(i, 10)REP(j, 10)d[i][j] = INF;
	d[0][1] = d[1][0] = d[1][2] = d[2][1] = d[2][3] = d[3][2] = d[3][4] = 1;
	d[4][3] = d[4][5] = d[5][4] = d[5][6] = d[6][7] = d[7][8] = d[8][9] = d[9][5] = 1;
	cin >> n;
	REP(i, n){
		cin >> pos >> goal;

		if (pos == goal){
			cout << pos << endl;
			continue;
		}

		REP(j, 10)used[j] = 0;
		used[pos] = 1;
		solve(pos);
		ans.clear();
	}
}