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 togo[10][2] = {{1,1},{0,2},{1,3},{2,4},{3,5},{4,6},{7,7},{8,8},{9,9},{5,5}};
	int a,b,n,l,r,c,d;
	cin >> n;
	for(int i = 0;i < n;++i){
		c = 0;d = 1;
		cin >> a >> b;
		l = r = a;
		while(l != b && r != b){
			l = togo[l][c];
			r = togo[r][d];
			if(!l) c = 1 - c;
			if(!r) d = 1 - d;
		}
		c = 0;d = 1;
		cout << a;
		while(a != b){
			if(l == b){
				a = togo[a][c];
				if(!a) c = 1 - c;
			}
			else{
				a = togo[a][d];
				if(!a) d = 1 - d;
			}
			cout << " " << a;
		}
		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[15]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};

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<15; i++){
            if(basutei[i]==b){
                start1=i;
                break;
            }
        }
        
        for(int i=0; i<15; i++){
            if(basutei[(start1+i)%15]==e){
                end1=(start1+i)%15;
                break;
            }
        }
        int l1=0;
        if(end1<start1){
            l1=end1+15-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<15; i++){
            if(basutei[(start2+i)%15]==e){
                end2=(start2+i)%15;
                break;
            }
        }
        
        int l2=0;
        if(end2<start2){
            l2=end2+15-start2;
        }else{
            l2=end2-start2;
        }
        if(l1<l2){
            cout<<basutei[start1];
            for(int i=start1+1; i<=start1+l1; i++){
                cout<<" "<<basutei[i%15];
            }
            cout<<endl;
        }else{
            cout<<basutei[start2];
            for(int i=start2+1; i<=start2+l2; i++){
                cout<<" "<<basutei[i%15];
            }
            cout<<endl;
            
        }
    }
}

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

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

int main() {
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    int s, g; cin >> s >> g;
    for(int j = 0; j < 15; j++) {
      if(j < 9 && s < 6 && g < 6 && s > g) j += 9;
      if(s == stop[j]) {
        for(int k = 0; k < 15; k++) {
          int num = (j+k)%15;
          cout << stop[num];
          if(stop[num] != g) cout << ' ';
          else {
              cout << endl;
              break;
          }
        }
      }
    if(s < g && j > 5) break;
    }
  }
}

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

void downTo(vector<int> &vs, int s, int t) {
    while (t <= s) {
        vs.push_back(s--);
    }
}

void upTo(vector<int> &vs, int s, int t) {
    while (s <= t) {
        vs.push_back(s++);
    }
}

int main() {
    int n;
    while (cin >> n) {
        while (n--) {
            int s, t;
            cin >> s >> t;
            vector<int> ans;
            if (s <= 5) {
                if (s < t) {
                    upTo(ans, s, t);
                } else {
                    downTo(ans, s, t);
                }
            } else {
                if (s < t) {
                    upTo(ans, s, t);
                } else {
                    upTo(ans, s, 9);
                    if (t < 5) {
                        downTo(ans, 5, t);
                    } else {
                        upTo(ans, 5, t);
                    }
                }
            }
            cout << ans[0];
            for (int i = 1, size = ans.size(); i < size; i++) {
                cout << " " << ans[i];
            }
            cout << endl;
        }
    }
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<int> v{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};
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        int ans = INF<int>, jj = 0, kk = 0;
        for (int j = 0; j < v.size(); ++j) {
            for (int k = j+1; k < v.size(); ++k) {
                if(v[j] == a && v[k] == b){
                    if(ans > abs(j-k)){
                        ans = abs(j-k);
                        jj = j; kk = k;
                    }
                }
            }
        }
        for (int j = jj; j <= kk; j++) {
            if(j != jj) printf(" ");
            printf("%d", v[j]);
            if(j == kk) break;
        }
        puts("");
    }
    return 0;
}