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>
using namespace std;

int main() {
  int a[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};
  int n, s, e, p;

  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> s >> e;
    if (!s || s > 5 || s < e) {
      p = s;
    } else {
      p = 15-s;
    }
    while (a[p]!=e) {
      cout << a[p] << " ";
      p = (p+1)%15;
    }
    cout << a[p] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	int n;
	
	int a, b;
	
	cin >> n;
	
	for(int loop = 0; loop < n; loop++){
		cin >> a >> b;
		if(a == b){
			printf("%d\n", b);
		}else if(a < b){
			for(int i = a; i < b; i++){
				printf("%d ", i);
			}
			printf("%d\n", b);
		}else if(a <= 5){
			for(int i = a; i > b; i--){
				printf("%d ", i);
			}
			printf("%d\n", b);
		}else if(b <= 5){
			for(int i = a; i <= 9; i++){
				printf("%d ", i);
			}
			for(int i = 5; i > b; i--){
				printf("%d ", i);
			}
			printf("%d\n", b);
		}else{
			for(int i = a; i <= 9; i++){
				printf("%d ", i);
			}
			printf("5 4 3 2 1 0 1 2 3 4 5 ");
			for(int i = 6; i < b; i++){
				printf("%d ", i);
			}
			printf("%d\n", b);
		}
	}
	
	return 0;
}

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

int K[15] = { 0,1,2,3,4,5,6,7,8,9,5,4,3,2,1 };
int s, t, n, c, ok, q;
vector<int>x[15];
vector<int>p;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 15; j++) {
			x[j].clear();
		}
		p.clear();
		c = -1; ok = 0; q = 1145141919;
		cin >> s >> t;
		for (int j = 0; j < 15; j++) {
			if (K[j] == s) {
				for (int k = j; k < 15 + j; k++) {
					x[j].push_back(K[k % 15]);
					if (K[k % 15] == t) {
						break;
					}
				}
			}
		}
		for (int j = 0; j < 15; j++) {
			if (q > x[j].size() && x[j].size() >= 1) {
				q = x[j].size();
				p = x[j];
			}
		}
		for (int j = 0; j < p.size(); j++) {
			if (j >= 1) {
				cout << ' ';
			}
			cout << p[j];
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

int n, s, t;
int stops[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0};
vector<int> ss1, ss2;

int main()
{
	cin >> n;

	REP(n)
	{
		cin >> s >> t;
		
		ss1.clear();
		ss2.clear();

		//printf("s = %d, t = %d\n", s, t);

		if (0 <= s && s <= 5)
		{
			for (int j=s; j<16; j++)
			{
				ss1.pb(stops[j]);
				if (stops[j] == t) break;
			}
			for (int j=15-s; j<16; j++)
			{
				ss2.pb(stops[j]);
				if (stops[j] == t) break;
			}
		} else {
			for (int j=s; j<16; j++)
			{
				ss1.pb(stops[j]);
				if (stops[j] == t) break;
			}
		}

		//printf("ss1.size = %d, ss2.size = %d\n", ss1.size(), ss2.size());

		if (ss1.size() != 0 && ss2.size() != 0 && ss1.size() < ss2.size())
		{
			rep(j, ss1.size())
			{
				cout << ss1[j];
				cout << ((j != ss1.size() - 1) ? " " : "\n");
			}
		}
		if (ss1.size() != 0 && ss2.size() != 0 && ss2.size() < ss1.size())
		{
			rep(j, ss2.size())
			{
				cout << ss2[j];
				cout << ((j != ss2.size() - 1) ? " " : "\n");
			}
		}
		if (ss1.size() != 0 && ss2.size() == 0)
		{
			rep(j, ss1.size())
			{
				cout << ss1[j];
				cout << ((j != ss1.size() - 1) ? " " : "\n");
			}
		}
		if (ss1.size() == 0 && ss2.size() != 0)
		{
			rep(j, ss2.size())
			{
				cout << ss2[j];
				cout << ((j != ss2.size() - 1) ? " " : "\n");
			}
		}
		if (ss1.size() == ss2.size())
		{
			rep(j, ss1.size())
			{
				cout << ss1[j];
				cout << ((j != ss1.size() - 1) ? " " : "\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 <= b; i++) printf("%d%c", i, i == b ? '\n' : ' ');
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	string ans[10][10]={
	{
		"0",
		"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",
		"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",
		"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",
		"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",
		"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",
		"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",
		"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",
		"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",
		"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",
		"9"
	}
};
	int n,a,b;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		cout<<ans[a][b]<<endl;
	}
	return 0;
}