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 <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 cost[10][10];
int d[10];
bool used[10];
int V = 10;
int prev[10];

void dijkstra(int s){
    fill(d, d+V, INF);
    fill(used, used+V, false);
    fill(prev, prev+V, -1);
    d[s] = 0;

    while(true){
        int v = -1;
        for(int u=0; u < V; u++){
            if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
        }

        if(v == -1) break;
        used[v] = true;

        for(int u=0; u < V; u++){
            if(d[u] > d[v]+cost[v][u]){
                d[u] = d[v]+cost[v][u];
                prev[u] = v;
            }
        }
    }
}

vector<int> get_path(int t){
    vector<int > path;
    for(; t != -1; t = prev[t]) path.push_back(t);
    reverse(all(path));
    return path;
}

int main(){
    int n;
    cin >> n;
    for(int k=0; k < n; k++){
        for(int i=0; i < 10; i++) for(int j=0; j < 10; j++) cost[i][j] = INF;

        for(int i=1; i < 6; i++){
            cost[i][i-1] = 1;
            cost[i-1][i] = 1;
        }
        cost[5][6] = 1; cost[6][7] = 1; cost[7][8] = 1; cost[8][9] = 1; cost[9][5] = 1;

        int e1,e2;
        cin >> e1 >> e2;

        dijkstra(e1);
        vector<int> path = get_path(e2);
        for(int i=0; i < path.size(); i++){
            if(i == 0) cout << path[i];
            else cout << " " << path[i];
        }
        cout << endl;
    }
}

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

int main() {
	int hmData;		//	how many Data?
	cin >> hmData;
	
	for(int i = 0;i < hmData;i++)
	{
		int Dep,Dest;	//Dep = Departure Place,Dest = Destination Place
		cin >> Dep;
		cin >> Dest;
		
		if(Dep <= 5 && Dest <= 5)
		{
			if(Dep > Dest)
			{
				Dep = 15 - Dep;
				Dest = 15 - Dest;
			}
		}else{
			if(Dep > Dest)
			{
				Dest = 15 - Dest;
			}
		}
		
		while(Dep <= Dest)
		{
			if(Dep > 9){
				cout << 15 - Dep;
			}else{
				cout << Dep;
			}
			cout << " ";
			Dep++;
		}
		cout << "\n";
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
const int field[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8};
const int l = sizeof(field) / sizeof(int);

int main() {
	int n;
	cin >> n;
	while (n--) {
		int s, g;
		int res_size = 100, res_begin;
		cin >> s >> g;
		for (int i = 0; i < l; i++) {
			if (field[i] != s) continue;
			for (int j = i + 1; j < l; j++) {
				if (field[j] != g) continue;
				int size = j - i;
				if (size < res_size) {
					res_size = size;
					res_begin = i;
				}
			}
		}
		for (int i = res_begin;; i++) {
			if (i != res_begin) cout << ' ';
			cout << field[i];
			if (field[i] == g) break;
		}
		cout << endl;
	}
	return 0;
}

C++: # define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;

# define INF ((int)(1<<30))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12

template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,-1,1,0 }, dy[4] = { 1,0,0,-1 };

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int now, end;
		cin >> now >> end;
		vi ans;
		bool a = false;
		if (now > end&&now>5)
		{
			for (; now <= 9; now++)ans.push_back(now);
			now = 5; 
			for (; now >= 0; now--)
			{
				ans.push_back(now);
				if (now == end)break;
			}
			
			if (now != end) {
				now = 1;
				for (; now <= end; now++)
				{
					ans.push_back(now);
					if (now == end)break;
				}
			}
		}
		else if (now > end)
		{
			for (; now >= end; now--)ans.push_back(now);
		}
		else
		{
			for (; now <= end; now++)ans.push_back(now);
		}
		for (int i = 0; i < ans.size(); i++)
		{
			cout << (i ? " " : "") << ans[i];
		}
		cout << endl;

	}
}

C++: #include <iostream>
#include <cstdio>

using namespace std;

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

        cin >> s >> e;

        if (s <= 5) {
            if (s < e) {
                while (s != e) 
                    printf("%d ", s++);
                printf("%d\n", e);
            }
            else {
                while (s != e)
                    printf("%d ", s--);
                printf("%d\n", e);
            }
        }
        else if (e >= 5) {
            while (s != e) {
                printf("%d ", s);
                s = (s + 1) - ((s + 1) / 10) * 5;
            }
            printf("%d\n", e);
        }
        else if (e < 5) {
            while (s != 5) {
                printf("%d ", s);
                s = (s + 1) - ((s + 1) / 10) * 5;
            }
            while (s != e)
                printf("%d ", s--);
            printf("%d\n", e);
        }
    }

    return 0;
}

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

int BusStop[] ={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
int Offset[]={0,13,11,9,7,5};
vector<int> Result1, Result2;
	
int main(void){
    int n,start,end,i,j;
    
    cin>>n;
    while(n--){
        cin>>start>>end;
        Result1.clear();
        Result2.clear();
        if(start>5 || start==0){	//0 || 6:9
			for(int i=start; BusStop[i%15]!=end; i++){
				cout<<BusStop[i%15]<<" ";
			}
		}else{
			int i=start, j=start+Offset[i]; 
			while(1){
				if(BusStop[i%15] == end){
					for(int k=0; k<Result1.size(); k++){
						cout<<Result1[k]<<" ";
					}
					break;
				}
				if(BusStop[j%15] == end){
					for(int k=0; k<Result2.size(); k++){
						cout<<Result2[k]<<" ";
					}
					break;
				}
				Result1.push_back(BusStop[i%15]);
				Result2.push_back(BusStop[j%15]);
				i++;
				j++;
			}
		}
		cout<<end<<endl;
    }
	
    return 0;
}