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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int s[16] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
int s2[10] = {5,6,7,8,9,5,6,7,8,9};
int main(void){
  int n;
  cin>>n;
  while(n--){
    int a,b;
    vector<int> ans;
    cin>>a>>b;
    bool f=false;
    REP(i,16){
      if(s[i]==a){
        if(!f)f=true;
        else ans.clear();
      }
      if(f) ans.push_back(s[i]);
      if(f&&s[i]==b) break;
    }
    if(a+b>=13){
      ans.clear();
      f = false;
      REP(i,10){
        if(s2[i]==a){
          if(!f)f=true;
          else ans.clear();
        }
        if(f) ans.push_back(s2[i]);
        if(f&&s2[i]==b) break;
      }
    }
    REP(i,ans.size()){
      if(i) cout<<" ";
      cout<<ans[i];
    }
    cout<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	
	int n;
	cin>>n;
	rep(i,n){
		vint ans;
		int a,b;
		cin>>a>>b;
		// cout<<q.front()<<endl;
		queue<int> q;
		rep(i,10) q.push(i);
		rep(i,6) q.push(5-i);
		rep(i,30){
			int t=q.front();
			q.push(t);
			q.pop();
			if(t==a){
				ans.clear();
				ans.PB(t);
			}
			else if(t==b&&ans.size()&&ans[0]==a){
				ans.PB(t);
				break;
			}
			else{
				ans.PB(t);
			}
		}
		rep(i,ans.size()){
			if(i) cout<<" ";
			cout<<ans[i];
		}
		cout<<endl;
	}
}

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

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

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

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define INF 1000000
using namespace std;
int loop[15] ={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
	
int main(){
  int a,b;
  int mn = INF;
  vector<int>ans;
  int n;
  cin >> n;
  while(n-- ){
    cin >> a >>b;
    ans.clear();
    ans.push_back(a);
    for(int i = a+1 ;; i++){

      if(loop[i%15] == a)ans.clear();

      ans.push_back(loop[i%15]);

      if(loop[i%15] == b)break;
    }

    for(int i = 0 ; i < ans.size() ; i++ ){
      if(i == 0)cout << ans[i];
      else cout << ' ' << ans[i];  
    }
    cout << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int x=0;x<n;++x){
		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>
using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int a,b;
		cin >> a >> b;
		if(a < b){
			for(int j = a;j <= b;j++) cout << (j == a ? "" : " ") << j;
		}else if(a >= 6){
			for(int j = a;j <= 9;j++) cout << (j == a ? "" : " ") << j;
			if(b >= 5) for(int j = 5;j <= b;j++) cout << " " << j;
			else for(int j = 5;j >= b;j--) cout << " " << j;
		}else{
			for(int j = a;j >= b;j--) cout << (j == a ? "" : " ") << j;
		}
		cout << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  while(n--){
    int a,b;
    cin>>a>>b;
    if(a==b){
      printf("%d\n",a);
      continue;
    }
    if(a>5){
      if(a<b){
        for(int i=a;i<=b;i++){
          printf("%d%c",i,i==b?'\n':' ');
        }
        continue;
      }
      for(int i=a;i<=9;i++)printf("%d ",i);printf("5");
      if(b==5){
        printf("\n");
        continue;
      }else printf(" ");
      if(b<5){
        for(int i=4;i>=b;i--)printf("%d%c",i,i==b?'\n':' ');
        continue;
      }
      for(int i=4;i>=0;i--)printf("%d ",i);
      for(int i=1;i<=5;i++)printf("%d ",i);
      for(int i=6;i<=b;i++)printf("%d%c",i,i==b?'\n':' ');
    }else{
      if(b<=5){
        if(a<b)for(int i=a;i<=b;i++)printf("%d%c",i,i==b?'\n':' ');
        else for(int i=a;i>=b;i--)printf("%d%c",i,i==b?'\n':' ');
        continue;
      }else{
        for(int i=a;i<=5;i++)printf("%d ",i);
        for(int i=6;i<=b;i++)printf("%d%c",i,i==b?'\n':' ');
      }
    }
  }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define PP(m) REP(i, m.size()) cout << m[i] << endl;

int main() {
  int n;
  vector<int> co(10);
  vector<int> cr(6);

  REP(i, 9) co[i] = i+1;
  REP(i, 9) cr[i] = i+1;
  co[9] = 5;
  cr[9] = 5;

  for (int i=0; i<5; i++) cr[5-i] = 4-i;

  // PP(co);PP(cr);

  cin >> n;
  REP(i, n) {
    int a,b;
    bool rev = false;
    cin >> a >> b;
    while (1==1) {
      cout << a;
      if (a == b) {
        cout << endl;
        break;
      }
      if (a == 9 || (a == 0 && rev) || (a <= 5 && b <= 5 && a > b && !rev)) {
        rev = !rev;
      }
      if (!rev) {
        a = co[a];
      } else {
        a = cr[a];
      }
      cout << " ";
    }
  }


  return 0;
}