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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename V>
constexpr string join(const V &v, const string &sep) {
  stringstream ss;
  if (v.size()) ss << v[0];
  loop(i, 1, v.size()) ss << sep << v[i];
  return ss.str();
}

void solve() {
  vi t = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};
  int n;
  cin >> n;
  while (n--) {
    int a, b;
    cin >> a >> b;
    int i = distance(t.begin(), find(all(t), a));
    vi v;
    for (;;) {
      v.pb(t[i]);
      i = (i + 1) % t.size();
      if (t[i] == b) break;
      if (t[i] == a) v.clear();
    }
    v.pb(t[i]);
    cout << join(v, " ") << endl;
  }
}

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

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

  int n;
  while (cin >> n) {
    while (n--) {
      int a, b;
      cin >> a >> b;

      int s = 0;
      for (; s < bussize; ++s) {
	if (busstop[s] == a)
	  break;
      }

      vector<int> ans;
      for (int i = s; i < bussize; ++i) {
	ans.push_back(busstop[i]);
	if (busstop[i] == b)
	  break;
      }

      if (1 <= a && a <= 5 && b < a) {
	vector<int> rev;
	for (int i = s; i >= 0; --i) {
	rev.push_back(busstop[i]);
	if (busstop[i] == b)
	  break;
	}
	if (rev.size() < ans.size())
	  ans = rev;
      }

      for (int i = 0; i < ans.size()-1; ++i)
	cout << ans[i] << " ";
      cout << ans.back() << endl;
    }
  }
  return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){

	int n,start,goal;

	scanf("%d",&n);

	for(int i=0; i < n; i++){
		scanf("%d %d",&start,&goal);

		if(start <= 5){
			if(start < goal){
				printf("%d",start);
				for(int k = start+1; k <= goal; k++){
					printf(" %d",k);
				}
				printf("\n");
			}else{
				printf("%d",start);
				for(int k = start-1; k >= goal; k--){
					printf(" %d",k);
				}
				printf("\n");
			}
		}else{
			if(goal >= 5){
				if(start < goal){
					printf("%d",start);
					for(int k= start+1; k <= goal; k++)printf(" %d",k);

					printf("\n");

				}else{
					printf("%d",start);
					for(int k= start+1; k <= 9; k++)printf(" %d",k);
					for(int k=5; k <= goal; k++)printf(" %d",k);
					printf("\n");
				}

			}else{
				printf("%d",start);
				for(int k=start+1; k <= 9; k++)printf(" %d",k);
				for(int k=5; k >= goal; k--)printf(" %d",k);
				printf("\n");
			}

		}

	}

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n;
	cin >> n;
	while (n--) {
		int a, b;
		scanf("%d %d", &a, &b);
		if (a < b)
			for (int i = a; i <= b; i++) printf("%d%c", i, i == b ? '\n' : ' ');
		else if (a <= 5)
			for (int i = a; i >= b; i--) printf("%d%c", i, i == b ? '\n' : ' ');
		else {
			for (int i = a; i <= 9; i++) printf("%d ", i);
			if (b < 5)
				for (int i = 5; i >= b; i--) printf("%d%c", i, i == b ? '\n' : ' ');
			else
				for (int i = 5; i <= b; i++) printf("%d%c", i, i == b ? '\n' : ' ');
				
		}
	}
	return 0;
}

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

int sol[10];

void print(int i,int e){
   if( i == -1)return;
   print( sol[i] , 0);
   if( e ){
      printf("%d\n",i);
   }else{
      printf("%d ",i);
   }
}

int main(){
   int j,k;
   while( scanf("%d %d",&j,&k) != EOF){

      queue<int> next;
      bool vis[10];
      memset(vis,0,sizeof(vis));
      memset(sol,-1,sizeof(sol));

      next.push(j);
      vis[j] = true;
      sol[j] = -1;
      int nx;
      while( !next.empty() ){
         nx = next.front();
         next.pop();
         if(nx == k)break;
         rep(i,10){
            if( graph[nx][i] && !vis[i]){
               vis[i] = true;
               sol[i] = nx;
               next.push(i);
            }
         }
      }

      print(k,1);
   }
   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;
}