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++: #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;
                }
                if (dst <= 5) {
                    for (int j = 5; j >= dst; --j) {
                        cout << ' ' << j;
                    }
                } else {
                    for (int j = 5; j <= dst; ++j) {
                        cout << ' ' << j;
                    }
                }
            }
            cout << endl;
        }

    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    for (int j=0; j<n; j++) {
        int on,off;
        cin>>on>>off;
        if(on<6){
            if(on<off){
                for(int i=on;i<off;i++)cout<<i<<" ";
                cout<<off<<endl;
            }else{
                for(int i=on;i>off;i--)cout<<i<<" ";
                cout<<off<<endl;
            }
        }else{
            if(off>5){
                if(on<off){
                    for(int i=on;i<off;i++)cout<<i<<" ";
                    cout<<off<<endl;
                }else{
                    for(int i=on;i<10;i++)cout<<i<<" ";
                    for(int i=5;i>0;i--)cout<<i<<" ";
                    for(int i=0;i<off;i++)cout<<i<<" ";
                    cout<<off<<endl;
                }
            }else{
                for(int i=on;i<10;i++)cout<<i<<" ";
                for(int i=5;i>off;i--)cout<<i<<" ";
                cout<<off<<endl;
            }
        }
    }
}

C++: #include<iostream>
using namespace std;
int main(){
	int a[16]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
        int n;
	cin>>n;
        int x,y;
        for(int i=0;i<n;i++){
		cin>>x>>y;
		int l,m;
             if(x<y){
                for(int j=0;j<10;j++)
                        if(a[j]==x) l=j;
	        for(int k=l;k<10;k++)
			if(a[k]==y) m=k;
		for(int p=l;p<=m;p++){
		    cout<<a[p]<<" ";
                }
              }else {
		for(int j=0;j<16;j++)
                        if(a[j]==x) l=j;
	        for(int k=l;k<16;k++)
			if(a[k]==y) m=k;
		for(int p=l;p<=m;p++){
		    cout<<a[p]<<" ";
                }
              }
              cout<<endl;
        }
        return 0;
}

C++: //Name: Bus Line
//Level: 2
//Category: シミュレーション
//Note: 

/**
 * 1周ぶんの系列を埋め込んでおき、適宜出力する。
 * 直線部のバス停が指定された時は別途対応する。
 */
#include <iostream>
#include <vector>

using namespace std;

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

bool solve(bool first) {
    int a, b;
    cin >> a >> b;
    if(a <= 5 && b <= 5) {
        bool first = true;
        for(int i = a; i != b; i += a<b?1:-1) {
            if(!first) cout << ' ';
            cout << i;
            first = false;
        }
        cout << ' ' << b;
    } else {
        int cur = 0;
        while(ROUTE[cur] != a) ++cur;
        cout << ROUTE[cur];
        while(ROUTE[cur] != b) {
            cur = (cur + 1) % (sizeof(ROUTE) / sizeof(int));
            cout << ' ' << ROUTE[cur];
        }
    }
    cout << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(2);

    bool first = true;
    int N;
    cin >> N;
    while(N-- && solve(first)) {
        first = false;
    }
    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, 1, 2, 3, 4, 5, 6, 7, 8, 9
};
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>
using namespace std;

void solve(int n, int m, bool d){

  if(n == m){
    cout << n << endl;
    return;
  }
  cout << n << " ";
  if(n == 9) solve(5, m, false);
  else if(!n) solve(n+1, m, true);
  else if(d) solve(n+1, m, true);
  else solve(n-1, m, false);
}

int main(){

  int l;
  int n,m;

  cin >> l;

  while(l--){
    cin >> n >> m;
    if(n == 9) solve(n, m, false);
    else if(n < 6 && n > m) solve(n, m, false);
    else solve(n, m, true);
  }

}