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 <stdio.h>
#include <math.h>

int main(void) {
    int bus_stop[15] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
    int start, end, spin, n_spin;
    int num, i, j, idx1, idx2;
    
    scanf("%d", &num);
    
    while(num--) {
    
        scanf("%d %d", &start, &end);
        
        for(j = 0; j < 10; j++) {
            if(bus_stop[j] == start) {
                idx1 = j;
            }
            if(bus_stop[j] == end) {
                idx2 = j;
            }
        }

        spin = (idx1 + 1) + (15 - idx2);
        n_spin = fabs(idx2 - idx1) + 1;

        if(n_spin < spin) {
            if(start > end) {
                for(i = idx1; i >= idx2; i--) {
                    printf("%d", bus_stop[i]);
                    if(i == idx2)
                        putchar('\n');
                    else
                        putchar(' ');
                }
            }
            else if(start < end) {
                for(i = idx1; i <= idx2; i++) {
                    printf("%d", bus_stop[i]);
                    if(i == idx2)
                        putchar('\n');
                    else
                        putchar(' ');
                }
            }
        } else if(spin < n_spin) {
            for(i = idx1; i >= 0; i--) {
                printf("%d", bus_stop[i]);
                if(i == idx2)
                    putchar('\n');
                else
                    putchar(' ');
            }
            for(i = 14; i >= idx2; i--) {
                printf("%d", bus_stop[i]);
                if(i == idx2)
                    putchar('\n');
                else
                    putchar(' ');
            }
        }
    }
    
    return(0);
}

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

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

int main() {
  
  int n, s, t;
  cin >> n;
  
  rep(i,n) {
    cin >> s >> t;
    if(s <= 5) {
      if(s < t) {
	cout << s;
	for(int j=s+1; j<=t; j++) cout << " " << j;
	cout << endl;
      }
      if(s > t) {
	cout << s;
	for(int j=s-1; j>=t; j--) cout << " " << j;
	cout << endl;
      }
    }
    else {
      if(t <= 5) {
	for(int j=s; j<10; j++) cout << j << " ";
	s=5;
	cout << s;
	for(int j=s-1; j>=t; j--) cout << " " << j;
	cout << endl;
      } else if(s < t) {
	cout << s;
	for(int j=s+1; j<=t; j++) cout << " " << j;
	cout << endl;
      } else {
	for(int j=s; j<10; j++) cout << j << " ";
	cout << "5 4 3 2 1 0 1 2 3 4 5";
	for(int j=6; j<=t; j++) cout << " " << j;
	cout << endl;
      }
    }
  }
  
  return 0;
}

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

#define INF (1<<20)
#define min(a,b) ((a) > (b) ? (b) : (a))

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

int main(){
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			dp[i][j] = INF;
		}
		dp[i][i] = 0;
	}
	for(int i = 0; i < 15; i++){
		dp[from[i]][to[i]] = 1;
	}
	for(int k = 0; k < 10; k++){
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}

	int n,s,e;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d%d",&s,&e);
		vector<int> r = vector<int>();
		r.push_back(e);
		while(s != e){
			for(int j = 0; j < 10; j++){
				if(dp[s][e] - dp[s][j] == 1 && dp[j][e] == 1){
					e = j;
					r.push_back(j);
					break;
				}
			}
		}
		for(int i = r.size() - 1; i > 0; i--){
			printf("%d ",r[i]);
		}
		printf("%d\n",r[0]);

	}
	return 0;
}

C++: #include<iostream>
int main(){int s,t,d,n;std::cin>>n;while(n--){std::cin>>s>>t;d=(t<s&&s<6)?-1:1;while(t!=s){printf("%d ",s);s+=d;if(s==10){d=-1;s=5;}else if(s==-1){d=s=1;}}printf("%d\n",t);}return 0;}

C++: #include <iostream>
using namespace std;
int s[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};

int disp(int a, int b){
	for(int i = a+1;;i++){
		cout << " " << s[i%15];
		if(s[i%15] == b){cout << endl;return 0;}
	}
	return 0;
}

int main(){
	int n, a, b;cin >> n;
	while(n--){
		cin >> a >> b;
		cout << a;
		if(6 <= a && a <= 9)disp(a, b);
		else disp(0 < b-a ? a : 15-a, b);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
	int q;
	cin >> q;
	for(int i=0;i<q;i++)
	{
		int from,to;
		cin >> from >> to;
		if(from < to)
		{
			for(int j=from;j<to;j++)cout << j << ' ';
			cout << to << endl;
			continue;
		}
		if(from<=5)
		{
			for(int j=from;j>to;j--)cout << j <<  ' ';
			cout << to << endl;
		}
		else if(to>5)
		{
			for(int j=from;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=5;j<to;j++)cout << j << ' ';
			cout << to << endl;
		}
		else
		{
			for(int j=from;j<=9;j++)cout << j << ' ';
			for(int j=5;j>to;j--)cout << j << ' ';
			cout << to << endl;
		}
	}
	return 0;
}

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

int n;
queue<int> Q, R;

int main()
{
    for(int i = 0; i < 10; i++)
        Q.push(i);

    for (int i = 5; i > 0; i--)
        Q.push(i);

    cin >> n;

    for (int i = 0; i < n; i++) {
        int a, b;

        cin >> a >> b;

        int c = Q.front();

        while (c != a) {
            Q.push(c);
            Q.pop();
            c = Q.front();
        }

        if (a == 0 || a > 5) {
            while (c != b) {
                cout << c << " ";
                Q.push(c);
                Q.pop();
                c = Q.front();
            }
        }
        else {
            R.push(c);
            Q.push(c);
            Q.pop();
            c = Q.front();

            while (c != b && c != a) {
                R.push(c);
                Q.push(c);
                Q.pop();
                c = Q.front();
            }

            if (c == a) {
                while (c != b) {
                    cout << c << " ";
                    Q.push(c);
                    Q.pop();
                    c = Q.front();
                }
            }
            else {
                while (!R.empty()) {
                    cout << R.front() << " ";
                    R.pop();
                }
            }
        }

        cout << b << endl;
    }

    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	char s[]="0123456789543210";

	int n;	cin>>n;
	while(n--){
		int start,goal;	cin>>start>>goal;
		int ans=100,ans_st;
		for(int i=0;i<16;i++){
			if(s[i]!=start+'0')	continue;
			for(int j=i+1;j<16;j++){
				if(s[j]==goal+'0'){
					if(ans>j-i)	ans=j-i,ans_st=i;
				}
			}
		}
		for(int i=ans_st;;i++){
			cout<<(i==ans_st?"":" ")<<s[i];
			if(s[i]==goal+'0')	break;
		}
		cout<<endl;
	}

	return 0;
}