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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

string toString(int x)
{
	stringstream ss; ss << x;
	return ss.str();
}

string rootString(int f, int t)
{
	int b = f < t ? 1 : -1;
	
	string res;
	
	for(int i = f; i != t; i += b)
		res += toString(i);
	
	return res + toString(t);
}

void print(string s)
{
	rep(i, s.size())
		cout << s[i] << (i == s.size() - 1 ? "\n" : " ");
}

int main()
{
	int n;
	cin >> n;
	
	while(n--)
	{
		int f, t;
		cin >> f >> t;
		
		if(f < t)	print(rootString(f, t));
		else
		{
			if(f <= 5)	print(rootString(f, t));
			else if(t < 5) print(rootString(f, 9) + toString(5) + rootString(4, t));
			else if(t == 5) print(rootString(f, 10).substr(0, f - t - 1) + toString(5));
			else print(rootString(f, 5) + rootString(4, 0) + rootString(1, t));
		}
	}
}

C++: #include<cstdio>

using namespace std;

int main(void){
	
	int n;
	while(scanf("%d", &n)!= EOF){
		int s,e;
		for(int j = 0; j < n; j++){
			scanf("%d%d", &s, &e);
		
			if(s <= 5 && e <= 5){
				if(s > e){
					for(int i = s; i >= e; i--){
						if(i != s)printf(" ");
						printf("%d",i);
					}
				}else {
					for(int i = s; i <= e; i++){
						if(i != s)printf(" ");
						printf("%d",i);
					}
				}
			}else if(e > 5 && e <10 && s <= 5){
				for(int i = s; i <= e; i++){
					if(i != s)printf(" ");
					printf("%d",i);
				}
			}else if(s > 5 && e<=5){
				for(int i = s; i < 10; i++){
					if(i != s)printf(" ");
					printf("%d",i);
				}
				for(int i = 5; i >= e; i--){
					printf(" %d",i);
				}
			}else if(s < e && s > 5 && e <10){
				for(int i = s; i <= e; i++){
					if(i != s)printf(" ");
					printf("%d",i);
				}
			}else{
				for(int i = s; i <=9; i++){
					if(i != s)printf(" ");
					printf("%d",i);
				}
				for(int i = 5; i > 0; i--){
					printf(" %d",i);
				}
				for(int i = 0; i <= e; i++){
					printf(" %d",i);
				}
			}
			
			puts("");
		}
	}
	
	return 0;
}

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

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

int main() {
    int n;
    cin >> n;
    while (n--) {
        int a, b;
        cin >> a >> b;
        int i;
        if (a > 5 || a < b) {
            cout << stop[a];
            for (i = a + 1; stop[i] != b; i++) {
                cout << " " << stop[i];
            }
            cout << " " << stop[i];
            cout << endl;
        } else {
            cout << stop[15 - a];
            for (i = 15 - a + 1; stop[i] != b; i++) {
                cout << " " << stop[i];
            }
            cout << " " << stop[i];
            cout << endl;
        }
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<double,int> P;

static const double eps = 10e-9;

int main(){
	int n;
	scanf("%d",&n);
		for(int i=0;i<n;i++){
			int src,dst;
			scanf("%d %d",&src,&dst);
			if(src <= 5 && dst <= 5){
				if(src < dst){
					for(int j=src;j<=dst;j++){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
				else if(src > dst){
					for(int j=src;j>=dst;j--){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
			}
			else if(src >= 5 && dst >= 5){
				if(src < dst){
					for(int j=src;j<=dst;j++){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
				else if(src > dst){
					for(int j=src;j<=9;j++){
						printf("%d ",j);
					}

					if(dst == 5){
						cout << 5 << endl;
						continue;
					}
					for(int j=5;j>=0;j--){
						printf("%d ",j);
					}

					for(int j=1;j<=4;j++){
						printf("%d ",j);
					}

					for(int j=5;j<=dst;j++){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
			}

			else{
				if(src < dst){
					for(int j=src;j<=dst;j++){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
				else if(src > dst){
					for(int j=src;j<=9;j++){
						printf("%d ",j);
					}

					for(int j=5;j>=dst;j--){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
			}

		}
}

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

void printRes( string s )
{
    for( int i = 0; i < s.size() - 1; i++ )
        cout << s[i] << " ";
    cout << s[s.size()-1] << endl;
}

int main()
{
    int n, a[24], x, y;
    string s, t;

    for( int i = 0; i < 10; i++ )
        a[i] = i;
    for( int i = 10; i < 16; i++ )
        a[i] = 15 - i;
    for( int i = 16; i < 24; i++ )
        a[i] = i - 15;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        s = "";
        t = "";
        cin >> x >> y;

        if( 6 <= x && x <= 9 )
        {
            for( int j = x; j < 24; j++ )
            {
                s += a[j] + '0';
                if( a[j] == y )
                    break;
            }
            printRes( s );
        }
        else
        {
            bool judge1 = false, judge2 = false;
            for( int j = x; j >= 0; j-- )
            {
                s += a[j] + '0';
                if( a[j] == y )
                {
                    judge1 = true;
                    break;
                }
            }

            for( int j = x; j < 16; j++ )
            {
                t += a[j] + '0';
                if( a[j] == y )
                {
                    judge2 = true;
                    break;
                }
            }

            if( s.size() < t.size() )
            {
                if( judge1 == 1 )
                    printRes( s );
                else
                    printRes( t );
            }
            else
            {
                if( judge2 == 1 )
                    printRes( t );
                else
                    printRes( s );
            }
        }
    }
    return 0;
}