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>
#include <algorithm>
#include <cstring>
#include <cstdlib>

using namespace std;

int main(){

	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		int from,to;
		cin>>from>>to;
		// ¶ûüÉV~[V
		int angle=1;
		int c=from;
		vector<int> ph;
		ph.push_back(c);
		while(1){
			if(angle==0&&c==5){
				c++;
			}
			else if(angle==1&&c==5){
				c--;
			}
			else if(c>=6&&c<=9){
				c++;
				if(c==10){
					c=5;
					angle=1;
				}
			}
			else if(angle==0&&c>=1&&c<=4){
				c++;
			}
			else if(angle==1&&c>=1&&c<=4){
				c--;
			}
			else if(c==0){
				c++;
				angle=0;
			}
			ph.push_back(c);
			if(c==to)
				break;
		}
		c=from;
		angle=0;
		vector<int>ph2;
		ph2.push_back(c);
		while(1){
			if(angle==0&&c==5){
				c++;
			}
			else if(angle==1&&c==5){
				c--;
			}
			else if(c>=6&&c<=9){
				c++;
				if(c==10){
					c=5;
					angle=1;
				}
			}
			else if(angle==0&&c>=1&&c<=4){
				c++;
			}
			else if(angle==1&&c>=1&&c<=4){
				c--;
			}
			else if(c==0){
				c++;
				angle=0;
			}
			ph2.push_back(c);
			if(c==to)
				break;
		}
		if(ph.size()<ph2.size()){
			for(int j = 0; j < ph.size(); j++){
				cout<<ph[j];
				if(j!=ph.size()-1){
					cout<<" ";
				}
				else
					cout<<endl;
			}
		}
		else{
			for(int j = 0; j < ph2.size(); j++){
				cout<<ph2[j];
				if(j!=ph2.size()-1){
					cout<<" ";
				}
				else
					cout<<endl;
			}
		}

	}

	return 0;
}

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);
					if(goal != 5){
						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 <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n;
	cin >> n;
	while (n--) {
		int a, b;
		scanf("%d %d", &a, &b);
		if (a < b)
			for (int i = a; i <= b; i++) printf("%d%c", i, i == b ? '\n' : ' ');
		else if (a <= 5)
			for (int i = a; i >= b; i--) printf("%d%c", i, i == b ? '\n' : ' ');
		else {
			for (int i = a; i <= 9; i++) printf("%d ", i);
			if (b <= 5)
				for (int i = 5; i >= b; i--) printf("%d%c", i, i == b ? '\n' : ' ');
			else {
				for (int i = 5; i > 0; i--) printf("%d ", i);
				for (int i = 0; i <= b; i++) printf("%d%c", i, i == b ? '\n' : ' ');
			}
		}
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"



int main() {
	int N; cin >> N;
	for (int i = 0; i < N; ++i) {
		int a, b; cin >> a >> b;
		vector<int>anss;
		if (a < b) {
			for (int j = a; j <= b; ++j) {
				anss.emplace_back(j);
			}
		}
		else {
			if (a <=5) {
				for (int j = a; j >= b; --j) {
					anss.emplace_back(j);
				}
			}
			else {
				if (b <= 5) {

					for (int j = a + 1; j <= 9; ++j) {
						anss.emplace_back(j);
					}
					for (int j = 5; j >= b; --j) {
						anss.emplace_back(j);
					}
				}
				else {
					for (int j = a + 1; j <= 9; ++j) {
						anss.emplace_back(j);
					}
					for (int j = 5; j >= 0; --j) {
						anss.emplace_back(j);
					}
					for (int j = 1; j <= b; ++j) {
						anss.emplace_back(j);
					}
				}
			}
		}
		for (int i = 0; i < anss.size(); ++i) {
			cout << anss[i];
			if (i == anss.size() - 1)cout << endl;
			else cout << " ";
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int map[15]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
int main(){
	int n,a,b;
	cin>>n;
	int dx[2]={1,-1},set,best=100;
	for(int u=0;u<n;u++){
		cin>>a>>b;
		int sa[2],top=0;
		for(int i=0;i<15;i++){
			if(map[i]==a)sa[top]=i,top++;
		}
		int dx[2]={1,-1},set,best=100;
		for(int s=0;s<2;s++){
			for(int y=0;y<top;y++){
				int cnt=0,pla=sa[y];
				while(true){
					if(map[pla]==b)break;
					cnt++;
					pla+=dx[s];
					if(pla==15)pla=0;
			        if(pla==-1)pla=14;
				}
				if(cnt<best){
					best=cnt;
					set=s*100+y;
				}
			}
		}
		int pla=sa[set%10];
		while(true){
			if(map[pla]==b)break;
			cout<<map[pla]<<" ";
			pla+=dx[set/100];
			if(pla==15)pla=0;
			if(pla==-1)pla=14;
		}
		cout<<b<<endl;
	}
	return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    int N;
    cin >> N;
    for (;N--;) {
        int src, dst;
        cin >> src >> dst;

        if (src < dst) {
            cout << src;
            for (int j = src+1; j <= dst; ++j) {
                cout << ' ' << j;
            }
            cout << endl;
        } else {
            cout << src;
            if (src <= 5) {
                for (int j = src-1; j >= dst; --j) {
                    cout << ' ' << j;
                }
            } else {
                for (int j = src+1; j <= 9; ++j) {
                    cout << ' ' << j;
                }
                if (dst <= 5) {
                    for (int j = 5; j >= dst; --j) {
                        cout << ' ' << j;
                    }
                } else {
                    for (int j = 5; j >= 0; --j) {
                        cout << ' ' << j;
                    }
                    for (int j = 1; j <= dst; ++j) {
                        cout << ' ' << j;
                    }
                }
            }
            cout << endl;
        }

    }

    return 0;
}