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 <stack>
#include <queue>

using namespace std;

int hyou[10][10] = {{0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
				    {1, 0, 1, 0, 0, 0, 0, 0, 0, 0},
				    {0, 1, 0, 1, 0, 0, 0, 0, 0, 0},
				    {0, 0, 1, 0, 1, 0, 0, 0, 0, 0},
				    {0, 0, 0, 1, 0, 1, 0, 0, 0, 0},
				    {0, 0, 0, 0, 1, 0, 1, 0, 0, 0},
				    {0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
				    {0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
				    {0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
					{0, 0, 0, 0, 0, 1, 0, 0, 0, 0},};

typedef pair<int, int> P;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		queue<P> q;
		P pp;
		pp.first = a;
		pp.second = -1;
		int hyou2[10] = {0};
		q.push(pp);
		while (!q.empty()) {
			P p = q.front();
			hyou2[p.first] = p.second;
			bool hantei = false;
			q.pop();
			for (int j = 0; j < 10; j++) {
				if (hyou[p.first][j] == 1) {
					if (j == b) {
						hyou2[j] = p.first;
						hantei = true;
						break;
					} else if (hyou2[j] == 0){
						P ppp;
						ppp.first = j;
						ppp.second = p.first;
						q.push(ppp);
					}
				}
			}
			if (hantei) {
				break;
			}
		}
		stack<int> stk;
		int t = b;
		while (t != -1) {
			stk.push(t);
			t = hyou2[t];
		}
		cout << stk.top();
		stk.pop();
		while (!stk.empty()) {
			cout << " " << stk.top();
			stk.pop();
		}
		cout << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	printf("%d\n", n);
	while (n--)
	{
		int from, to;
		scanf("%d %d", &from, &to);
		if (to > from)
		{
			for (int i = from; i < to; ++i)
				printf("%d ", i);
			printf("%d\n", to);
		}
		else
		{
			if (from >= 6)
			{
				for (int i = from; i <= 9; ++i)
					printf("%d ", i);

				if (to >= 6 && to < from)
				{
					for (int i = 5; i > 0; --i)
						printf("%d ", i);
					for (int i = 0; i < to; ++i)
						printf("%d ", i);
					printf("%d\n", to);
					continue;
				}
				else
					from = 5;
			}
			for (int i = from; i > to; --i)
				printf("%d ", i);
			printf("%d\n", to);
		}
	}

	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;
		f(a,b);
	}
	return 0;
}

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

int busLine[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1 };
const int SIZE = sizeof(busLine) / sizeof(int);

int main()
{
	int n;
	while( cin >> n ){
		for( int i = 0; i < n; ++i ){
			int start, end;
			cin >> start >> end;

			int step = 0;
			int index = 0;
			int memo[ SIZE ];
			bool bFoundStart = false;
			while( 1 ){
				if( busLine[ index ] == start ){
					bFoundStart = true;
					step = 0;
					memo[ step ] = busLine[ index ];
					++index;
					continue;
				}
				++step;
				memo[ step ] = busLine[ index ];
				if( bFoundStart && busLine[ index ] == end ){
					break;
				}
				++index;
				index %= SIZE;
			}

			bool bFirst = true;
			for( int j = 0; j <= step; ++j ){
				if( bFirst ){
					bFirst = false;
				}else{
					cout << " ";
				}
				cout << memo[ j ];
			}
			cout << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
int main()
{
	int n;

	cin >> n;
	for(int i = 0; i < n; ++i){
		int st, ed;
		queue<int> q;
		cin>>st>>ed;

		if( st == ed ){
			cout << st << '\n';
			continue;
		}
		if( ed <= 5 ){
			if( st > 5 ){
				for(int i = st; i <= 9; ++i) q.push( i ); 
				for(int i = 5; i >= ed; --i) q.push( i );
			}else{
				if( st > ed )
					for(int i = st; i >= ed; --i) q.push( i );
				else
					for(int i = st; i <= ed; ++i) q.push( i );
			}
		}else{
			if( st < ed ){
				for(int i = st; i <= ed; ++i) q.push( i );
			}else{
				for(int i = st; i <= 9; ++i) q.push( i );
				for(int i = 5; i <= ed; ++i) q.push( i );
			}
		}
		cout << q.front();
		q.pop();
		while( !q.empty() ){
			cout << ' ' << q.front();
			q.pop();
		}
		cout << '\n';
	}
	return 0;
}

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

int main()
{
  const int bus_stop[] = { 0, 1, 2, 3, 4, 5,
                           6, 7, 8, 9 ,
                           5, 4, 3, 2, 1,
                         };
  int n;
  cin >> n;
  for (int dataset = 0; dataset<n; dataset++)
  {
    int from,to;
    cin >> from >> to;
    if ( 1 <= from && from <= 5 && to < from )
    {
      for (int i=from; i > to; i--)
      {
        cout << i << ' ' << flush;
      }
      cout << to << endl;
    }
    else
    {
      for (int i=from; bus_stop[i] != to; ( i == 14)? i=0 : i++)
      {
        cout << bus_stop[i] << ' ';
      }
      cout << to << endl;
    }
  }
}

C++: #include<iostream>
using namespace std;
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++){
		int a, b; cin >> a >> b;
		if (a <= 5 && b <= 5){
			if (a > b) for (int i = a; i >= b; i--){
				cout << i;
				if (i != b)cout << ' ';
				else cout << endl;
			}
			else for (int i = a; i <= b; i++){
				cout << i;
				if (i != b)cout << ' ';
				else cout << endl;
			}
		}
		else{
			if (a >= 6){
				if (b >= 6){
					if (a < b){
						for (int i = a; i <= b; i++){
							cout << i;
							if (i != b)cout << ' ';
							else cout << endl;
						}
					}
					else {
						for (int i = a; i < 10; i++) {
							cout << i << ' ';
						}
						cout << "5 4 3 2 1 0 1 2 3 4 5 ";
						for (int i = 6; i <= b; i++) {
							cout << i;
							if (i != b)cout << ' ';
							else cout << endl;
						}
					}
				}
				else{
					for (int i = a; i < 10; i++){
						cout << i << ' ';
					}
					for (int i = 5; i >= b; i--){
						cout << i;
						if (i != b)cout << ' ';
						else cout << endl;
					}
				}
			}
			else{
				for (int i = a; i <= b; i++){
					cout << i;
					if (i != b)cout << ' ';
					else cout << endl;
				}
			}
		}
	}
}