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 <bits/stdc++.h>
 
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 < (int)v.size(); i++) {
            if (i > 0) cout << " ";
            cout << v[i];
        }
        cout << endl;
    }
    return 0;
}

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

const static char *BUSLINE = "012345678954321";
const static int BUSLINE_LEN = 15;

int main() {
  int n;
  cin >> n;
  
  for( int i = 0; i < n; i++ ) {
    int ent, ext;
    int route = 1;
    vector<int> route1, route2;
    cin >> ent >> ext;

    for( int j = 0; j < BUSLINE_LEN; j++ ) {
      if( BUSLINE[ j ] == ent + '0' ) {
        for( int k = j; ; k = ( k + 1 ) % BUSLINE_LEN ) {
          if( route == 1 ) {
            route1.push_back( BUSLINE[ k ] - '0' );
          } else {
            route2.push_back( BUSLINE[ k ] - '0' );
          }
          if( BUSLINE[ k ] == ext + '0' ) {
            route++;
            break;
          }
        }
      }
    }

    vector<int>* vp;
    if( route2.size() == 0 || route1.size() < route2.size() ) {
      vp = &route1;
    } else {
      vp = &route2;
    }
    
    int len = vp->size();
    for( int i = 0; i < len; i++ ) {
      cout << vp->at(i) << flush;
      if( i == len - 1 ) { break; }
      cout << " " << flush;
    }
    cout << endl;
  }

  return EXIT_SUCCESS;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    while(--n >= 0){
        int a, b;
        cin >> a >> b;
        cout << a;

        if(a <= 5){
            if(b < a){
                for(int i=a-1; i>=b; --i)
                    cout << ' ' << i;
            }else{
                for(int i=a+1; i<=b; ++i)
                    cout << ' ' << i;
            }
        }else{
            if(b <= 5){
                for(int i=a+1; i<=9; ++i)
                    cout << ' ' << i;
                for(int i=5; i>=b; --i)
                    cout << ' ' << i;
            }else{
                for(int i=a+1; i<=b; ++i)
                    cout << ' ' << i;
            }
        }
        cout << endl;
    }

    return 0;
}

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 > 0) 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;
}