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 <vector>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define PP(m) REP(i, m.size()) cout << m[i] << endl;

int main() {
  vector<int> co(10);
  vector<int> cr(10);

  REP(i, 9) co[i] = i+1;
  REP(i, 9) cr[i] = i+1;
  co[9] = 5;
  cr[9] = 5;

  for (int i=0; i<5; i++) cr[5-i] = 4-i;

  int n;
  cin >> n;
  REP(i, n) {
    int a,b;
    string r="";
    bool rev = false;
    cin >> a >> b;
    while (true) {
      r += to_string(a);
      if (a == b) {
        r += "\n";
        break;
      }
      if (a == 9 || (a == 0 && rev) || (a <= 5 && b <= 5 && a > b && !rev)) {
        rev = !rev;
      }
      if (!rev) {
        a = co[a];
      } else {
        a = cr[a];
      }
      r += " ";
    }
    cout << r;
  }

  return 0;
}

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

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

int main() {
  int n, a, b;
  cin >> n;
  while(n--) {
    cin >> a >> b;
    int res = 100;
    int minI, minJ;
    for(int i = 0; i < 15; ++i) {
      for(int j = 0; j < 15; ++j) {
        if(c[i] == a && c[j] == b) {
          int next = (j-i+15)%15;
          if(res > next) {
            res = next;
            minI = i;
            minJ = j;
          }
        }
      }
    }
    for(int k = minI; k != minJ; k = (k+1)%15) {
      cout << c[k] << " ";
    }
    cout << c[minJ] << endl;
  }
  return 0;
}

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

int main(){
    int togo[10][2] = {{1,1},{0,2},{1,3},{2,4},{3,5},{4,6},{5,7},{6,8},{7,9},{8,5}};
	int a,b,n,l,r;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> a >> b;
		l = r = a;
		while(l != b && r != b){
			l = togo[l][0];
			r = togo[r][1];
		}
		cout << a;
		while(a != b){
			if(l == b) a = togo[a][0];
			else a = togo[a][1];
			cout << " " << a;
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	const int path[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1 };
//	cut here before submit 
//	freopen ("testcase.busline2", "r", stdin );
	string str = "";
	int n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;
		if (n == 0 ){
			break;
		} // end if
		int i, j, k;
		for (i = 0; i < n; ++i){
			getline (cin, str );
			if (str.empty() ){
				break;
			} // end if
			vector <int> res;
			int from, to;
			stringstream ss(str);
			ss >> from >> to;
			int len = sizeof(path)/sizeof(path[0]);
			if (from < to ){
				for (j = from; j != to; j = (j + 1) % len ){
					res.push_back(path[j]);
				} // end for
			}else if (from > to ){
				bool found = (from < 6 ? false : true);
				for (k = 0; k < len; ++k){
					if (path[k] == from){
						if (!found ){
							found = true;
							continue;
						}else{
							break;
						} // end if
					} // end if
				} // end for
				for (j = k; j != to || path[j] != to; j = (j + 1) % len ){
					res.push_back(path[j]);
				} // end for
			} // end if
						
			res.push_back(path[to] );

			int size = res.size();
			for (j = 0; j < size; ++j){
				cout << res[j];
				if (j != size - 1){
					cout << ' ';
				} // end if
			} // end for
			cout << endl;
		} // end for
	} // end loop
		
	return 0;
}

C++: #include <iostream>
using namespace std;
int s[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};

void disp(int a, int b){
	for(int i = a+1;;i++){
		cout << " " << s[i%15];
		if(s[i%15] == b){cout << endl;break;}
	}
}

int main(){
	int n, a, b;cin >> n;
	while(n--){
		cin >> a >> b;cout << a;
		if(6 <= a && a <= 9)disp(a, b);
		else disp(0 < b-a ? a : 15-a, b);
	}
	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++: #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); }

int INF = 1 << 20;

struct P
{
	int d;
	string root;
	
	P() : d(INF), root("") {}
	P(int d, string root) : d(d), root(root) {}
};

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

int main()
{
	P G[10][10];
	
	rep(i, 10) rep(j, 10) if(j - i == 1 || (i <= 5 && j <= 5 && i - j == 1) || (i == 9 && j == 5))
		G[i][j] = P(1, toString(i) + toString(j));
	
	rep(k, 10) rep(i, 10) rep(j, 10) if(G[i][j].d > G[i][k].d + G[k][j].d)
		G[i][j] = P(G[i][k].d + G[k][j].d, G[i][k].root + G[k][j].root.substr(1));
	
	int n;
	cin >> n;
	
	while(n--)
	{
		int f, t;
		cin >> f >> t;
		
		string ans = G[f][t].root;
		
		rep(i, ans.size())
			cout << ans[i] << (i == ans.size() - 1 ? "\n" : " ");
	}
}