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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

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

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a) * b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
	return l.first + t * (l.first - l.second);
}

bool intersectSP(const line &l, const xy_t &p){
	return abs(l.first- p) + abs(l.second - p) - abs(l.first - l.second) < EPS;
}

double distanceSP(line s, xy_t p){
	const xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

int next1[] = {
	1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0
};
int next2[] = {
	1, 0, 1, 2, 3, 4, 5
};

int main(){
	int n;
	cin >> n;
	rep(t, n){
		int a, b;
		cin >> a >> b;
		if(a > 5 || a <= 5 && a < b){
			while(a != b){
				cout << a << " ";
				a = next1[a];
			}
			cout << b << endl;
		}else{
			while(a != b){
				cout << a << " ";
				a = next2[a];
			}
			cout << b << endl;
		}
	}
	return 0;
}

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

int main(){
	int n;
	cin>>n;
	int busstop[15]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
	for(int i=0;i<n;i++){
		int start,stop,l,j;
		vector<int> ans1,ans2;
		cin>>start>>stop;
		for(l=start;busstop[l%15]!=stop;l++){
			ans1.push_back(busstop[l]);
		}
		ans1.push_back(busstop[l]);
		for(j=15-start;busstop[j%15]!=stop;j++){
			ans2.push_back(busstop[j]);
			if(j==14)j=-1;
		}
		ans2.push_back(busstop[j]);
		if(ans1.size()<ans2.size()){
			for(int k=0;k<(ans1.size()-1);k++){
				cout<<ans1[k]<<" ";
			}
			cout<<ans1[ans1.size()-1]<<endl;
		}else{
			for(int k=0;k<(ans2.size()-1);k++){
				cout<<ans2[k]<<" ";
			}
			cout<<ans2[ans2.size()-1]<<endl;
		}
	}
	return 0;
}

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

int main(){
	int n,s,g;
	int seq[]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
	cin >> n;
	
	while(n--){
		cin >> s >> g;
		for(int i=0;i<16;i++){
			if(s<=5 && s>g){
				if(seq[10+i]==s){
					for(int j=10+i;j<16;j++){
						if(j!=10+i)cout << " ";
						cout << seq[j];
						if(seq[j]==g)break;
					}
					cout << endl;
					break;
				}
			}else{
				if(seq[i]==s){
					for(int j=i;j<16;j++){
						if(j!=i)cout << " ";
						cout << seq[j];
						if(seq[j]==g)break;
					}
					cout << endl;
					break;
				}
			}
		}
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> way = {6, 7, 8, 9, 5, 4, 3, 2, 1, 0};
    for(int i = 0; i < n; i++)
    {
        int s, g; cin >> s >> g;
        if(s < g)
        {
            for(int i = s; i <= g; i++)
            {
                if(i != s) cout << " ";
                cout << i;
            }
        }
        else if(s <= 5 and g <= 5)
        {
            for(int i = s; i >= g; i--)
            {
                if(i != s) cout << " ";
                cout << i;
            }
        }
        else
        {
            int pos = s - 6;
            vector<int> ans;
            while(true)
            {
                ans.push_back(way[pos]);
                if(way[pos] == g) break;
                pos++;
                if(pos >= way.size())
                {
                    for(int i = 1; i <= g; i++) ans.push_back(i);
                    break;
                }
            }
            for(int i = 0; i < ans.size(); i++)
            {
                if(i) cout << " ";
                cout << ans[i];
            }
        }
        cout << endl;
    }
    return 0;
}

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

void solve(int s, int g){
	if(s <= 5){
		if(s < g){
			for(int i = s; i < g; i++){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}else{
			for(int i = s; i > g; i--){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}
	}else if(g <= 5){
		for(int i = s; i <= 9; i++){
			printf("%d ", i);
		}
		for(int i = 5; i > g; i--){
			printf("%d ", i);
		}
		printf("%d\n", g);
	}else{
		if(s < g){
			for(int i = s; i < g; i++){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}else{
			for(int i = s; i <= 9; i++){
				printf("%d ", i);
			}
			for(int i = 5; i < g; i++){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}
	}
}

int main(void){
	int n, s, g;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d %d", &s, &g);
		solve(s, g);
	}
  return 0;
}

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

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

char v[] ="0123456789543210123456789";

void solve(int s,int g) {
    int ans = 10000;
    int p = 0;
    rep(i,25){
        if(v[i] != s+'0') continue;
        loop(j,i+1,25){
            if(v[j] == g + '0') {
                ans = min(ans,j-i);
                p = i;
                continue;
            }
        }
    }

    for(int i=p; i<=p+ans; i++) cout<< (i==p?"":" ") <<v[i];
    cout << endl;
}

int main() {
    int n; cin >> n;
    rep(i,n){
        int f, t;
        cin >> f >> t;
        solve(f,t);
    }
}

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

void disp(int a, int b){
	for(int i = a+1;;i++){
		cout << " " << s[i%15];
		if(s[i%15] == b){cout << endl;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;
}