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

int main(){
    int way[15] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};

    int n, from, to, ansf, anst;
    cin >> n;

    for(int i = 0; i < n; i++){
        int length = 20;
        cin >> from >> to;
        for(int start = 0; start < 15; start++){
            if(way[start] == from){
                int tmp = 1;
                int now = start;
                while(way[now] != to){
                    tmp++;
                    now = (now+1)%15;
                }

                if(length > tmp){
                    ansf = start;
                    anst = now;
                    length = tmp;
                }

            }
        }

        for(int i = 0; i < length; i++){
            if(i)   cout << " ";
            cout << way[(ansf+i)%15];
        }
        cout << endl;

    }

    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.h>



using namespace std;

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

int main(){
    int n;
    cin>>n;
    for(int roop=0; roop<n; roop++){
        int b,e;
        cin>>b>>e;
        int start1;
        int end1;
        for(int i=0; i<16; i++){
            if(basutei[i]==b){
                start1=i;
                break;
            }
        }
        
        for(int i=0; i<16; i++){
            if(basutei[(start1+i)%16]==e){
                end1=(start1+i)%16;
                break;
            }
        }
        int l1=0;
        if(end1<start1){
            l1=end1+16-start1;
        }else{
            l1=end1-start1;
        }
        
        //----------------------------------
        
        int start2;
        int end2;
        for(int i=15; i>=0; i--){
            if(basutei[i]==b){
                start2=i;
                break;
            }
        }
        
        for(int i=0; i<16; i++){
            if(basutei[(start2+i)%16]==e){
                end2=(start2+i)%16;
                break;
            }
        }
        
        int l2=0;
        if(end2<start2){
            l2=end2+16-start2;
        }else{
            l2=end2-start2;
        }
        if(l1<l2){
            cout<<basutei[start1];
            for(int i=start1+1; i<=start1+l1; i++){
                cout<<" "<<basutei[i%16];
            }
            cout<<endl;
        }else{
            cout<<basutei[start2];
            for(int i=start2+1; i<=start2+l2; i++){
                cout<<" "<<basutei[i%16];
            }
            if(roop+1==n)break;
            cout<<endl;
            
        }
    }
}

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

int main(){

  int n,m,p,i;

  cin >> p;

  for(int s=0;s<p;s++){

    cin >> n >> m;
    i = n;

    cout << n;
    while(i != m){
      if(i == 9) i = 5;

      if(i > 5) i++;
      else if(i < m)i++;
      else if(i > m)i--;
      cout << " " << i;
    }

    cout << endl;
  }
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int p[10][10];

int main(){
    string p="0123456789543210123456788954321012345678";
    int n;
    cin>>n;
    rep(roop,n){
        int a,b;
        cin>>a>>b;
        int c=0;
        vector<int> ans[2];
        rep(i,p.size()){
            if(p[i]=='0'+a&&c<2){
                for(int j=i;j<p.size();j++){
                    ans[c].pb(p[j]-'0');
                    if(p[j]=='0'+b)break;
                }
                c++;
            }
        }
        vector<int> out;
        if(ans[0].size()<ans[1].size())out=ans[0];
        else out=ans[1];
        
        rep(i,out.size()){
            if(i!=0)cout<<" ";
            cout<<out[i];
        }
        cout<<endl;
    }
    
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

#define INF 1000010

using namespace std;

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

int main(){
    int n;
    cin >> n;
    for(int k=0; k < n; k++){

        int e1,e2;
        bool isFirst = false;
        cin >> e1 >> e2;

        if(e1 > e2) isFirst = true;

        for(int i=0;; i++){
            if(busstop[i] == e1){
                if(isFirst){
                    isFirst = !isFirst;
                    continue;
                }
                for(int j=i; ; j++){
                    if(busstop[j] == e2){
                        cout << " " << busstop[j];
                        goto end_state;
                    }
                    else {
                        if(j == i) cout << busstop[j];
                        else cout << " " << busstop[j];
                    }
                }
            }
        }
end_state:
        cout << endl;
    }
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"



int main() {
	int N; cin >> N;
	for (int i = 0; i < N; ++i) {
		int a, b; cin >> a >> b;
		vector<int>anss;
		if (a < b) {
			for (int j = a; j <= b; ++j) {
				anss.emplace_back(j);
			}
		}
		else if (a == b) {
			anss.emplace_back(a);
		}
		else {
			if (a <=5) {
				for (int j = a; j >= b; --j) {
					anss.emplace_back(j);
				}
			}
			else {
				if (b <= 5) {

					for (int j = a + 1; j <= 9; ++j) {
						anss.emplace_back(j);
					}
					for (int j = 5; j >= b; --j) {
						anss.emplace_back(j);
					}
				}
				else {
					for (int j = a + 1; j <= 9; ++j) {
						anss.emplace_back(j);
					}
					for (int j = 5; j >= 0; --j) {
						anss.emplace_back(j);
					}
					for (int j = 1; j <= b; ++j) {
						anss.emplace_back(j);
					}
				}
			}
		}
		for (int i = 0; i < anss.size(); ++i) {
			cout << anss[i];
			if (i == anss.size() - 1)cout << endl;
			else cout << " ";
		}
	}
	return 0;
}