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 <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    int N;
    cin >> N;
    for (;N--;) {
        int src, dst;
        cin >> src >> dst;

        if (src < dst) {
            cout << src;
            for (int j = src+1; j <= dst; ++j) {
                cout << ' ' << j;
            }
            cout << endl;
        } else {
            cout << src;
            if (src <= 5) {
                for (int j = src-1; j >= dst; --j) {
                    cout << ' ' << j;
                }
            } else {
                for (int j = src+1; j <= 9; ++j) {
                    cout << ' ' << j;
                }
                for (int j = 5; j >= dst; --j) {
                    cout << ' ' << j;
                }
            }
            cout << endl;
        }

    }

    return 0;
}

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

int main() {
    int N; cin >> N;
    while(N--) {
        int from, to; cin >> from >> to;
        vector<int> route;
        if(from <= 5 && to < from) {
            for(int i = from; i >= to; i--) {
                route.push_back(i);
            }
        }
        else {
            if(from >= 6 && to >= 6 && to < from) {
                for(int i = from; i <= 9; i++) {
                    route.push_back(i);
                }
                for(int i = 5; i >= 0; i--) {
                    route.push_back(i);
                }
                for(int i = 1; i <= 5; i++) route.push_back(i);
                for(int i = 6; i <= to; i++) route.push_back(i);
            }
            else if(from >= 6 && to <= 5) {
                for(int i = from; i <= 9; i++) {
                    route.push_back(i);
                }
                for(int i = 5; i >= to; i--) {
                    route.push_back(i);
                }
            }
            else {
                for(int i = from; i <= to; i++) {
                    route.push_back(i);
                }
            }
        }
        for(int i = 0; i < (int)route.size() - 1; i++) cout << route[i] << ' ';
        cout << *route.rbegin() << endl;
    }
}

C++: #include <cstdio>

using namespace std;

int main()
{
    int n;
    scanf( "%d\n", &n );
    for( int j = 0; j < n; j++ )
    {
        int source = 0, sink = 0;
        scanf( "%d %d\n", &source, &sink );
        if( source <= 5 )
        {
            if( source < sink )
            {
                for( int i = source; i <= sink; i++ )
                {
                    printf( "%d ", i );
                }
                printf( "\n" );
            }
            else
            {
                for( int i = source; i >= sink; i-- )
                {
                    printf( "%d ", i );
                }
                printf( "\n" );
            }
        } 
        else
        {
            if( sink >= 5 )
            {
                if( source < sink )
                {
                    for( int i = source; i <= sink; i++ )
                    {
                        printf( "%d ", i );
                    }
                    printf( "\n" );
                }
                else
                {
                    for( int i = source; i <= 9; i++ )
                    {
                        printf( "%d ", i );
                    }
                    if( sink != 5 )
                    {
                        printf( "5 4 3 2 1 0 1 2 3 4" );
                    }
                    for( int i = 5;i < sink; i++ )
                    {
                        printf( "%d ", i );
                    }
                    printf( "\n" );
                }
            }
            else
            {
                for( int i = source; i <= 9; i++ )
                {
                    printf( "%d ", i );
                }
                for( int i = 5; i >= sink; i++ )
                {
                    printf( "%d ", i );
                }
                printf( "\n" );
            }
        }
    }
    return 0;
}

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

using namespace std;

#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define FOR1(i,a,b) for(int i = a ; i <= b ; i++)
#define FOR2(i,a,b) for(int i = a ; i >= b ; i--)

int main(){
    int n;
     
    cin >> n;
    while(n--){
        int s,g;
        vector<int> v;
         
        cin >> s >> g;
        if(s < g){
	  FOR1(i,s,g) v.push_back(i);
        }
        else if(s > g){
            if(s > 5){
	      FOR1(i,s,9) v.push_back(i);
                if(g > 5){
		  FOR2(i,5,0) v.push_back(i);
		  FOR1(i,1,g) v.push_back(i);
                }
                else{
		  FOR2(i,5,g) v.push_back(i);
                }
            }
            else if(s <= 5){
	      FOR2(i,s,g) v.push_back(i);
            }
        }        
    
	rep(i,(int)v.size()){
            if(!i) cout << v[i];
            else cout << ' ' << v[i];
        }
        cout << endl;
    }
     
    return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){

	int n,start,goal;

	scanf("%d",&n);

	for(int i=0; i < n; i++){
		scanf("%d %d",&start,&goal);

		if(start <= 5){
			if(start < goal){
				printf("%d",start);
				for(int k = start+1; k <= goal; k++){
					printf(" %d",k);
				}
				printf("\n");
			}else{
				printf("%d",start);
				for(int k = start-1; k >= goal; k--){
					printf(" %d",k);
				}
				printf("\n");
			}
		}else{ //start > 6
			if(goal >= 5){  //??´??????????????????
				if(start < goal){
					printf("%d",start);
					for(int k= start+1; k <= goal; k++)printf(" %d",k);

					printf("\n");

				}else{ //start > goal
					printf("%d",start);
					for(int k= start+1; k <= 9; k++)printf(" %d",k);
					if(goal != 5){
						printf(" 5 4 3 2 1 0 1 2 3 4");
					}
					for(int k=5; k <= goal; k++)printf(" %d",k);
					printf("\n");
				}

			}else{ //goal <= 4
				printf("%d",start);
				for(int k=start+1; k <= 9; k++)printf(" %d",k);
				for(int k=5; k >= goal; k--)printf(" %d",k);
				printf("\n");
			}

		}

	}

    return 0;
}