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 "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"



int main() {
	int N; cin >> N;
	for (int i = 0; i < N; ++i) {
		int a, b; cin >> a >> b;
		vector<int>anss;
		if (a < b) {
			for (int j = a; j <= b; ++j) {
				anss.emplace_back(j);
			}
		}
		else if (a == b) {
			anss.emplace_back(a);
		}
		else {
			if (a <=5) {
				for (int j = a; j >= b; --j) {
					anss.emplace_back(j);
				}
			}
			else {
				if (b <= 5) {

					for (int j = a; j <= 9; ++j) {
						anss.emplace_back(j);
					}
					for (int j = 5; j >= b; --j) {
						anss.emplace_back(j);
					}
				}
				else {
					for (int j = a; j <= 9; ++j) {
						anss.emplace_back(j);
					}
					for (int j = 5; j >= 0; --j) {
						anss.emplace_back(j);
					}
					for (int j = 1; j <= b; ++j) {
						anss.emplace_back(j);
					}
				}
			}
		}
		for (int i = 0; i < anss.size(); ++i) {
			cout << anss[i];
			if (i == anss.size() - 1)cout << endl;
			else cout << " ";
		}
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
#include <queue>

using namespace std;

int hyou[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},};

typedef pair<int, int> P;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		queue<P> q;
		P pp;
		pp.first = a;
		pp.second = -1;
		int hyou2[10];
		for (int j = 0; j < 10; j++) {
			hyou2[j] = -2;
		}
		q.push(pp);
		while (!q.empty()) {
			P p = q.front();
			hyou2[p.first] = p.second;
			bool hantei = false;
			q.pop();
			for (int j = 0; j < 10; j++) {
				if (hyou[p.first][j] == 1) {
					if (j == b) {
						hyou2[j] = p.first;
						hantei = true;
						break;
					} else if (hyou2[j] == -2){
						P ppp;
						ppp.first = j;
						ppp.second = p.first;
						q.push(ppp);
					}
				}
			}
			if (hantei) {
				break;
			}
		}
		stack<int> stk;
		int t = b;
		while (t != -1) {
			stk.push(t);
			t = hyou2[t];
		}
		cout << stk.top();
		stk.pop();
		while (!stk.empty()) {
			cout << " " << stk.top();
			stk.pop();
		}
		cout << endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

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

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a) * b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
	return l.first + t * (l.first - l.second);
}

bool intersectSP(const line &l, const xy_t &p){
	return abs(l.first- p) + abs(l.second - p) - abs(l.first - l.second) < EPS;
}

double distanceSP(line s, xy_t p){
	const xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

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

int main(){
	int n;
	cin >> n;
	rep(t, n){
		int a, b;
		cin >> a >> b;
		if(a > 5 || a <= 5 && a < b){
			while(next1[a] != b){
				cout << next1[a] << " ";
				a++;
			}
			cout << b << endl;
		}else{
			while(next2[a] != b){
				cout << next2[a] << " ";
				a--;
			}
			cout << b << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  const char *ans[10][10]={
    "","0 1","0 1 2","0 1 2 3","0 1 2 3 4","0 1 2 3 4 5","0 1 2 3 4 5 6","0 1 2 3 4 5 6 7","0 1 2 3 4 5 6 7 8","0 1 2 3 4 5 6 7 8 9",
    "1 0","","1 2","1 2 3","1 2 3 4","1 2 3 4 5","1 2 3 4 5 6","1 2 3 4 5 6 7","1 2 3 4 5 6 7 8","1 2 3 4 5 6 7 8 9",
    "2 1 0","2 1","","2 3","2 3 4","2 3 4 5","2 3 4 5 6","2 3 4 5 6 7","2 3 4 5 6 7 8","2 3 4 5 6 7 8 9",
    "3 2 1 0","3 2 1","3 2","","3 4","3 4 5","3 4 5 6","3 4 5 6 7","3 4 5 6 7 8","3 4 5 6 7 8 9",
    "4 3 2 1 0","4 3 2 1","4 3 2","4 3","","4 5","4 5 6","4 5 6 7","4 5 6 7 8","4 5 6 7 8 9",
    "5 6 7 8 9 5 4 3 2 1 0","5 6 7 8 9 5 4 3 2 1","5 6 7 8 9 5 4 3 2","5 6 7 8 9 5 4 3","5 6 7 8 9 5 4","","5 6","5 6 7","5 6 7 8","5 6 7 8 9",
    "6 7 8 9 5 4 3 2 1 0","6 7 8 9 5 4 3 2 1","6 7 8 9 5 4 3 2","6 7 8 9 5 4 3","6 7 8 9 5 4","6 7 8 9 5","","6 7","6 7 8","6 7 8 9",
    "7 8 9 5 4 3 2 1 0","7 8 9 5 4 3 2 1","7 8 9 5 4 3 2","7 8 9 5 4 3","7 8 9 5 4","7 8 9 5","7 8 9 5 4 3 2 1 0 1 2 3 4 5 6","","7 8","7 8 9",
    "8 9 5 4 3 2 1 0","8 9 5 4 3 2 1","8 9 5 4 3 2","8 9 5 4 3","8 9 5 4","8 9 5","8 9 5 4 3 2 1 0 1 2 3 4 5 6","8 9 5 4 3 2 1 0 1 2 3 4 5 6 7","","8 9",
    "9 5 4 3 2 1 0","9 5 4 3 2 1","9 5 4 3 2","9 5 4 3","9 5 4","9 5","9 5 4 3 2 1 0 1 2 3 4 5 6","9 5 4 3 2 1 0 1 2 3 4 5 6 7","9 5 4 3 2 1 0 1 2 3 4 5 6 7 8","",
  };
  int n;
  scanf("%d",&n);
  while(n --> 0){
    int a,b;
    scanf("%d%d",&a,&b);
    puts(ans[a][b]);
  }
  return 0;
}