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>
#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];
            }
            if(roop+1==n)break;
            cout<<endl;
            
        }
    }
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){

	int n,start,goal;

	scanf("%d",&n);

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

		if(start <= 5){
			if(start < goal){
				printf("%d",start);
				for(int k = start+1; k <= goal; k++){
					printf(" %d",k);
				}
				printf("\n");
			}else{
				printf("%d",start);
				for(int k = start-1; k >= goal; k--){
					printf(" %d",k);
				}
				printf("\n");
			}
		}else{ //start > 6
			if(goal >= 5){  //??´??????????????????
				if(start < goal){
					printf("%d",start);
					for(int k= start+1; k <= goal; k++)printf(" %d",k);

					printf("\n");

				}else{ //start > goal
					printf("%d",start);
					for(int k= start+1; k <= 9; k++)printf(" %d",k);
					printf(" 5 4 3 2 1 0 1 2 3 4");
					for(int k=5; k <= goal; k++)printf(" %d",k);
					printf("\n");
				}

			}else{ //goal <= 4
				printf("%d",start);
				for(int k=start+1; k <= 9; k++)printf(" %d",k);
				for(int k=5; k >= goal; k--)printf(" %d",k);
				printf("\n");
			}

		}

	}

    return 0;
}

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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct Edge{
	int src,dst;
	Edge(){}
	Edge(int s,int d):src(s),dst(d){}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void solve(Graph& g,int begin,int end)
{
	int size=g.size();
	vi prev(size,-1);
	queue<Edge> q;
	q.push(Edge(-2,begin));
	while(q.size()){
		Edge e=q.front(); q.pop();
		if(prev[e.dst]!=-1) continue;
		prev[e.dst]=e.src;
		foreach(it,g[e.dst])
			q.push(*it);
	}
	vi res;
	for(int i=end;i>0;i=prev[i])
		res.push_back(i);
	reverse(allof(res));
	rep(i,res.size())
		printf("%d%c",res[i],i==res.size()-1?'\n':' ');
}

int main()
{
	Graph g(10);
	int src[]={0,1,1,2,2,3,3,4,4,5,5,6,7,8,9};
	int dst[]={1,0,2,1,3,2,4,3,5,4,6,7,8,9,5};
	rep(i,sizeof(src)/sizeof(src[0]))
		g[src[i]].push_back(Edge(src[i],dst[i]));
	
	int n;
	cin>>n;
	rep(i,n){
		int begin,end;
		cin>>begin>>end;
		solve(g,begin,end);
	}
	
	return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int N = 10;
const int INF = 1e9;

vector<int> solve(int a, int b, int p){
  vector<int> res;
  res.push_back(a);
  while(a != b){
    a += p;
    if(a == 10) { a = 5; p = -1; }
    if(a == -1) { a = 1; p = 1; }
    res.push_back(a);
  }
  return res;
}

int main() {
  int T; cin >>T;
  REP(t, T){
    int a, b; cin >>a >>b;
    vector<int> ans = solve(a, b, 1);
    if(a <= 5){
      vector<int> tmp = min(ans, solve(a, b, -1));
      if(tmp.size() < ans.size()) ans = tmp;
    }
    REP(i, ans.size()) cout <<ans[i] <<(i + 1 == (int)ans.size() ? "" : " ");
    cout <<endl;
  }
  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);}

#define 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 ;
  cin>>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;
  }
}