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>
#include<vector>
using namespace std ;

int N , a , b ;
int table[] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1} ;

void func(){
	vector<int> V1 ;
	vector<int> V2 ;
	
	for( int i=0 ; i<15 ; i++ ){
		if( table[i] == a && V1.size() ){
			for( int j=i ; ; j++ ){
				V2.push_back( table[j%15] ) ;
				if( table[j%15] == b ) break ;
			}
		}
		else if( table[i] == a ){
			for( int j=i ; ; j++ ){
				V1.push_back( table[j%15] ) ;
				if( table[j%15] == b ) break ;
			}
		}
	}
	
	if( V1.size() <= V2.size() ){
		for( int i=0 ; i<V1.size() ; i++ ) cout << (i?" ":"") << V1[i] ;
		cout << endl ;
	}else {
		for( int i=0 ; i<V2.size() ; i++ ) cout << (i?" ":"") << V2[i] ;
		cout << endl ;
	}
}

int main(){
	
	cin >> N ;
	while( N-- ){
		cin >> a >> b ;
		func() ;
	}
	
return 0 ;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

#deefine N 15
int d[N] = {0, 1, 2, 3, 4, 5 ,6 ,7 ,8 ,9 ,5 ,4 ,3 ,2 ,1};

int main(void){
  int n ;
  while(n--){
    int a,b;
    cin>>a>>b;
    if(a<=5 && b < a){
      a = 15 - a;
    }
    while(d[a] != b){
      cout<<d[a]<<" ";
      a = (a + 1) % N; 
    }
    cout<<d[a]<<endl;
  }
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
void up(int x, bool f) {
	bool dir = f;
	if (dir) {
		x++;
		if (x == 10) {
			x = 5;
		}
	}
}
signed main() {
	int n; cin >> n;
	while (n--) {
		//for (int i = 0; i < 10; i++) {
		//	for (int j = 0; j < 10; j++) {
		//		int a(i), b(j);
		int a, b;
		cin >> a >> b;
		//cout << "start " << a << " fin " << b << endl;
		int x = a;
		vector<int>v, w;
		bool dir = true;
		while (x != b) {
			v.push_back(x);
			if (dir) {
				if (x == 9) {
					x = 5;
					if (b <= 5)dir = false;
					else dir = true;
				}
				else x++;
			}
			else {
				if (x == 0) {
					dir = true;
					x = 1;
				}
				else x--;
			}
		}
		v.push_back(x);
		dir = false;
		x = a;
		while (x != b) {
			w.push_back(x);
			if (6 <= x&&x <= 9)dir = true;
			if (dir) {
				if (x == 9) {
					x = 5;
					if (b <= 5)dir = false;
					else dir = true;
				}
				else x++;
			}
			else {
				if (x == 0) {
					x = 1;
					dir = true;
				}
				else x--;
			}
		}
		w.push_back(x);


		dumpc(v); dumpc(w);
		if (v.size() < w.size()) {
			rep(i, 0, v.size()) {
				if (i)cout << " ";
				cout << v[i];
			}
			cout << endl;
		}
		else {
			rep(i, 0, w.size()) {
				if (i)cout << " ";
				cout << w[i];
			}
			cout << endl;
		}
		//}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
	
    while (n--){
        int f, e;
        cin >> f >> e;
		
        if (f < e){
            for (int i = f; i <= e ; i++){
                cout << i;
                if (i < e) {
                    cout << ' ';
                }
            }
        }
		else if (f > e && 6 <= f && f <= 9 && 6 <= e && e <= 9){
            int i = f;
            for (; 1 <= i ;i--){
                cout << i << ' ';
            }
            for (; i <= e; i++){
                cout << i;
                if (i < e){
                    cout << ' ';
                }
            }
        }
        else if (f > e){
            for (int i = f; e <= i; i--){
                cout << i;
                if (i > e) {
                    cout << ' ';
                }
            }
        }
        cout << endl;
    }
    return 0;
}

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

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

int main(){
	int n,s,g;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> s >> g;
		if(s <= 5 && g <= 5){
			if(s < g){
				while(s != g){
					cout << s++ << " ";
				}
				cout << g << endl;
			}
			else{
				while(s != g){
					cout << s-- << " ";
				}
				cout << g << endl;
			}
		}
		else if(s <= 5 && g <= 9){
			while(s != g){
				cout << s++ << " ";
			}
			cout << g << endl;
		}
		else{
			while(busstop[s] != g){
				cout << busstop[s++] << " ";
			}
			cout << g << endl;
		}
	}
	return 0;
}