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>
#include <vector>
using namespace std;

int main() {
	vector<int> v;

	for(int i = 0; i < 10; i++)
		v.push_back(i);
	for(int i = 5; i > 0; i--)
		v.push_back(i);

	int n;
	cin >> n;
	for(int t = 0; t < n; t++) {
		int s, g;
		vector<int> ret;
		ret.resize(64);
		cin >> s >> g;
		for(int i = 0;i < v.size(); i++) {
			if(s == v[i]) {
				vector<int> tmp;
				for(int j = i;; j++) {
					tmp.push_back(v[j]);
					if(v[j % v.size()] == g)
						break;
				}
				if(tmp.size() < ret.size())
					ret = tmp;
			}
		}

		cout << ret[0];
		for(int i = 1; i < ret.size(); i++)
			cout << " " << ret[i];
		cout << endl;
	}
}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem0140 : Bus Line **/
int main()
{
	int N; cin>>N;
	int p1[] = {5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0};
	
	rep(z, N) {
		int s, t; cin>>s>>t;
		
		int ans=INF, a=-1, b=-1;
		for (int i=0; i<21; i++) {
			if (p1[i]==s) {
				int tt=1;
				for (int j=i; j<21; j++) {
					if (p1[j]==t) {
						if (ans>tt) {
							ans = tt;
							a = i;
							b = i+tt;
						}
						break;
					}
					tt++;
				}
			}
		}
		
		
		for (int i=a; i<b; i++) {
			if (i!=a) cout<<" ";
			cout << p1[i];
		}
		cout << endl;
	}
}

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 RETURNED 2
#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 parent, 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] != VISITED) {
            if (parent == 9 && now == 5 && i == 6) continue;
            int r = dfs(i, now, 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;

        if (s > 6 && d > 5 && s > d) {
            cout << s << " ";
            for (int k = s + 1; k <= 9; k++) {
                cout << k << " ";
            }
            FORR(i, 5, -1) cout << i << " ";
            FOR(i, 1, 6) cout << i << " ";

            for (int k = 6; k < d; k++) {
                cout << k << " ";
            }
            cout << d << endl;
            continue;
        }

        result.clear();
        dfs(s, -1, 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<string>
using namespace std;

int main() {
	string sa = "012345678954321012345678954321";
	int n;
	cin >> n;
	for (int x = 0;x < n;x++) {
		char a, b;
		cin >> a >> b;
		int aa=1e-9, ab=1e9;
		for (int i = 0;i < sa.size();i++) {
			if (sa[i] == a) {
				for (int j = i;j <= sa.size();j++) {
					if (sa[j] == b) {
						if (ab - aa > j - i) {
							aa = i;
							ab = j;
						}
					}
				}
			}
		}
		for (int i = aa; i <= ab;i++) {
			if (i != aa)cout << ' ';
			cout << sa[i];
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
void p(int x,int y){
 
  cout<<x;
  for(int i=x+1;i<=y;i++){
    cout<<' '<<i;
  }
  
}
void pb(int x,int y){
  cout<<x;
  for(int i=x-1;i>=y;i--){
    cout<<' '<<i;
  }

}
int main(){
  int n,a,b;
  cin>>n;
  while(n--){
    cin>>a>>b;
    if(a<=5&&b<=5){
      if(a<b)p(a,b);
      else p(b,a);
      cout<<endl;
    }else if(a<=5&&b>=6){
      if(a<5){p(a,4);cout<<' ';}
      p(5,b);
      cout<<endl;
    }else if(a>=6&&b<=5){
      p(a,9);cout<<' ';
      pb(5,b);cout<<endl;
    }else{
      
      if(a<=b){
	p(a,b);cout<<endl;
      }else{
	p(a,9);cout<<' ';
	pb(5,0);cout<<' ';
	p(1,4);cout<<' ';
	p(5,b);cout<<endl;
      }

    }
  }
  
}