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 <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 main()
{
  char s[]="012345678954321012345678";
 int len=24;
  int n;
  cin >>n;
  while(n--){
        int start,goal; cin>>start>>goal;
        int ans=100,ans_st,ans_finish;
        for(int i=0;i<len;i++){
            if(s[i]!=start+'0') continue;
            for(int j=i+1;j<len;j++){
                if(s[j]==goal+'0'){
		  if(ans>j-i){
		  ans=j-i;
		  ans_st=i;
		  ans_finish =j;
		  }
                }
            }
        }
	cout <<s[ans_st];
	cout <<" ";
	for(int i =ans_st+1;i <ans_finish;i++){
	  cout <<s[i]<<" ";
	}
	cout <<s[ans_finish];
	cout <<endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  
  int Tc; cin >> Tc;
  
  while(Tc--) {
    int a, b; cin >> a >> b;
    int const S = a;
    int const T = b;
    
    if(S < T && S < 5) {
      for(int i=S; i<=T; i++) {
	if(i>S) cout << " ";
	cout << i;
      }
      cout << endl;
    }
    else if(S > T && S < 5) {
      for(int i=S; i>=T; i--) {
	if(i<S) cout << " ";
	cout << i;
      }
      cout << endl;
    }
    else if(S == 5) {
      if(0<=T && T<5) {
	for(int i=S; i>=T; i--) {
	  if(i<S) cout << " ";
	  cout << i;
	}
	cout << endl;
      }
      else {
	for(int i=S; i<=T; i++) {
	  if(i>S) cout << " ";
	  cout << i;
	}
	cout << endl; goto EXIT;
      }
    }
    else {
      assert(S > 5);
      if(5 < T && T < S) {
	for(int i=S; i<10; i++) {
	  if(i>S) cout << " ";
	  cout << i;
	}
	for(int i=5; i<=T; i++) {
	  cout << " "; cout << i;
	}
	cout << endl;
	
      }
      else if(S < T) {
	for(int i=S; i<=T; i++) {
	  if(i>S) cout << " ";
	  cout << i;
	}
	cout << endl;
      }
      else {
	for(int i=S; i<10; i++) {
	  if(i>S) cout << " ";
	  cout << i;
	}
	for(int i=5; i>=T; i--) {
	  cout << " " << i;
	}
	cout << endl;
      }
    }
    
  EXIT:;
  }
  
  return 0;
}

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

int main(){
	int n;
	cin >> n ;
	for(int t=0 ; t < n ; t++ ){
		int s, g;
		cin >> s >> g;
		if( g < s && s <= 5 ){
			for(int i=s ; i >= g ; i-- ){
				cout << i;
				(i == g)? cout << endl : cout << " ";
			}
		}else if( s >= 6 && g <= 5 ){
			for(int i=s ; i <= 9 ; i++ ){
				cout << i << " ";
			}
			for(int i=5 ; i >= g ; i-- ){
				cout << i;
				(i == g)? cout << endl : cout << " ";
			}
		}else if( s >= 6 && g >= 6 && g < s ){
			for(int i=s ; i <= 9 ; i++ ){
				cout << i << " ";
			}
			cout << "5 4 3 2 1 ";
			for(int i=0 ; i <= g ; i++ ){
				cout << i;
				(i == g)? cout << endl : cout << " ";
			}
		}else{
			for(int i=s ; i <= g ; i++ ){
				cout << i;
				(i == g)? cout << endl : cout << " ";
			}
		}
	}
}

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

const int INT = -1;
int nextstop[10][2] = {{1,1},{0,2},{1,3},{2,4},{3,5},{4,6},{INT,7},{INT,8},{INT,9},{INT,5}};

int main(){
	int n,start,goal,a;
	vector<int> rout;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> start >> goal;
		for(int j = 0;j < 2;++j){
			a = start;
			rout.clear();
			while(a != goal){
				rout.push_back(a);
				a = nextstop[a][j];
				if(a == -1 || a == 0){
					break;
				}
			}
			if(a == goal) {
				rout.push_back(a);
				break;
			}
		}
		for(int j = 0;j < rout.size();++j){
			if(j) cout << " ";
			cout << rout[j];
		}
		cout << endl;
	}
	return 0;
}

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

int from, to;
int d[15] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
int p[2][15];

int calc(int pos, int k) {
  int cost = 0;
  p[k][0] = d[pos];
  while(d[pos] != to) {
    pos = (pos+1)%15;
    cost++;
    p[k][cost] = d[pos];
  }
  return cost;
}

void solve() {
  int k = 0;
  int mini = 999999;
  int mink = -1;
  for(int i = 0; i < 15; ++i) {
    if(d[i] == from) {
      int c1 = calc(i, k);
      if(c1 < mini) {
	mini = c1;
	mink = k;
      }
      k++;
    }
  }
  for(int i = 0; i <= mini; ++i) {
    if(i != 0) cout << " ";
    cout << p[mink][i];
  }
  cout << endl;
}

main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> from >> to;
    solve();
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int s,g;
  cin >> s >> g;
  bool flag = false;
  if(s >= 6 && s <= 9){
    if(g >= s){
      for(int i=s;i<=g;i++){
	if(flag) cout << " ";
	cout << i;
	flag = true;
      }
      cout << endl;
      return 0;
    }
    else {
      for(int i=s;i<=9;i++){
	if(flag) cout << " ";
	cout << i;
	flag = true;
      }
      if(g >= 6 && s > g){
	for(int i=5;i> 0;i--){
	  if(flag) cout << " ";
	  cout << i;
	  flag  = true;
	}
	for(int i=0;i<=g;i++){
	  if(flag) cout << " ";
	  cout << i;
	  flag  = true;
	}
	cout << endl;
	return 0;
      }
      s = 5;
    }
  }
  if(g - s > 0){
    for(int i=s;i<=g;i++){
      if(flag) cout << " ";
      cout << i;
      flag  = true;
    }
    cout << endl;
  }
  else {
    for(int i=s;i>=g;i--){
      if(flag) cout << " ";
      cout << i;
      flag = true;
    }
    cout << endl;
  }
}