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(){
  int bus[20],index;
  for(int i=0;i<=9;i++)bus[i]=i;
  index=10;
  for(int i=5;i>=0;i--)bus[index++]=i;
  //for(int i=0;i<16;i++)cout << bus[i] << " ";
  //cout << endl;
  int n,st,ed,rs;
  cin >> n;
    vector<int> perm,vec;
    bool giveway;
    for(int k=0;k<n;k++){
      perm.clear();vec.clear();
      giveway = false;
      cin >> st >> ed;
      rs = st;
      
      while(st != ed){

	perm.push_back(st);
	if(!giveway)st++;
	if(giveway)st--;
	if(!giveway &&st == 10){
	  st = 5;
	  giveway = true;
	}
	else if(giveway && st == 0){
	  giveway = false;
	}
      }
      giveway = false;
      perm.push_back(ed);
     
      if(1<=rs && rs<=5){
     
	while(rs != ed){
	  vec.push_back(rs);
	  if(!giveway)rs--;
	  if(giveway)rs++;
	  if(!giveway &&rs == 0){
	    giveway = true;
	  }
	  else if(giveway && rs == 10){
	    rs = 5;
	    giveway = false;
	  }
	}
  vec.push_back(ed);
      if(perm.size() > vec.size() )perm = vec;
      }
    
  
      for(int i=0;i<perm.size();i++){
	cout << perm[i];
	i == perm.size()-1 ? cout << endl:cout << " ";
      }


    }

  
  return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    int n;
    string s = "0123456789543210123456789543210123456789543210";
    cin >> n;
    for(int i=0;i<n;i++){
	char a,b;
	cin >> a >> b;
	int m = (int)(a - '0');
	int l = (int)(b - '0');
	if(0<= m && m  <= 5 && 0<= l && l <= 5){
	    if(m < l){
		cout << m;
		for(int i=m+1;i<=l;i++){
		    cout << " " << i;
		}
		cout << endl;
	    }else{
		cout << m;
		for(int i=m-1;i>=l;i--){
		    cout << " " << i;
		}
		cout << endl;
	    }
	    continue;
	}
	int x = 0;
	cout << a;
	while(s[x] != a) x++;
	while(s[x] != b){
	    x++;
	    cout << " "<< s[x];
	}
	cout << endl;

    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

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

int s,g;
vector<int> w1,w2;
vector<int> ss;

void solve(){
	w1.clear();
	w2.clear();
	ss.clear();
	REP(i,15){
		if (way[i]==s){
			ss.push_back(i);
		}
	}
	if (ss.size()==1){
		int v=ss[0];
		while (way[v]!=g){
			printf("%d ",way[v]);
			v++;
			v%=15;
		}
		printf("%d\n",g);
		return;
	}
	int v=ss[0];
	while (way[v]!=g){
		w1.push_back(way[v]);
		v++;
		v%=15;
	}
	w1.push_back(g);
	v=ss[1];
	while (way[v]!=g){
		w2.push_back(way[v]);
		v++;
		v%=15;
	}
	w2.push_back(g);
	if (w1.size()<w2.size()){
		REP(i,(int)w1.size()){
			if (i) printf(" ");
			printf("%d",w1[i]);
		}
		printf("\n");
	}else{
		REP(i,(int)w2.size()){
			if (i) printf(" ");
			printf("%d",w2[i]);
		}
		printf("\n");
	}
}

int main(){
	int n;
	cin>>n;
	REP(i,n){
		cin>>s>>g;
		solve();
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int num[]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
    for(int i=0,x,y;i<n;i++){
        cin>>x>>y;
        if(x<6&&y<6&&y-x>0){
            cout<<num[x];
            for(int j=x+1;j<=y;j++)cout<<" "<<num[j];
            cout<<endl;
        }
        else if(x<6&&y<6){
            cout<<num[15-x];
            for(int j=16-x;j<16-y;j++)cout<<" "<<num[j];
            cout<<endl;
        }
        else{
            cout<<num[x];
            for(int j=x+1;num[j-1]!=y;j++){
                if(j==16)j=1;
                cout<<" "<<num[j];
            }
            cout<<endl;
        }
    }

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

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

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	int s[15] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
	int N;
	cin>>N;
	for(int ds=0;ds<N;ds++){
		int A,B;
		cin>>A>>B;
		vector<int> ans;
		int ss = find(s,s+15,A)-s, d = 0;
		for(int i=0;i<15;i++, d++){
			if(s[(ss+i)%15]==A){
				d = 0; ans.clear();
			}
			ans.push_back(s[(ss+i)%15]);
			if(s[(ss+i)%15]==B) break;
		}
		printf("%d",ans[0]); for(int i=1;i<ans.size();i++) printf(" %d",ans[i]); puts("");
	}
	return 0;
}