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 <cstdio>
#include <vector>
#include <queue>
#include <map>

using namespace std;

#define rep(i,b) for(int i=0; i<int(b); i++)

vector<vector<int> > G{
    {1},{0,2},{1,3},{2,4},{3,5},{6},{7},{8},{9},{5}
};

void solve(int a, int b){
    queue<pair<int,int>> q;

    int prev[10], d[10];
    rep(i,10) d[i]=1e9;
    d[a]=0;
    q.push(make_pair(a,0));
    while(q.size()){
        pair<int,int> s=q.front(); q.pop();
        int v=s.first, dis=s.second;

        for(int i=0; i<G[v].size(); i++){
            int e=G[v][i];
            if(d[e] > d[v]+1){
                prev[e]=v;
                d[e] = d[v]+1;
                q.push(make_pair(e,d[e]));
            }
        }
    }

    vector<int> ans{b};
    while(ans.back()!=a) ans.push_back(prev[ans.back()]);
    for(int i=0; i<ans.size(); i++){
        cout << ans[ans.size()-1-i] << (i+1==ans.size() ? '\n' : ' ');
    }
}

int main(){
    int n; cin>>n;
    rep(i,n){
        int a,b; cin>>a>>b;
        solve(a,b);
    }
}

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

void solve(int f,int t) {
bool r = false;
  if(f < t) {
    for(int i=0;i< t - f + 1;i++) {
      if(r) cout << " ";
      cout << f + i;
      r = true;
    }
    cout << endl;
    return;
  }

  else if(f > t) {
    if(f >= 6) {
      for(int i=0;i < 9 - f + 1;i++) {
        if(r) cout << " ";
        cout << f + i;
        r = true;
      }
      f = 5;
    }
    if(t == 5) {
      cout << endl;
      return;
    }
    for(int i=0;i< f - t + 1;i++) {
      if(r) cout << " ";
      cout << f - i;
      r = true;
    }
    cout << endl;
    return;
  }
}

int main() {
  int n,f,t;
  cin >> n;
  for(int i=0;i<n;i++) {
    cin >> f >> t;
    solve(f,t);
  }
}

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

int main()
{
  const int busstop[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  const int bussize = sizeof(busstop) / sizeof(int);

  int n;
  while (cin >> n) {
    while (n--) {
      int a, b;
      cin >> a >> b;

      int s = 0;
      for (; s < bussize; ++s) {
	if (busstop[s] == a)
	  break;
      }

      vector<int> ans;
      for (int i = s; i < bussize; ++i) {
	ans.push_back(busstop[i]);
	if (busstop[i] == b)
	  break;
      }

      if (1 <= a && a <= 5 && b < a) {
	vector<int> rev;
	for (int i = s; i >= 0; --i) {
	rev.push_back(busstop[i]);
	if (busstop[i] == b)
	  break;
	}
	if (rev.size() < ans.size())
	  ans = rev;
      }

      for (int i = 0; i < ans.size()-1; ++i)
	cout << ans[i] << " ";
      cout << ans.back() << endl;
    }
  }
  return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int n;//入力
int main()
{
  cin >>n;
  for(int i = 0;i < n;i++){
    int start;
    int finish;
    int ans;
    bool flag;
    cin >>start>>finish;
    if(start >5&&finish <=5){
      cout <<start;
      cout <<" ";
      ans = start;
      for(int j = 1;j <=(9-ans);j++){
	cout <<++start;
	cout <<" ";
      }
    for(int j = 5;j !=finish;j--){
      cout <<j;
      cout <<" ";
    }
    cout <<finish<<endl;
    continue;
    }
    if(start >6&&finish >5&&finish <start){
      cout <<start;
      cout <<" ";
      ans = start;
      for(int j = 1;j <=(9-ans);j++){
	cout<<++start;
	cout <<" ";
      }
      for(int j = 5; j!=-1;j--){
	cout <<j;
	cout <<" ";
      }
      for(int j = 1;j <finish;j++){
	cout <<j;
	cout <<" ";
      }
      cout <<finish<<endl;
      continue;
    }
    if(finish >start){
      ans = finish-start;
      flag =true;
    }
    else if(finish <start){
      ans = start-finish;
      flag =false;
    }
  
    if(flag){
    cout <<start;
    cout <<" ";
    for(int j = 1;j <ans;j++){
      cout <<++start;
      cout <<" ";
    }
    cout <<finish<<endl;
    }
    else if(!flag){
      cout <<start;
      cout <<" ";
      for(int j = 1;j <ans;j++){
	cout <<--start;
	cout <<" ";
      }
      cout <<finish<<endl;
    }
  }
  return 0;
}

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

int main(void){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		printf("%d",f);
		if(f<=5){
			if(t>f){
				while(f!=t){
					f++;
					printf(" %d",f);
				}
			}
			if(t<f){
				while(f!=t){
					f--;
					printf(" %d",f);
				}
			}
		}else if(f>5){
			if(f<t && t<=9){
				while(f!=t){
					f++;
					printf(" %d",f);
				}
			}else if(t==5){
				while(f!=9){
					f++;
					printf(" %d",f);
				}
				f=5;
				printf(" %d",f);
			}else{
				while(f!=9){
					f++;
					printf(" %d",f);
				}
				f=5;
				printf(" %d",f);
				if(t<5){
					while(f!=t){
						f--;
						printf(" %d",f);
					}
				}else{
					while(f!=0){
						f--;
						printf(" %d",f);
					}
					while(f!=t){
						f++;
						printf(" %d",f);
					}
				}
			}
		}
		printf("\n");
	}
    return 0;
}

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

vector<int> route = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};

int main() {
    int n, s, t;
    cin >> n;
    for (int i=0; i<n; ++i) {
        cin >> s >> t;
        int m = route.size();
        int l = -1, r = -1;
        for (int j=1; j<=m; ++j) {
            for (int k=0; k+j-1<m; ++k) {
                if (route[k] == s && route[k+j-1] == t) {
                    l = k;
                    r = k+j-1;
                    break;
                }
            }
            if (0 <= l) {
                break;
            }
        }
        for (int i=l; i<=r; ++i) {
            cout << (i == l ? "" : " ") << route[i];
        }
        cout << endl;
    }
    return 0;
}