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<cstdio>
using namespace std;

int n,m,l;

void solve(int p, int d){
  
  if(p == m){
    printf("%d\n",p);
    return;
  }
  
  printf("%d ",p);
  
  if(p == 9) solve(5, 0);
  else if(!p || d) solve(p+1, 1);
  else solve(p-1, 0);

}

int main(){
  
  scanf("%d",&l);
  
  while(l--){
    scanf("%d%d",&n,&m);
    if(n == 9 || (n < 6 && n > m)) solve(n, 0);
    else solve(n, 1);
  }
  
}

C++: #include<iostream>
#include<queue>
using namespace std;
int main()
{
	int n;

	cin >> n;
	for(int i = 0; i < n; ++i){
		int st, ed;
		queue<int> q;
		cin>>st>>ed;

		if( st == ed ){
			cout << "\n";
			continue;
		}

		if( ed <= 5 ){
			if( st > 5 ){
				for(int i = st; i <= 9; ++i) q.push( i ); 
				for(int i = 5; i >= ed; --i) q.push( i );
			}else{
				if( st > ed )
					for(int i = st; i >= ed; --i) q.push( i );
				else
					for(int i = st; i <= ed; ++i) q.push( i );
			}
		}else{
			if( st < ed ){
				for(int i = st; i <= ed; ++i) q.push( i );
			}else{
				for(int i = st; i <= 9; ++i) q.push( i );
				for(int i = 5; i <= ed; ++i) q.push( i );
			}
		}
		cout << q.front();
		q.pop();
		while( !q.empty() ){
			cout << ' ' << q.front();
			q.pop();
		}
		cout << '\n';
	}
	return 0;
}

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

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

string x[2] = {"0 1 2 3 4 5 6 7 8 9 5 4 3 2 1 ", "0 1 2 3 4 5 9 8 7 6 5 4 3 2 1 "};

int main(void){
	x[0] += x[0]; x[1] += x[1];
	int n, i, s, t, l, r;
	pair<int,string> res;
	scanf("%d", &n);
	for(;n--;){
		res.first = 12345;
		scanf("%d %d", &s, &t);
		rep(i, 2){
			rep(l, x[i].size())if(x[i][l] == '0' + s){
				for(r = l + 1;r < x[i].size();++r)if(x[i][r] == '0' + t)break;
				if(r < x[i].size() && res.first > r - l){
					res.first = r - l + 1;
					res.second = x[i].substr(l, r - l + 1);
				}
			}

		}
		cout << res.second << endl;
	}
	
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int F = 9;

int main()
{
    int s, g, n;  cin >> n;
    rep(k, n)
    {
        vector<int> ans;
        cin >> s >> g;
        if(s <= 5 && g <= 5)//OK
        {
            if( s < g)for(int j = s;j <= g;j++) ans.push_back(j);

            if(s > g)for(int j = s; j >= g;j--) ans.push_back(j);
        }
        if( s>5 && g <= 5)
        {
            for(int j = s; j<= F;j++) ans.push_back(j);

            for(int j = 5; j >= g;j--) ans.push_back(j);
        }
        if(s <= 5 && g> 5)//OK
            for(int j = s; j<=g;j++) ans.push_back(j);

        if(s >5 && g > 5)
        {
            if( s < g)for(int j = s; j<=g;j++) ans.push_back(j);
            if( s > g )
            {
                for(int j = s; j<=F;j++) ans.push_back(j);
                for(int j = 5; j>0;j--) ans.push_back(j);
                for(int j = 0;j <=g;j++) ans.push_back(j);
            }
        }

        rep(j,ans.size()){ cout << ans[j]; if(j == ans.size()-1) break; cout << " ";}
        cout << endl;
    }
    return 0;
}

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

#define INF 999999999

int gcd(int x, int y) {
	if (x % y == 0)return y;
	else return gcd(y, x%y);
}

int lcm(int x, int y) {
	return x*y / gcd(x, y);
}

int main() {
	list<int> bus = { 0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0 };
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		int c = INF, d;
		vector<vector<int> > path;
		for (auto itr = bus.begin(); itr != bus.end(); itr++) {
			if (*itr == a) {
				vector<int> tmp;
				for (auto itrr = itr; *itrr != b; itrr++) {
					tmp.push_back(*itrr);
					auto tmp = itrr;
					if (++tmp == bus.end())itrr = bus.begin();
				}
				tmp.push_back(b);
				path.push_back(tmp);
				if (c > tmp.size()) {
					c = tmp.size();
					d = path.end() - path.begin() - 1;
				}
			}
		}
		for (int i = 0; i + 1 < path[d].size(); i++) {
			cout << path[d][i] << " ";
		}
		cout << b << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

main(){
  int n;
  while(cin >> n){
    for(int c=0;c<n;c++){
      int s, g;
      cin >> s >> g;
      int d;
      if(s<=5 && g<s){
	d=0;
      }else{
	d=1;
      }
      if(d==1){
	bool finish=false;
	for(int i=s;i<10;i++){
	  cout << i;
	  if(i==g){
	    finish=true;
	    break;
	  }
	  cout << ' ';
	}
	if(finish){
	  cout << endl;
	  continue;
	}
	for(int i=5;i>=0;i--){
	  cout << i;
	  if(i==g){
	    break;
	  }
	  cout << ' ';
	}
	cout << endl;
      }else{
	for(int i=s;i>=0;i--){
	  cout << i;
	  if(i==g) break;
	  cout << ' ';
	}
	cout << endl;
      }
    }
  }
  return 0;
}

C++: #include<stdio.h>

int main(){
	int n,a,b,i,j;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&a,&b);
		if(a<6){
			if(a-b>0){
				for(j=a;j>b;j--){
					printf("%d ",j);
				}
				printf("%d\n",b);
			}else{
				for(j=a;j<b;j++){
					printf("%d ",j);
				}
				printf("%d\n",b);
			}
		}else{
			if(b>a){
				for(j=a;j<b;j++){
					printf("%d ",j);
				}
				printf("%d\n",b);
			}else if(b<6){
				for(j=a;j<10;j++){
					printf("%d ",j);
				}
				for(j=5;j>b;j--){
					printf("%d ",j);
				}
				printf("%d\n",b);
			}else{
				for(j=a;j<10;j++){
					printf("%d ",j);
				}
				for(j=5;j>0;j--){
					printf("%d ",j);
				}
				for(j=0;j<b;j++){
					printf("%d ",j);
				}
				printf("%d\n",b);
			}
		}
	}
	return 0;
}