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++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
void up(int x, bool f) {
	bool dir = f;
	if (dir) {
		x++;
		if (x == 10) {
			x = 5;
		}
	}
}
signed main() {
	int n; cin >> n;
	while (n--) {
		//for (int i = 0; i < 10; i++) {
		//	for (int j = 0; j < 10; j++) {
		//		int a(i), b(j);
		int a, b;
		cin >> a >> b;
		//cout << "start " << a << " fin " << b << endl;
		int x = a;
		vector<int>v, w;
		bool dir = true;
		while (x != b) {
			v.push_back(x);
			if (dir) {
				if (x == 9) {
					x = 5;
					if (b <= 5)dir = false;
					else dir = true;
				}
				else x++;
			}
			else {
				if (x == 0) {
					dir = true;
					x = 1;
				}
				else x--;
			}
		}
		v.push_back(x);
		dir = false;
		x = a;
		while (x != b) {
			w.push_back(x);
			if (6 <= x&&x <= 9)dir = true;
			if (dir) {
				if (x == 9) {
					x = 5;
					if (b <= 5)dir = false;
					else dir = true;
				}
				else x++;
			}
			else {
				if (x == 0) {
					x = 1;
					dir = true;
				}
				else x--;
			}
		}
		w.push_back(x);

		if (v.size() < w.size()) {
			rep(i, 0, v.size()) {
				if (i)cout << " ";
				cout << v[i];
			}
			cout << endl;
		}
		else {
			rep(i, 0, w.size()) {
				if (i)cout << " ";
				cout << w[i];
			}
			cout << endl;
		}
		//}
	}
	return 0;
}

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

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int a,b;
		cin>>a>>b;
		if(5<a&&5<b){
			if(b<a){
				cout<<a;
				for(int i=a+1;i<10;i++)cout<<' '<<i;
				for(int i=5;i<=b;i++)cout<<' '<<i;
			}else{
				cout<<a;
				for(int i=a+1;i<=b;i++)cout<<' '<<i;
			}
		}else if(5<a){
			cout<<a;
			for(int i=a+1;i<10;i++)cout<<' '<<i;
			for(int i=5;i>=b;i--)cout<<' '<<i;
		}else if(5<b){
			cout<<a;
			for(int i=a+1;i<=b;i++)cout<<' '<<i;
		}else{
			if(b<a){
				cout<<a;
				for(int i=a-1;i>=b;i--)cout<<' '<<i;
			}else{
				cout<<a;
				for(int i=a+1;i<=b;i++)cout<<' '<<i;
			}
		}
		cout<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
template <class _Tv> inline string join(const _Tv &v,string sep=" "){
    ostringstream s;for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

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

vector<int> solve(int st, int ed){
    vector<int> r;
    int n = sizeof(tbl)/sizeof(tbl[0]);
    bool f = false;
    for(int i = 0; i < n*2; ++i){
        if(tbl[i%n] == st){
            f = true; r.clear();
        }
        if(f){
            r.push_back(tbl[i%n]);
            if(tbl[i%n] == ed) break;
        }
    }
    return r;
}

int main(){
    int n,a,b;
    cin >> n;
    while(cin >> a >> b){
        cout << join(solve(a,b)) << endl;
    }
    return 0;
}

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

int main(){
  int n,f,t,m,num;
  int line[] = {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,0};

  cin >> n;
  while(n--){
    cin >> f >> t;

    m = 30;
    num = -1;
    for(int i=0;i<=30;i++){
      if(line[i] == f){
	for(int j=i+1;j<=30;j++){
	  if(line[j] == t){
	    if(m>j-i){
	      m = j-i;
	      num = i;
	    }
	  }
	}
      }
    }

    for(int i=num;i<num+m;i++)cout << line[i] << " ";
    cout << line[num+m] << endl;
  }
}

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)
#define PB push_back
#define p(a,b) g.PB(pii(a, b))
#define INF (1<<29)

typedef pair<int, int> pii;
typedef vector<pii> vp;

int main() {
	vp g; //pos to
	REP(i, 9) p(i, i + 1);
	p(9, 10);
	REP(i, 4) p(5 - i, i + 11);
	p(1, 0);
	
	int n;
	cin >> n;
	while (n--) {
		int prev[2][20], miner[2], tmp[2];
		int a, b;
		scanf("%d %d", &a, &b);
		
		tmp[0] = tmp[1] = INF;
		REP(i, g.size()) if (g[i].first == a) {
			if (tmp[0] == INF) tmp[0] = i;
			else tmp[1] = i;
		}
		
		miner[0] = miner[1] = INF;
		REP(i, 2) {
			if (tmp[i] == INF) break;
			
			queue<int> que; //pos
			que.push(tmp[i]);
			
			miner[i] = 0;
			while(true) {
				int pos = g[que.front()].first;
				int to = g[que.front()].second;
				que.pop();
				
				prev[i][miner[i]++] = pos;
				if (pos == b) break;
				
				que.push(to);
			}
		}
		
		int ans = miner[0] < miner[1] ? 0 : 1;
		REP(i, miner[ans]) {
			if (i != 0) printf(" ");
			printf("%d", prev[ans][i]);
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int x=0;x<n;++x){
		int from,to;
		cin>>from>>to;
		if(from<to)for(int i=from;i<=to;++i)cout<<i<<((i==to)?"":" ");
		else if(from<=5)for(int i=from;i>=to;--i)cout<<i<<((i==to)?"":" ");
		else if(to<=5){
			for(int i=from;i<=9;++i)cout<<i<<((i==9)?"":" ");
			for(int i=5;i>=to;--i)cout<<" "<<i;
		}else{
			for(int i=from;i<=9;++i)cout<<i<<((i==9)?"":" ");
			for(int i=5;i>=0;--i)cout<<" "<<i;
			for(int i=1;i<=to;++i)cout<<" "<<i;
		}
		cout<<"\n";
	}
	return 0;
}