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 q;
	cin >> q;
	for(int i=0;i<q;i++)
	{
		int from,to;
		cin >> from >> to;
		if(from <= to)
		{
			for(int j=from;j<=to;j++)
			{
				if(j!=to)cout << j << ' ';
				else cout << j << endl;
			}
			continue;
		}
		if(from<=5)
		{
			for(int j=from;j>=to;j--)
			{
				if(j!=to)cout << j <<  ' ';
				else cout << j << endl;
			}
		}
		else
		{
			for(int j=from;j<=9;j++)cout << j << ' ';
			for(int j=5;j>to;j--)cout << j << ' ';
			cout << to << endl;
		}
	}
	return 0;
}

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

const std::string bstop = "012345678954321";

int main()
{
	int n;
	std::cin >> n;
	while( n-- )
	{
		int s, e;
		std::cin >> s >> e;
		
		bool fl = false;
		std::string ans;

		while( true )
		{
			for( int i = 0; i != bstop.size(); ++i )
			{
				if( fl )
				{
					ans += ' ';
					ans += bstop[i];
				}

				if( bstop[i] == s + '0' )
				{
					ans.clear();
					fl = true;
					ans = bstop[i];
				}

				if( fl && bstop[i] == e + '0' )
					goto end;
			}
		}
end:;
		std::cout << ans << std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	const int path1[] = { 0, 1, 2, 3, 4, 5, 4, 3, 2, 1 };
	const int path2[] = { 5, 6, 7, 8, 9 };

	int len1 = sizeof(path1)/sizeof (path1[0]);
	int len2 = sizeof(path2)/sizeof (path2[0]);

//	cut here before submit 
//	freopen ("testcase.busline2", "r", stdin );
	string str = "";
	int n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;
		if (n == 0 ){
			break;
		} // end if
		int i, j, k;
		for (i = 0; i < n; ++i){
			getline (cin, str );
			if (str.empty() ){
				break;
			} // end if
			vector <int> res;
			int from, to;
			stringstream ss(str);
			ss >> from >> to;

			if (from < to ){
				if (from < 5 && to <= 5 ){
					for (j = from; j <= to; ++j){
						res.push_back (path1[j]);
					} // end if
				}else if (from < 5 && to > 5){
					for (j = from; path1[j] != 5; ++j){
						res.push_back (path1[j]);
					} // end for
					for (k = 0; path2[k] <= to; ++k){
						res.push_back (path2[k]);
					} // end if
				}else if (from >= 5 && to > 5){
					for (k = from - 5; path2[k] <= to; ++k){
						res.push_back (path2[k]);
					} // end if
				} // end if
			}else if (from > to){
				if (from <= 5 && to < 5 ){
					for (j = (len1 - from) % len1; path1[j] != to; j = (j + 1) % len1){
						res.push_back (path1[j]);	
					} // end for
					res.push_back (path1[j] );
				}else if (from > 5 && to <= 5 ){
					for (k = from - 5; path2[k] != 5; k = (k + 1) % len2 ){
						res.push_back (path2[k]);
					} // end for
					for (j = 5; path1[j] != to; j = (j + 1) % len1 ){
						res.push_back (path1[j]);
					} // end for
					res.push_back (path1[j]);
				
				}else if (from > 5 && to > 5 ){
					for (k = from - 5; path2[k] != to; k = (k + 1) % len2 ){
						res.push_back (path2[k] );
					} // end for
					res.push_back (path2[k]);
				} // end if
			} // end if

			int size = res.size();
			for (j = 0; j < size; ++j){
				cout << res[j];
				if (j != size - 1){
					cout << ' ';
				} // end if
			} // end for
			cout << endl;
		} // end for
	} // end loop
		
	return 0;
}

C++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
template <class _Tv> inline string join(const _Tv &v,string sep=" "){
    ostringstream s;FOREACH(it,v){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef complex<D> P;
#define X real()
#define Y imag()
#define EPS (1e-9)
#define DEQ(p1,p2) (abs((p1)-(p2)) < EPS)

#ifdef _DEBUG
template<class _Tv> inline void _prfe(const char *_n,const _Tv _c,bool _p=false){
    ITER(_c) _it=_c.begin();
    if(_p){cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

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

vector<int> solve(int a, int b){
    vector<int> r;
    int n = ESIZEOF(tbl);
    bool f = false;
    REP(i,n){
        if(tbl[i] == a){f = true; r.clear();}
        if(f){
            r.pb(tbl[i]);
            if(tbl[i] == b) break;
        }
    }
    return r;
}

int main(){
    int n,a,b;
    cin >> n;
    while(cin >> a >> b){
        cout << join(solve(a,b)) << endl;
    }

    return 0;
}