Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

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 <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<double,int> P;

static const double eps = 10e-9;

int main(){
	int n;
	int route[] = {5,6,7,8,9,5};
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			int src,dst;
			scanf("%d %d",&src,&dst);
				if(src <= 5 && dst <= 5 || src >= 5 && dst >= 5){
					if(src < dst){
						for(int j=src;j<=dst;j++){
							printf("%d%s",j,j == dst ? "\n" : " ");
						}
					}
					else if(src > dst){
						for(int j=src;j>=dst;j--){
							printf("%d%s",j,j == dst ? "\n" : " ");
						}
					}
				}

				else{
					if(src < dst){
						for(int j=src;j<=dst;j++){
							printf("%d%s",j,j == dst ? "\n" : " ");
						}
					}
					else if(src > dst){
						for(int j=src;j<=9;j++){
							printf("%d ",j);
						}

						for(int j=5;j>=dst;j--){
							printf("%d%s",j,j == dst ? "\n" : " ");
						}
					}
				}

		}
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;

int main(){
	int n;
	scanf("%d",&n);
	int a[] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8};
	int b[] = {0,1,2,3,4,5};
	rep(q,n){
		int from,to;
		bool f = false;
		scanf("%d%d",&from,&to);
		if(from < 6 && to < 6){
			if(from > to){
				int x = from;
				while(1){
					if(b[x] == to){
						printf(" %d\n",to);
						break;
					}
					if(f)printf(" ");
					printf("%d",b[x]);
					x--;
					f = true;
				}
			}
			else{
				int x = from;
				while(1){
					if(b[x] == to){
						printf(" %d\n",to);
						break;
					}
					if(f)printf(" ");
					printf("%d",b[x]);
					x++;
					f = true;
				}
			}
		}
		else{
			int x = from;
			while(1){
				if(a[x] == to){
					printf(" %d\n",to);
					break;
				}
				if(f)printf(" ");
				printf("%d",a[x]);
				x++;
				f = true;
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,s,e;
  cin >> n;
  rep(i,n){
    cin >> s >> e;
    if(s + e < 7){
      if(s < e){
        REP(j,s,e){
          cout << j << " ";
        }
        cout << e << endl;
      }
      else{
        for(int j = s; j > e;--j){
          cout << j << " ";
        }
        cout << e << endl;
      }
    }
    else{
      if(s < e){
        REP(j,s,e){
          cout << j << " ";
        }
        cout << e << endl;
      }
      else{
        if(e < 6){
          REP(j,s,10){
            cout << j<< " ";
          }
          rep(j,5-e){
            cout << 5-j<< " ";
          }
          cout << e << endl;
        }
        else{
          REP(j,s,10){
            cout << j<< " ";
          }
          rep(j,5){
            cout << 5-j<< " ";
          }
          rep(j,e){
            cout << j << " ";
          }
          cout << e << endl;
        }
      }
    }
  }
  return 0;
}

C++: #include <cstdio>

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

int main()
{
    int n;
    scanf( "%d\n", &n );
    while( 0 < n )
    {
        int source = 0, sink = 0;
        scanf( "%d %d\n", &source, &sink );
        if( source <= 5 )
        {
            if( source < sink )
            {
                for( int i = source; i <= sink; i++ )
                {
                    printf( "%d ", i );
                }
                printf( "\n" );
            }
            else
            {
                for( int i = source; i >= sink; i-- )
                {
                    printf( "%d ", i );
                }
                printf( "\n" );
            }
        } 
        else
        {
            if( sink >= 5 )
            {
                if( source < sink )
                {
                    for( int i = source; i <= sink; i++ )
                    {
                        printf( "%d ", i );
                    }
                    printf( "\n" );
                }
                else
                {
                    for( int i = source; i <= 9; i++ )
                    {
                        printf( "%d ", i );
                    }
                    if( sink != 5 )
                    {
                        printf( "5 4 3 2 1 0 1 2 3 4" );
                    }
                    for( int i = 5;i < sink; i++ )
                    {
                        printf( "%d ", i );
                    }
                    printf( "\n" );
                }
            }
            else
            {
                for( int i = source; i <= 9; i++ )
                {
                    printf( "%d ", i );
                }
                for( int i = 5; i >= sink; i++ )
                {
                    printf( "%d ", i );
                }
                printf( "\n" );
            }
        }
        n--;
    }
    return 0;
}