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++: #include <iostream>
using namespace std;

int main(){
    int ans2[20],ans1[20];
    int n,f,e,cnt;
    bool sj,fj,judge,ze,ro;
    cin >> n;
    while(n--){
        cin >> f >> e;
        cnt = 1;
        sj = false;
        fj = false;
        ze = true;
        ro = true;
        judge = false;
        int sta = f;
        ans1[0] = sta;
        ans2[0] = sta;
        while(1){
            if(sta == e) break;
            if(f == e){
                judge = true;
                break;
            }
            if(f > 5 && f < 9) f = -100000;
            if(sta == 9 && !sj){
                sta = 5;
                sj = true;
            }
            else if(sta == 0 && sj) sj = false;
            else if(sj) sta--;
            else if(!sj) sta++;
            ans1[cnt] = sta;
            
            if(f == 0 && !fj) fj = true;
            else if(f == 9 && !fj){
                fj = false;
                f = 5;
            }
            else if(!fj) f--;
            else if(fj) f++;
            ans2[cnt] = f;
            cnt++;
        }
        if(judge){
            for(int i=0;i<cnt-1;i++){
                cout << ans2[i] << " ";
                if(ans2[i+1] == 0 && ans2[i] == 0) i++;
            }
            cout << ans2[cnt-1] << endl;
        }
        else {
            for(int i=0;i<cnt-1;i++){
                cout << ans1[i] << " ";
                if(ans1[i+1] == 0 && ans1[i] == 0) i++;
            }
            cout << ans1[cnt-1] << endl;
        }
    }
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

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

	REP( dt, 0, t )
	{
		int a, b;
		cin >> a >> b;

		VI r, l;
		int i, j;

		i = a;
		for ( j = i; Stop[j] != b; j++ )
		{
			if ( 15 <= j )
			{
				j = 0;
			}

			r.PB( Stop[j] );
		}
		r.PB( Stop[j] );

		i = a;
		for ( j = i; Stop[j] != b; j-- )
		{			
			if ( j < 0 )
			{
				j = 14;
			}

			l.PB( Stop[j] );
		}
		l.PB( Stop[j] );

		VI res = ( l.size() < r.size() ? l : r );

		UREP( i, 0, res.size() )
		{
			cout << res[i] << ( i + 1 == res.size() ? '\n' : ' ' );
		}
	}

	return 0;
}

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

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

using namespace std;

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

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

	rep(i,n)
	{
		int a,b;
		cin >> a >> b;

		vector<int> v,v2;
		
		bool flag = false;
		for(int j=0;j<16;j++)
		{
			if(d[j] == a && !flag)
			{
				flag = true;
			}
			else if(d[j] == a && flag)
			{
				v.clear();
			}

			if(flag) v.push_back(d[j]);
			
			if(flag && d[j] == b)
			{
				flag = false;
				break;
			}
		}

		rep(j,v.size())
		{
			cout << v[j]  << " ";
		}
		cout << endl;
	}
	return 0;
}

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{
				for(int i=from;i<=9;++i)cout<<i<<((i==9)?"":" ");
				for(int i=5;i>=to;--i)cout<<" "<<i;
			}
			cout<<"\n";
		}
	}
	return 0;
}

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

using namespace std;

int main(){
	
	int n;
	
	int a, b;
	
	cin >> n;
	
	for(int loop = 0; loop < n; loop++){
		cin >> a >> b;
		if(a == b){
			printf("%d\n", b);
		}else if(a < b){
			for(int i = a; i < b; i++){
				printf("%d ", i);
			}
			printf("%d\n", b);
		}else if(a <= 5){
			for(int i = a; i > b; i--){
				printf("%d ", i);
			}
			printf("%d\n", b);
		}else if(b <= 5){
			for(int i = a; i <= 9; i++){
				printf("%d ", i);
			}
			for(int i = 5; i > b; i++){
				printf("%d ", i);
			}
			printf("%d\n", b);
		}else{
			for(int i = a; i <= 9; i++){
				printf("%d ", i);
			}
			printf("5 4 3 2 1 0 1 2 3 4 5 ");
			for(int i = 6; i < b; i++){
				printf("%d ", i);
			}
			printf("%d\n", b);
		}
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n;
	cin >> n;
	while (n--) {
		int a, b;
		scanf("%d %d", &a, &b);
		if (a < b)
			for (int i = a; i <= b; i++) printf("%d%c", i, i == b ? '\n' : ' ');
		else if (a <= 5)
			for (int i = a; i >= b; i--) printf("%d%c", i, i == b ? '\n' : ' ');
		else {
			for (int i = a; i <= 9; i++) printf("%d ", i);
			for (int i = 5; i > 0; i--) printf("%d ", i);
			for (int i = 0; i <= b; i++) printf("%d%c", i, i == b ? '\n' : ' ');
		}
	}
	return 0;
}