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<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<utility>
#include<cctype>
using namespace std;

#define ull unsigned long long
#define stt(it,order) sort(it.begin(),it.end(),order)
#define st(it) sort(it.begin(),it.end())
#define ll long long
#define rep(i,j) for(int i=0;i<j;++i)
#define loop(i,a,j) for(int i=a;i<j;++i)
#define mpi(it,table,T,E) for(map<T,E>::iterator it = table.begin();it!=table.end();++it)
#define PI 3.141592654
#define pb(v,e) v.push_back(e)

string sint(int i){
   stringstream buf;
   buf<<i;
   return buf.str();
}

/*
   ifstream fin("input.txt");
   ofstream fout("output.txt");
#define cin fin
#define cout fout
*/

int graph[15][15] = { 
   {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
   {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
   {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
   {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0},
   {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0},
   {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
   {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0},
   {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},
   {0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},
   {0,0,0,0,0,0,0,0,0,0,1,0,0,0,0},
   {0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
   {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
   {0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
   {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};

int sol[15];

int alias[] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};

string print(int i,int e){
   if( i == -1)return "";
   if(e)return print(sol[i],0)+sint(alias[i])+"\n";
   return print(sol[i],0)+sint(alias[i])+" ";
}

string do_bfs(int j,int k){
   
   bool vis[15];
   memset(vis,0,sizeof(vis));
   memset(sol,-1,sizeof(sol));

   vis[j] = true;
   sol[j] = -1;

   queue<int> nodes;
   nodes.push(j);

   int stop = j;

   while(!nodes.empty()){
      int nx = nodes.front();
      nodes.pop();
      if( alias[nx] == k){
         stop = nx;
         break;
      }
      rep(i,15){
         if( graph[nx][i] == 1 && !vis[i]){
            sol[i] = nx;
            vis[i] = true;
            nodes.push(i); 
         }
      }
   }
   return print(stop,1);
}

int main(){
   int u;
   scanf("%d",&u);
   rep(a,u){
      string sol = "1 2 3 4 5 6 7 8 9 5 4 3 2 1 0 0 0";
      
      int j,k;
      scanf("%d %d",&j,&k);

      rep(i,15){
         if( alias[i] == j){
            string aux = do_bfs(i,k);
            if( sol.size() > aux.size()) sol = aux;
         }
      }
      printf("%s",sol.c_str());
   }
   return 0;
}

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

int main(){
	int n;
	cin>>n;
	int busstop[15]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
	for(int i=0;i<n;i++){
		int start,stop,l,j;
		vector<int> ans1,ans2;
		cin>>start>>stop;
		for(l=start;busstop[l%15]!=stop;l++){
			ans1.push_back(busstop[l]);
			if(l==0)l=-1;
		}
		ans1.push_back(busstop[l]);
		for(j=15-start;busstop[j%15]!=stop;j++){
			ans2.push_back(busstop[j]);
			if(j==14)j=-1;
		}
		ans2.push_back(busstop[j]);
		if(ans1.size()<ans2.size()){
			for(int k=0;k<(ans1.size()-1);k++){
				cout<<ans1[k]<<" ";
			}
			cout<<ans1[ans1.size()-1]<<endl;
		}else{
			for(int k=0;k<(ans2.size()-1);k++){
				cout<<ans2[k]<<" ";
			}
			cout<<ans2[ans2.size()-1]<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;
string bus_stop = "0123456789543210123456789543210123456789543210";

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		char s, g;
		cin >> s >> g;
		string ans1, ans2;
		bool flag = false;
		int pos = 0;
		for(int i = 0; i < bus_stop.size(); ++i)
		{
			if(!flag && bus_stop[i] == s)
			{
				flag = true;
				pos = i;
			}
			if(flag)
			{
				ans1 += bus_stop[i];
				if(bus_stop[i] == g)
				{
					break;
				}
			}
		}
		flag = false;
		for(int i = pos + 1; i < bus_stop.size(); ++i)
		{
			if(bus_stop[i] == s)
			{
				flag = true;
			}
			if(flag)
			{
				ans2 += bus_stop[i];
				if(bus_stop[i] == g)
				{
					break;
				}
			}
		}
		if(ans1.size() < ans2.size())
		{
			cout << ans1[0];
			for(int i = 1; i < ans1.size(); ++i)
			{
				cout << " " << ans1[i];
			}
			cout << endl;
		}
		else
		{
			cout << ans2[0];
			for(int i = 1; i < ans2.size(); ++i)
			{
				cout << " " << ans2[i];
			}
			cout << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>

using namespace std;

int main(void){

  int n;
  cin >> n;

  while(n--){

    int from,too;
    cin >> from >> too;

    if( from < too ){
      for( int i = from ; i <= too ; i++ ){
	if( i == too ) cout << i << endl;
	else cout << i << " ";
      }
    }
    else if( ( 0 <= from && from <= 5 ) && ( 0 <= too && too <= 5 ) ){
      for( int i = from ; i >= too ; i-- ){
	if( i == too ) cout << i << endl;
	else cout << i << " ";
      }
    }

    else if( 6 <= from && from <= 9 ){

      for( int i = from ; i <= 9 ; i++ )
	cout << i << " ";

      for( int i = 5 ; i >= too ; i-- ){
	if( i == too ) cout << i << endl;
	else cout << i << " ";
      }
    }
    
  }
return 0;
}

C++: int main(){int s,t,d,n;scanf("%d",&n);while(n--){scanf("%d %d",&s,&t);d=(t<s&&s<6)? -1:1;while(t!=s){printf("%d ",s);s+=d;if(s>9){d=-1;s=5;}elseif(s<0){d=1;s=1;}}printf("%d\n",t);}return 0;}

C++: // 2011/03/22 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int bus[15];
	bus[0]  = 0;
	bus[1]  = 1;
	bus[2]  = 2;
	bus[3]  = 3;
	bus[4]  = 4;
	bus[5]  = 5;
	bus[6]  = 6;
	bus[7]  = 7;
	bus[8]  = 8;
	bus[9]  = 9;
	bus[10] = 5;
	bus[11] = 4;
	bus[12] = 3;
	bus[13] = 2;
	bus[14] = 1;

	int n;
	cin >> n;

	for(int i=0; i<n; i++){
		int a, b;
		cin >> a >> b;

		if(a==1&&b<1)
			a = 14;
		if(a==2&&b<2)
			a = 13;
		if(a==3&&b<3)
			a = 12;
		if(a==4&&b<4)
			a = 11;
		if(a==5&&b<5)
			a = 10;

		cout << bus[a];
		do{
			a = (a+1)%15;
			cout << ' ' << bus[a];
		}while(bus[a]!=b);
		cout << endl;
	}

	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	const int stations[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0};
	int n;
	scanf("%d", &n);
	rep(i, n){
		int s, g;
		scanf("%d%d", &s, &g);
		
		for(s = 5<s || s<g ? s : 15-s; stations[s] != stations[g]; ++s)
			printf("%d ", stations[s]);
		printf("%d\n", stations[g]);
	}
	return 0;
}