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>

int main(){

int n,s,f;
int w;

//while(1){
scanf("%d",&n);

for(int i=0;i<n;i++){
scanf("%d %d",&s,&f);

if(s<=5){
 if(s<f){
for(int i=s;i<=f;i++)
{
if(i!=s)printf(" ");
printf("%d",i);
}
     }
else if(s>f){
for(int i=s;i>=f;i--)
{
if(i!=s)printf(" ");
printf("%d",i);
}
}
}
if(s>5){
 if(f>s){
for(int i=s;i<=f;i++)
{
if(i!=s)printf(" ");
printf("%d",i);
}
}
 else if(5<f&&f<s){
	 for(int i=s;i<=9;i++)
{
if(i!=s)printf(" ");
printf("%d",i);
}

for(int i=5;i>=0;i--)
{
printf(" ");
printf("%d",i);
}

for(int i=1;i<=f;i++)
{
printf(" ");
printf("%d",i);
}

}
 else if(f<=5){
for(int i=s;i<=9;i++)
{
if(i!=s)printf(" ");
printf("%d",i);
}

for(int i=5;i>=f;i--)
{
printf(" ");
printf("%d",i);
}

}
}printf("\n");
}

return 0;
}

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};

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;
                    }
                    else {
                        if(j == i) cout << busstop[j];
                        else cout << " " << busstop[j];
                    }
                }
            }
        }
end:
        cout << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	
	int n;
	cin>>n;
	rep(j,n){
		vint ans;
		int a,b;
		cin>>a>>b;
		// cout<<q.front()<<endl;
		queue<int> q;
		rep(i,10) q.push(i);
		rep(i,6) q.push(5-i);
		rep(i,30){
			int t=q.front();
			q.push(t);
			q.pop();
			if(t==a){
				ans.clear();
				ans.PB(t);
			}
			else if(t==b&&ans.size()&&ans[0]==a){
				ans.PB(t);
				break;
			}
			else{
				ans.PB(t);
			}
		}
		rep(i,ans.size()){
			if(i) cout<<" ";
			cout<<ans[i];
		}
		cout<<endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  const char *ans[10][10]={
    "","0 1","0 1 2","0 1 2 3","0 1 2 3 4","0 1 2 3 4 5","0 1 2 3 4 5 6","0 1 2 3 4 5 6 7","0 1 2 3 4 5 6 7 8","0 1 2 3 4 5 6 7 8 9",
    "1 0","","1 2","1 2 3","1 2 3 4","1 2 3 4 5","1 2 3 4 5 6","1 2 3 4 5 6 7","1 2 3 4 5 6 7 8","1 2 3 4 5 6 7 8 9",
    "2 1 0","2 1","","2 3","2 3 4","2 3 4 5","2 3 4 5 6","2 3 4 5 6 7","2 3 4 5 6 7 8","2 3 4 5 6 7 8 9",
    "3 2 1 0","3 2 1","3 2","","3 4","3 4 5","3 4 5 6","3 4 5 6 7","3 4 5 6 7 8","3 4 5 6 7 8 9",
    "4 3 2 1 0","4 3 2 1","4 3 2","4 3","","4 5","4 5 6","4 5 6 7","4 5 6 7 8","4 5 6 7 8 9",
    "5 4 3 2 1 0","5 4 3 2 1","5 4 3 2","5 4 3","5 4","","5 6","5 6 7","5 6 7 8","5 6 7 8 9",
    "6 7 8 9 5 4 3 2 1 0","6 7 8 9 5 4 3 2 1","6 7 8 9 5 4 3 2","6 7 8 9 5 4 3","6 7 8 9 5 4","6 7 8 9 5","","6 7","6 7 8","6 7 8 9",
    "7 8 9 5 4 3 2 1 0","7 8 9 5 4 3 2 1","7 8 9 5 4 3 2","7 8 9 5 4 3","7 8 9 5 4","7 8 9 5","7 8 9 5 4 3 2 1 0 1 2 3 4 5 6","","7 8","7 8 9",
    "8 9 5 4 3 2 1 0","8 9 5 4 3 2 1","8 9 5 4 3 2","8 9 5 4 3","8 9 5 4","8 9 5","8 9 5 4 3 2 1 0 1 2 3 4 5 6","8 9 5 4 3 2 1 0 1 2 3 4 5 6 7","","8 9",
    "9 5 4 3 2 1 0","9 5 4 3 2 1","9 5 4 3 2","9 5 4 3","9 5 4","9 5","9 5 4 3 2 1 0 1 2 3 4 5 6","9 5 4 3 2 1 0 1 2 3 4 5 6 7","9 5 4 3 2 1 0 1 2 3 4 5 6 7 8","",
  };
  int n;
  scanf("%d",&n);
  while(n --> 0){
    int a,b;
    scanf("%d%d",&a,&b);
    puts(ans[a][b]);
  }
  return 0;
}