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<bits/stdc++.h>
using namespace std;


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

int ans[10][10];
int tmp[10][10];

int main(){
  for(int i=15;i>=0;i--){

    for(int a=0;a<15;a++){

      int from=A[a];
      int to=A[ (a+i)%15 ];
      
      ans[ from ][ to ]=i;
      tmp[ from ][ to ]=a;
    }
  }

  int tc;
  cin>>tc;

  for(int Tc=0;Tc<tc;Tc++){

    int from;
    int to;
    cin>>from>>to;

    for(int i=0;i<=ans[from][to];i++){
      if(i>0)cout<<' ';

      cout<< A[ (tmp[from][to]+i)%15 ];
    }
    cout<<endl;
    
  }
  
  return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#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 each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
string str = "0 1 2 3 4 5 6 7 8 9 5 4 3 2 1 0 1 2 3 4 5 6 7 8";
string getstr(char s, char g) {
	int i, j;
	for (i = 0; str[i] != s; i++);
	for (j = i; str[j] != g; j++)if (str[j] == s)i = j;
	return str.substr(i, j - i + 1);
}
signed main() {
	int n; cin >> n;
	while (n--) {
		char a, b; cin >> a >> b;
		cout << getstr(a, b) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cctype>
#include <sstream>
#include <algorithm>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for (iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n;
  while(cin >> n) {
    while(n--) {
      int s,t;
      cin >> s >> t;
      vector<int> a;
      if(s<=5) {
	if(s<=t) {
	  while(s<=t) a.push_back(s++);
	} else {
	  while(s>=t) a.push_back(s--);
	}
      } else {
	if(t>=6 && s>t) {
	  while(s!=0) {
	    a.pb(s);
	    if(s>=6 && s<=9) s++;
	    else s--;
	    if(s==10) s=5;
	  }
	  while(s<=t) a.push_back(s++);	  
	} else {
	  while(1) {
	    a.pb(s);
	    if(s==t) break;
	    if(s>=6 && s<=9) s++;
	    else s--;
	    if(s==10) s=5;
	  }
	}
      }
      rep(i,a.size()) {
	if(i!=0) cout << " ";
	cout << a[i];
      }
      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++: #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){
				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 >= 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>=5;j--){
						printf("%d ",j);
					}

					for(int j=4;j>=0;j--){
						printf("%d ",j);
					}

					for(int j=1;j<=4;j++){
						printf("%d ",j);
					}

					for(int j=5;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" : " ");
					}
				}
			}

		}
	}
}