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++: #include <iostream>
#include <vector>
#include <climits>
#include <memory>
class Bus_stop {
public:
	Bus_stop(const int &i) :id{ i }, mins(10, INT_MAX - 1), prevs(10, nullptr){mins.at(i) = 0; };
	//?¬?????????????????¨????
	void set_next(Bus_stop &other) {
		//this ?????? other ????????????????????????
		sub_next(other);	//other ???????????????????¨???????????£????????????????????????????
	}
	//??¨??????????????¢?´¢
	void search_route() {
		call_sub_search(mins);	//private???????????????mins???virtual??¢??°?????±??§???????????????????????????
	};
	std::vector<int> get_route(const int &from, const int &to) const {
		return move(to)->sub_route(from);
	}
protected:
	//Bus_stop???ID
	int id;
	//?????????????????´??°??¨????¬??????¢?´¢???????§?????????????
	void sub_search(Bus_stop *next, const std::vector<int> &ms) {
		if (next->renew(ms, this)) {//?????????????????´??°????????£??????
			next->search_route(); //?¬??????¢?´¢???????§?
		}
	}
private:
	//???????????????????°??????????
	std::vector<int> mins;
	//????°???????????????¨???"???????????????"??????????????????
	std::vector<Bus_stop*> prevs;
	//mins??¨prevs?????´??°?????´??°???????????°true???????????°false
	bool renew(const std::vector<int> &prev, Bus_stop *from) {
		bool res = false;
		for (auto i = 0; i < prev.size(); ++i) {
			if (prev.at(i) + 1 < mins.at(i)) {
				mins.at(i) = prev.at(i) + 1;
				prevs.at(i) = from;
				res = true;
			}
		}
		return res;
	}
	//?????????????§????
	const Bus_stop *move(const int &to) const {
		if (to == id) {
			return this;
		}
		else {
			return prevs.at(to)->move(to);
		}
	}
	std::vector<int> sub_route(const int &from) const {
		if (from == id) {
			return std::vector<int>{from};
		}
		else {
			auto res = prevs.at(from)->sub_route(from);
			res.push_back(id);
			return res;
		}
	}
	//?¬???????????????????????????¢?´¢
	virtual void call_sub_search(const std::vector<int> &) = 0;
	//?¬?????????????????¨????
	virtual void sub_next(Bus_stop&) = 0;
};
class Loop_stop : public Bus_stop {
public:
	Loop_stop(const int &i) :Bus_stop(i), next{ nullptr } {};
private:
	void sub_next(Bus_stop &other) override {
		next = &other;
	}
	void call_sub_search(const std::vector<int> &mins) override {
		sub_search(next, mins);
	}
	Bus_stop *next;
};
class Line_stop : public Bus_stop {
public:
	Line_stop(const int &i) : Bus_stop(i), next1{ nullptr }, next2{ nullptr } {};
private:
	void sub_next(Bus_stop &other) override {
		if (next1) {
			next2 = &other;
		}
		else {
			next1 = &other;
		}
	}
	void call_sub_search(const std::vector<int> &mins) override {
		sub_search(next1, mins);
		sub_search(next2, mins);
	}
	Bus_stop *next1, *next2;
};
void show(std::vector<int> &route) {
	std::cout << route.at(0);
	for (auto i = 1; i < route.size(); ++i) {
		std::cout << ' ' << route.at(i);
	}
	std::cout << std::endl;
}
int main() {
	std::vector<std::shared_ptr<Bus_stop>> stops(15, nullptr);
	for (auto i = 0; i < 15; ++i) {
		stops.at(i) = std::make_shared<Loop_stop>(Loop_stop((i < 10) ? i : (15 - i)));
	}
	for (auto i = 0; i < 15; ++i) {
		stops.at(i)->set_next(*stops.at((i + 1) % 15));
	}
	stops.at(0)->search_route();
	int n;
	std::cin >> n;
	for (auto i = 0; i < n; ++i) {
		int from, to;
		std::cin >> from >> to;
		auto route1 = stops.at(to)->get_route(from, to);
		auto route2 = stops.at(15 - to)->get_route(from, to);
		if (route1.size() < route2.size()) {
			show(route1);
		}
		else {
			show(route2);
		}
	}
	return 0;
}

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

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int a,b;
		cin>>a>>b;
		if(5<a&&5<b){
			if(b<a){
				cout<<a;
				for(int i=a+1;i<10;i++)cout<<' '<<i;
				for(int i=5;i>0;i--)cout<<' '<<i;
				for(int i=0;i<=b;i++)cout<<' '<<i;
			}else{
				cout<<a;
				for(int i=a+1;i<=b;i++)cout<<' '<<i;
			}
		}else if(5<a){
			cout<<a;
			for(int i=a+1;i<10;i++)cout<<' '<<i;
			for(int i=5;i>=b;i--)cout<<' '<<i;
		}else if(5<b){
			cout<<a;
			for(int i=a+1;i<=b;i++)cout<<' '<<i;
		}else{
			if(b<a){
				cout<<a;
				for(int i=a-1;i>=b;i--)cout<<' '<<i;
			}else{
				cout<<a;
				for(int i=a+1;i<=b;i++)cout<<' '<<i;
			}
		}
		cout<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main() {
	int a[15] = { 0,1,2,3,4,5,6,7,8,9,5,4,3,2,1 };
	int s, t;
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> s >> t;
		int sum = 0, sum2 = 0, s2 = s;
		vector<int> go;
		vector<int>go2;
		while (a[s2] != t) {
			go.push_back(a[s2]);
			sum++;
			s2++;
			if (s2 > 14) s2 = 0;
		}
		go.push_back(t);
		sum++;
		s2 = s;
		while (a[s2] != t) {
			go2.push_back(a[s2]);
			sum2++;
			s2--;
			if (s2 < 0) s2 = 14;
		}
		go2.push_back(t);
		sum2++;
		if (sum < sum2) {
			for (int i = 0; i < sum; i++) {
				if (i == 0) cout << go[i];
				else cout << " " << go[i];
			}
			cout << endl;
		}
		else {
			for (int i = 0; i < sum2; i++) {
				if (i == 0) cout << go2[i];
				else cout << " " << go2[i];
			}
			cout << endl;
		}
	}
}

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

void solve(int s, int g){
	if(s <= 5){
		if(s < g){
			for(int i = s; i <= g; i++){
				printf("%d", i);
				if(i != g)	printf(" ");
			}
			printf("\n");
		}else{
			for(int i = s; i >= g; i--){
				printf("%d", i);
				if(i != g)	printf(" ");
			}
			printf("\n");
		}
	}else if(g <= 5){
		for(int i = s; i <= 9; i++){
			printf("%d ", i);
		}
		for(int i = 5; i >= g; i--){
			printf("%d", i);
			if(i != g)	printf(" ");
		}
		printf("\n");
	}else{
		if(s < g){
			for(int i = s; i <= g; i++){
				printf("%d", i);
				if(i != g)	printf(" ");
			}
			printf("\n");
		}else{
			for(int i = s; i <= 9; i++){
				printf("%d ", i);
			}
			for(int i = 5; i <= g; i++){
				printf("%d", i);
				if(i != g)	printf(" ");
			}
			printf("\n");
		}
	}
}

int main(void){
	int n, s, g;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d %d", &s, &g);
		solve(s, g);
	}
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
long n,s,e,i,j;
cin>>n;
for(j=0;j<n;j++){
cin>>s>>e;
if(s<6){
if(e<6){
if(s<e){cout<<s;for(i=s+1;i<=e;i++)cout<<" "<<i;cout<<endl;}
else{cout<<s;for(i=s-1;i>=e;i--)cout<<" "<<i;cout<<endl;}
}else{
cout<<s;for(i=s+1;i<=e;i++)cout<<" "<<i;cout<<endl;
}
}else{
if(e<6){
cout<<s;for(i=s+1;i<=9;i++)cout<<" "<<i;
for(i=5;i>=e;i--)cout<<" "<<i;cout<<endl;
}else{
cout<<s;for(i=s+1;i<=e;i++)cout<<" "<<i;cout<<endl;
}
}
}
return 0;
}