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 <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

string toString(int x)
{
	stringstream ss; ss << x;
	return ss.str();
}

string rootString(int f, int t)
{
	int b = f < t ? 1 : -1;
	
	string res;
	
	for(int i = f; i != t; i += b)
		res += toString(i);
	
	return res + toString(t);
}

void print(string s)
{
	rep(i, s.size())
		cout << s[i] << (i == s.size() - 1 ? "\n" : " ");
}

int main()
{
	int n;
	cin >> n;
	
	while(n--)
	{
		int f, t;
		cin >> f >> t;
		
		if(f < t)	print(rootString(f, t));
		else
		{
			if(f <= 5)	print(rootString(f, t));
			else if(t < 5) print(rootString(f, 9) + toString(5) + rootString(4, t));
			else if(t == 5) print(rootString(f, 9) + toString(5));
			else print(rootString(f, 5) + rootString(4, 0) + rootString(1, t));
		}
	}
}

C++: #include <iostream>
#include <cmath>

using namespace std;

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

int main()
{
    int a,b,n,p1,p2,d1,d2;
    bool flag;
    cin >> n;
    while(n--) {
        cin >> a >> b;
        flag = true;
        for(int i = 0; flag && i < 15; i++) {
            if(line[i] == a) {
                p1 = i;
                d1 = 0;
                for(int j = p1;; j++, d1++)
                    if(line[j % 15] == b) {
                        flag = false;
                        break;
                    }
            }
        }
        
        flag = true;
        for(int i = p1 + 1; flag; i++) {
            if(line[i % 15] == a) {
                p2 = i % 15;
                if(p2 == p1) {
                    d2 = d1;
                    break;
                } else {
                    d2 = 0;
                    for(int j = p2;; j++, d2++) 
                        if(line[j % 15] == b)  {
                            flag = false;
                            break;
                        }
                }
            }
        }
        if(d1 <= d2) {
            for(int i = 0; i <= d1; i++) {
                if(i == d1) {
                    cout << line[(i + p1) % 15] << endl;
                } else {
                    cout << line[(i + p1) % 15] << " ";
                }
            }
        } else {
            for(int i = 0; i <= d2; i++) {
                if(i == d2) {
                    cout << line[(i + p2) % 15] << endl;
                } else {
                    cout << line[(i + p2) % 15] << " ";
                }
            }

        }
    }
}

C++: #include <string>
#include <iostream>
using namespace std;
int n, x, y; string s = "0 1 2 3 4 5 6 7 8 9 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 5 4 3 2 1";
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &x, &y);
		string t = "0 1 2 3 4 5 6 7 8 9 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 5 4 3 2 1";
		for(int i = 0; i < s.size(); i += 2) {
			for(int j = i + 2; j < s.size(); j += 2) {
				if(s[i] == x + 48 && s[j] == y + 48 && j - i + 1 < t.size()) {
					t = s.substr(i, j - i + 1);
				}
			}
		}
		cout << t << endl;
	}
}

C++: #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    int N;
    cin >> N;
    for (;N--;) {
        int src, dst;
        cin >> src >> dst;

        if (src < dst) {
            cout << src;
            for (int j = src+1; j <= dst; ++j) {
                cout << ' ' << j;
            }
            cout << endl;
        } else {
            cout << src;
            if (src <= 5) {
                for (int j = src-1; j >= dst; --j) {
                    cout << ' ' << j;
                }
            } else {
                for (int j = src+1; j <= 9; ++j) {
                    cout << ' ' << j;
                }
                for (int j = 5; j >= dst; --j) {
                    cout << ' ' << j;
                }
            }
            cout << endl;
        }

    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

#define N 15
int d[N] = {0, 1, 2, 3, 4, 5 ,6 ,7 ,8 ,9 ,5 ,4 ,3 ,2 ,1};

int main(void){
  int n ;
  while(n--){
    int a,b;
    cin>>a>>b;
    if(a<=5 && b < a){
      a = 15 - a;
    }
    while(d[a] != b){
      cout<<d[a]<<" ";
      a = (a + 1) % N; 
    }
    cout<<d[a]<<endl;
  }
}