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;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define PB push_back
#define p(a,b) g.PB(pii(a, b))
#define INF (1<<29)

typedef pair<int, int> pii;
typedef vector<pii> vp;

int main() {
	vp g; //pos to
	REP(i, 9) p(i, i + 1);
	p(9, 10);
	REP(i, 4) p(5 - i, i + 11);
	p(1, 0);
	
	int n;
	cin >> n;
	while (n--) {
		int prev[2][9], miner[2], tmp[2];
		int a, b;
		scanf("%d %d", &a, &b);
		
		tmp[0] = tmp[1] = INF;
		REP(i, g.size()) if (g[i].first == a) {
			if (tmp[0] == INF) tmp[0] = i;
			else tmp[1] = i;
		}
		
		miner[0] = miner[1] = INF;
		REP(i, 2) {
			if (tmp[i] == INF) break;
			
			queue<int> que; //pos
			que.push(tmp[i]);
			
			miner[i] = 0;
			while(true) {
				int pos = g[que.front()].first;
				int to = g[que.front()].second;
				que.pop();
				
				prev[i][miner[i]++] = pos;
				if (pos == b) break;
				
				que.push(to);
			}
		}
		
		int ans = miner[0] < miner[1] ? 0 : 1;
		REP(i, miner[ans]) {
			if (i != 0) printf(" ");
			printf("%d", prev[ans][i]);
		}
		cout << endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;

int main(){
	int n; cin>>n;
	vector<int> v;
	FOR(i,10) v.push_back(i);
	for(int i = 5; i > 0; i--) v.push_back(i);
	while(n--){
		int x,y; cin>>x>>y;
		int ans_l,a_cnt = 100;
		FOR(i,sz(v)){
			if(v[i] == x){
				int cnt = 1;
				for(int j = i+1; v[j] != y; j = (j+1) % sz(v))
					cnt++;
				if(a_cnt > cnt){
					a_cnt = cnt;
					ans_l = i;
				}
			}
		}

		for(int i = 0; i <= a_cnt; i++) printf("%d%c",v[(ans_l+i)%sz(v)],i==a_cnt?'\n':' ');
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

V ans;
ll pos, goal, n;

ll d[10][10];
bool used[10];

void solve(ll pos){
	ans.push_back(pos);
	if (pos == goal){
		REP(i, ans.size()){
			i == ans.size() - 1 ? 
				cout << ans[i] << endl : cout << ans[i] << " ";
		}
		return;
	}

	for (int i = 0; i < 10; i++){
		if (d[pos][i] == 1){
			if (used[i] == 0){
				used[i] = 1;
				solve(i);
				ans.pop_back();
				used[i] = 0;
			}
		}
	}
	return;
}

int main(){
	//REP(i, 10)REP(j, 10)d[i][j] = INF;
	d[0][1] = d[1][0] = d[1][2] = d[2][1] = d[2][3] = d[3][2] = d[3][4] = 1;
	d[4][3] = d[4][5] = d[5][4] = d[5][6] = d[6][7] = d[7][8] = d[8][9] = d[9][5] = 1;
	cin >> n;
	REP(i, n){
		cin >> pos >> goal;

		if (pos == goal){
			cout << pos << endl;
			continue;
		}

		REP(j, 10)used[j] = 0;
		used[pos] = 1;
		solve(pos);
		ans.clear();
	}
}

C++: #include <iostream>

using namespace std;


int main(void){
	int s,e,n;
	
	cin >> n;
	
	for(int i=0;i<n;i++){
		cin >> s >> e;
		cout << s;
		if(s <= 5){
			if(e < s){
				for(int j=s-1;j>=e;j--){
					cout << " " << j;
				}
				cout << endl;
			}else{
				for(int j=s+1;j<=e;j++){
					cout << " " << j;
 				}
 				cout << endl;
			}
		}else{
			if(e >= 6){
				if(s < e){
					for(int j=s+1;j<=e;j++){
						cout << " " << j;
					}
					cout << endl;
				}else{
					for(int j=s+1;j<=9;j++){
						cout << " " << j;
					}
					for(int j=5;j>=0;j--){
						cout << " " << j;
					}
					for(int j=1;j<=5;j++){
						cout << " " << j;
					}					
					for(int j=6;j<=e;j++){
						cout << " " << j;
					}
					cout << endl;
				}
			}else{
				for(int j=s+1;j<=9;j++){
					cout << " " << j;
				}
				for(int j=5;j>=e;j--){
					cout << " " << j;
				}
				cout << endl;
			}
		}
	}

}

C++: #include <iostream>
#include <queue>
#include <vector>

#define MAX_V 10

using namespace std;

struct edge_t {
    int from, to;
    edge_t(int from=0, int to=0) :
        from(from), to(to) {}
};

vector<edge_t> graph[MAX_V];

void init() {
    for (int i = 0; i < 9; i++) 
        graph[i].push_back(edge_t(i, i+1));
    graph[9].push_back(edge_t(9, 5));
    for (int i = 5; i > 0; i--) 
        graph[i].push_back(edge_t(i, i-1));
}

struct state_t {
    int stop;
    string path;
    state_t(int stop=0, string path="") :
        stop(stop), path(path) {}
};

void show_path(int s, int g) {
    queue<state_t> q;
    q.push(state_t(s, string("")));

    while (!q.empty()) {
        state_t p = q.front(); q.pop();
        if (p.stop == g) {
            string path = p.path;
            path.push_back(g+'0');
            cout << path[0];
            for (int i = 1; i < path.size(); i++) {
                cout << ' ' << path[i];
            }
            cout << endl;
            break;
        }
        for (int i = 0; i < graph[p.stop].size(); i++) {
            edge_t e = graph[p.stop][i];
            string path = p.path; 
            path.push_back(e.from + '0');
            q.push(state_t(e.to, path));
        }
    }
}

int main() {
    init();
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        int s, g; cin >> s >> g;
        show_path(s, g);
    }
    return 0;
}

C++: #include <cstdio>
#include <cstring>
char* bus="0123456789543210";
char s[25], t[25];
int main()
{
    int n; scanf("%d", &n);
    while (n--) {
        int a, b; scanf("%d%d", &a, &b);
        int k = 0;
        for (int i = 0; i < strlen(bus); ++i)
            if (bus[i] == a + '0') k = i;
        int j = 0;
        for (int i = k; i < strlen(bus); ++i) {
            s[j++] = bus[i];
            s[j++] = ' ';
            if (bus[i] == b + '0') break;
        }
        if (j == 2) for (j = 0; j < 25; ++j) s[j] = 'x';
        s[j-1] = '\0';

        k = 0;
        for (int i = 0; i < strlen(bus); ++i)
            if (bus[i] == a + '0') { k = i; break; }
        j = 0;
        for (int i = k; i < strlen(bus); ++i) {
            t[j++] = bus[i];
            t[j++] = ' ';
            if (bus[i] == b + '0') break;
        }
        if (j == 2) for (j = 0; j < 25; ++j) t[j] = 'x';
        t[j-1] = '\0';
        puts(strlen(s) < strlen(t) ? s : t);
    }
    return 0;
}