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
//------------------------------------------
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>(b);i--)
#define REP(i,n)  FOR(i,0,n)

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
//-------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define INF (1<<21)
#define VISITED 1
#define NOT_VISITED 0

//typedef
//-------------------------------------------
typedef long long ll;

int g[10][10];
int visited[10];
vector<int> result;

int s, d;

int dfs(int now, int cost) {
    visited[now] = VISITED;
    if (now == d) return cost;

    int test = 0;
    int tmp = INF;
    int mini = -1;
    REP(i, 10) {
        if(g[now][i] != INF && visited[i] == NOT_VISITED) {
            int r = dfs(i, cost + 1);
            if (tmp > r) {
                tmp = r;
                mini = i;
            }
        }
    }
    if (mini > -1) result.push_back(mini);

    return tmp;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i, 10) REP(j, 10) g[i][j] = INF;
    g[0][1] = 1, g[1][0] = 1;
    g[1][2] = 1, g[2][1] = 1;
    g[2][3] = 1, g[3][2] = 1;
    g[3][4] = 1, g[4][3] = 1;
    g[4][5] = 1, g[5][4] = 1;
    g[5][6] = 1, g[6][7] = 1, g[7][8] = 1, g[8][9] = 1, g[9][5] = 1;

    int n;
    cin >> n;
    REP(j, n) {
        REP(i, 10) visited[i] = NOT_VISITED;
        if (!n) return 0;
        cin >> s >> d;
        result.clear();
        dfs(s, 0);
        reverse(result.begin(), result.end());
        cout << s << " ";
        for (int i = 0; i < result.size() - 1; i++) {
            cout << result[i] << " ";
        }
        cout << result[result.size() - 1] << endl;
    }
    return 0;
}

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

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

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  while(n--){
    int a,b;
    cin>>a>>b;
    if(a==b){
      printf("%d\n",a);
      continue;
    }
    if(a>5){
      if(a<b)for(int i=a;i<=b;i++){
        printf("%d%c",i,i==b?'\n':' ');
        continue;
      }
      for(int i=a;i<=9;i++)printf("%d ",i);printf("5");
      if(b==5){
        printf("\n");
        continue;
      }else printf(" ");
      if(b<5){
        for(int i=4;i>=b;i--)printf("%d%c",i,i==b?'\n':' ');
        continue;
      }
      for(int i=4;i>=0;i--)printf("%d ",i);
      for(int i=1;i<=5;i++)printf("%d ",i);
      for(int i=6;i<=b;i++)printf("%d%c",i,i==b?'\n':' ');
    }else{
      if(b<=5){
        if(a<b)for(int i=a;i<=b;i++)printf("%d%c",i,i==b?'\n':' ');
        else for(int i=a;i>=b;i--)printf("%d%c",i,i==b?'\n':' ');
        continue;
      }else{
        for(int i=a;i<=5;i++)printf("%d ",i);
        for(int i=6;i<=b;i++)printf("%d%c",i,i==b?'\n':' ');
      }
    }
  }
}