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<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<utility>
#include<cctype>
using namespace std;

#define ull unsigned long long
#define stt(it,order) sort(it.begin(),it.end(),order)
#define st(it) sort(it.begin(),it.end())
#define ll long long
#define rep(i,j) for(int i=0;i<j;++i)
#define loop(i,a,j) for(int i=a;i<j;++i)
#define mpi(it,table,T,E) for(map<T,E>::iterator it = table.begin();it!=table.end();++it)
#define PI 3.141592654
#define pb(v,e) v.push_back(e)

string sint(int i){
   stringstream buf;
   buf<<i;
   return buf.str();
}

/*
   ifstream fin("input.txt");
   ofstream fout("output.txt");
#define cin fin
#define cout fout
*/

int sol[15];

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

string print(int i,int e){
   if( i == -1)return "";
   if(e)return print(sol[i],0)+sint(alias[i])+"\n";
   return print(sol[i],0)+sint(alias[i])+" ";
}

string do_bfs(int j,int k){

   memset(sol,-1,sizeof(sol));
   sol[j] = -1;
   int stop = j;

   while(alias[stop] != k){
      int nx = stop;
      stop = (nx+1)%15;
      sol[stop] = nx;
   }

   return print(stop,1);
}

int main(){
   int u;
   scanf("%d",&u);
   rep(a,u){
      string sol = "1 2 3 4 5 6 7 8 9 5 4 3 2 1 0 0 0";
      
      int j,k;
      scanf("%d %d",&j,&k);

      rep(i,15){
         if( alias[i] == j){
            string aux = do_bfs(i,k);
            if( sol.size() > aux.size()) sol = aux;
         }
      }
      printf("%s",sol.c_str());
   }
   return 0;
}

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

//#define int long long
#define DEBUG 1
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

signed main() {
	string A = "012345678954321012345678954321";
	int n; cin >> n;
	rep(i,0,n){
		int a, b; cin >> a >> b;
		string ans = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
		rep(i, 0, A.size() / 2) {
			if (A[i] - '0' != a) continue;
			string temp = "";
			temp += A[i];
			rep(j, i + 1, A.size()) {
				temp += " ";
				temp += A[j];
				if (A[j] - '0' == b) break;
			}
			if (temp.size() < ans.size())ans = temp;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int s[16] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
int main(void){
  int n;
  cin>>n;
  while(n--){
    int a,b;
    vector<int> ans;
    cin>>a>>b;
    bool f=false;
    REP(i,16){
      if(s[i]==a){
        if(!f)f=true;
        else ans.clear();
      }
      if(f) ans.push_back(s[i]);
      if(f&&s[i]==b) break;
    }
    REP(i,ans.size()){
      if(i) cout<<" ";
      cout<<ans[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;
	int route[] = {5,6,7,8,9,5};
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			int src,dst;
			scanf("%d %d",&src,&dst);
			if(src <= 5 && dst <= 5){
				for(int j=min(src,dst);j<=max(src,dst);j++){
					printf("%d%s",j,j == max(src,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>=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 <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct Edge{
	int src,dst;
	Edge(){}
	Edge(int s,int d):src(s),dst(d){}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void solve(Graph& g,int begin,int end)
{
	int size=g.size();
	vi prev(size,-1);
	queue<Edge> q;
	q.push(Edge(-2,begin));
	while(q.size()){
		Edge e=q.front(); q.pop();
		if(prev[e.dst]!=-1) continue;
		prev[e.dst]=e.src;
		foreach(it,g[e.dst])
			q.push(*it);
	}
	vi res;
	for(int i=end;i>=0;i=prev[i])
		res.push_back(i);
	reverse(allof(res));
	rep(i,res.size())
		printf("%d%c",res[i],i==res.size()-1?'\n':' ');
}

int main()
{
	Graph g(10);
	int src[]={0,1,1,2,2,3,3,4,4,5,5,6,7,8,9};
	int dst[]={1,0,2,1,3,2,4,3,5,4,6,7,8,9,5};
	rep(i,sizeof(src)/sizeof(src[0]))
		g[src[i]].push_back(Edge(src[i],dst[i]));
	
	int n;
	cin>>n;
	rep(i,n){
		int begin,end;
		cin>>begin>>end;
		solve(g,begin,end);
	}
	
	return 0;
}