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;

void print_stops(int from, int to) {
    if (from <= 5 && to <= 5) {
        if (from < to) {
            for (int i = from; i <= to; i++) {
                cout << i << ' ';
            }
        } else {
            for (int i = from; i >= to; i--) {
                cout << i << ' ';
            }
        }
    } else if (from <= 5 && 6 <= to && to <= 9) {
        for (int i = from; i <= to; i++) {
            cout << i << ' ';
        }
    } else if (6 <= from && from <= 9 && to <= 5) {
        for (int i = from; i <= 9; i++) {
            cout << i << ' ';
        }
        for (int i = 5; to <= i; i--) {
            cout << i << ' ';
        }
    } else if (6 <= from && from <= 9 && 6 <= to && to <= 9) {
        if (from < to) {
            for (int i = from; i <= to; i++) {
                cout << i << ' ';
            }
        } else {
            for (int i = from; i <= 9; i++) {
                cout << i << ' ';
            }
            for (int i = 5; 0 <= i; i--) {
                cout << i << ' ';
            }
            for (int i = 1; i <= 5; i++) {
                cout << i << ' ';
            }
            for (int i = 6; i <= to; i++) {
                cout << i << ' ';
            }
        }
    }
    cout << endl;
}

int main() {
    int n; cin >> n;
    while (n--) {
        int from, to;
        cin >> from >> to;
        print_stops(from, to);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
 
// #define int long long
 
/* short */
#define pb push_back
#define print(x) cout << x << '\n'
 
/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, a) for (int i = (a); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = INT_MAX;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

signed main()
{
  //ios::sync_with_stdio(false);
  int n;

  cin >> n;
  
  for (;n--;){
    int a, b;
    cin >> a >> b;
    if (a < b){
      REPS(i, a, b + 1){
        printf("%d%c", i, (i != b) ? ' ' : '\n');
      }
    } else {
      if (0 <= a && a <= 5){
        DEPS(i, a, b){
          printf("%d%c", i, (i != b) ? ' ' : '\n');
        }
      } else {
        if (0 <= b && b <= 5){
          REPS(i, a, 10){
            printf("%d ", i);
          }
          DEPS(i, 5, b){
            printf("%d%c", i, (i != b) ? ' ' : '\n');
          }
        } else {
          REPS(i, a, 10){
            printf("%d ", i);
          }
          DEPS(i, 5, 1){
            printf("%d ", i);
          }
          REP(i, b + 1){
            printf("%d%c", i, (i != b) ? ' ' : '\n');
          }
        }
      }
    }
  }

  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,15){
			int t=q.front();
			q.push(t);
			q.pop();
			if(t==a){
				ans.clear();
				ans.PB(t);
			}
			else if(t==b){
				ans.PB(t);
				break;
			}
			else{
				ans.PB(t);
			}
		}
		rep(i,ans.size()){
			if(i) cout<<" ";
			cout<<ans[i];
		}
		cout<<endl;
	}
}

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

void solve(int s, int g){
	if(s <= 5){
		if(s < g){
			for(int i = s; i <= g; i++){
				printf("%d", i);
				if(i != g)	printf(" ");
			}
			printf("\n");
		}else{
			for(int i = s; i >= g; i--){
				printf("%d", i);
				if(i != g)	printf(" ");
			}
			printf("\n");
		}
	}else if(g <= 5){
		for(int i = s; i <= 9; i++){
			printf("%d ", i);
		}
		for(int i = 5; i >= g; i--){
			printf("%d", i);
			if(i != g)	printf(" ");
		}
		printf("\n");
	}else{
		if(s < g){
			for(int i = s; i <= g; i++){
				printf("%d", i);
				if(i != g)	printf(" ");
			}
			printf("\n");
		}else{
			for(int i = s; i <= 9; i++){
				printf("%d ", i);
			}
			for(int i = 5; i <= g; i++){
				printf("%d", i);
				if(i != g)	printf(" ");
			}
			printf("\n");
		}
	}
}

int main(void){
	int n, s, g;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d %d", &s, &g);
		solve(s, g);
	}
  return 0;
}