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 <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;

void solve(int src,int dst)
{
	vi res;
	if(src<=5 && dst<=5){
		if(src<dst)
			for(int i=src;i<=dst;i++)
				res.push_back(i);
		else
			for(int i=src;i>=dst;i--)
				res.push_back(i);
	}
	else if(src<=5){
		for(int i=src;i<=dst;i++)
			res.push_back(i);
	}
	else if(dst<=5){
		for(int i=src;i<=9;i++)
			res.push_back(i);
		for(int i=5;i>=dst;i--)
			res.push_back(i);
	}
	else if(src<dst){
		for(int i=src;i<=dst;i++)
			res.push_back(i);
	}
	else{
		for(int i=src;i<=9;i++)
			res.push_back(i);
		for(int i=5;i>0;i--)
			res.push_back(i);
		for(int i=0;i<5;i++)
			res.push_back(i);
		for(int i=5;i<=dst;i++)
			res.push_back(i);
	}
	for(int i=0;i<res.size();i++)
		printf("%d%c",res[i],i==res.size()-1?'\n':' ');
}

int main()
{
	int n;
	cin>>n;
	rep(i,n){
		int src,dst;
		cin>>src>>dst;
		solve(src,dst);
	}
	
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

void f(int a,int b){
	cout<<a;
	if(a==b){cout<<endl;return;}
	if(6<=a&&a<=8){
		a++;
	}else if(a==9){
		a=5;
	}else if(a<b){
		a++;
	}else{
		a--;
	}
	cout<<" ";
	f(a,b);
}

int main() {
	int n=in();
	int a,b;
	int i;
	for(i=0;i<n;i++){
		cin>>a>>b;
		if(6<=b&&b<a){
			if(b==6&&a==7)cout<<"7 8 9 5 4 3 2 1 0 1 2 3 4 5 6"<<endl;
			if(b==6&&a==8)cout<<"8 9 5 4 3 2 1 0 1 2 3 4 5 6"<<endl;
			if(b==6&&a==9)cout<<"9 5 4 3 2 1 0 1 2 3 4 5 6"<<endl;
			if(b==7&&a==8)cout<<"8 9 5 4 3 2 1 0 1 2 3 4 5 6 7"<<endl;
			if(b==7&&a==9)cout<<"9 5 4 3 2 1 0 1 2 3 4 5 6 7"<<endl;
			if(b==8&&a==9)cout<<"9 5 4 3 2 1 0 1 2 3 4 5 6 7 8"<<endl;
		}else{
			f(a,b);
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		int from,to;
		cin>>from>>to;
		if(from<to)for(int i=from;i<=to;++i)cout<<i<<((i==to)?"":" ");
		else if(from<=5)for(int i=from;i>=to;--i)cout<<i<<((i==to)?"":" ");
		else if(to<=5){
			for(int i=from;i<=9;++i)cout<<i<<((i==9)?"":" ");
			for(int i=5;i>=to;--i)cout<<" "<<i;
		}else{
			for(int i=from;i<=9;++i)cout<<i<<((i==9)?"":" ");
			for(int i=5;i<=to;++i)cout<<" "<<i;
		}
		cout<<"\n";
	}
	return 0;
}

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;
bool flag1, flag2;

int main()
{
	cin >> n;

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

		flag1 = flag2 = false;

		//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)
				{
					flag1 = true;
					break;
				}
			}
			for (int j=15-s; j<16; j++)
			{
				ss2.pb(stops[j]);
				if (stops[j] == t)
				{
					flag2 = true;
					break;
				}
			}
		} else {
			for (int j=s; j<16; j++)
			{
				ss1.pb(stops[j]);
				if (stops[j] == t)
				{
					flag1 = true;
					break;
				}
			}
		}

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

		if (flag1 && ss1.size() != 0 && ss2.size() != 0 && ss1.size() < ss2.size())
		{
			rep(j, ss1.size())
			{
				cout << ss1[j];
				cout << ((j != ss1.size() - 1) ? " " : "\n");
			}
		}
		if (flag2 && ss1.size() != 0 && ss2.size() != 0 && ss2.size() < ss1.size())
		{
			rep(j, ss2.size())
			{
				cout << ss2[j];
				cout << ((j != ss2.size() - 1) ? " " : "\n");
			}
		}
		if (flag1 && ss1.size() != 0 && ss2.size() == 0)
		{
			rep(j, ss1.size())
			{
				cout << ss1[j];
				cout << ((j != ss1.size() - 1) ? " " : "\n");
			}
		}
		if (flag2 && ss1.size() == 0 && ss2.size() != 0)
		{
			rep(j, ss2.size())
			{
				cout << ss2[j];
				cout << ((j != ss2.size() - 1) ? " " : "\n");
			}
		}
		if (flag1 && ss1.size() == ss2.size())
		{
			rep(j, ss1.size())
			{
				cout << ss1[j];
				cout << ((j != ss1.size() - 1) ? " " : "\n");
			}
		}
		if (flag2 && ss1.size() == ss2.size())
		{
			rep(j, ss2.size())
			{
				cout << ss2[j];
				cout << ((j != ss2.size() - 1) ? " " : "\n");
			}
		}
	}
	
	return 0;
}