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
//------------------------------------------
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>(b);i--)
#define REP(i,n)  FOR(i,0,n)

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
//-------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define INF (1<<21)
#define VISITED 1
#define NOT_VISITED 0

//typedef
//-------------------------------------------
typedef long long ll;

int g[10][10];
int visited[10];
vector<int> result;

int s, d;

int dfs(int now, int cost) {
    visited[now] = VISITED;
    if (now == d) return cost;

    int test = 0;
    int tmp = INF;
    int mini = -1;
    REP(i, 10) {
        if(g[now][i] != INF && visited[i] == NOT_VISITED) {
            int r = dfs(i, cost + 1);
            if (tmp > r) {
                tmp = r;
                mini = i;
            }
        }
    }
    if (mini > 0) result.push_back(mini);

    return tmp;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i, 10) REP(j, 10) g[i][j] = INF;
    g[0][1] = 1, g[1][0] = 1;
    g[1][2] = 1, g[2][1] = 1;
    g[2][3] = 1, g[3][2] = 1;
    g[3][4] = 1, g[4][3] = 1;
    g[4][5] = 1, g[5][4] = 1;
    g[5][6] = 1, g[6][7] = 1, g[7][8] = 1, g[8][9] = 1, g[9][5] = 1;

    int n;
    cin >> n;
    REP(j, n) {
        REP(i, 10) visited[i] = NOT_VISITED;
        if (!n) return 0;
        cin >> s >> d;
        result.clear();
        dfs(s, 0);
        reverse(result.begin(), result.end());
        cout << s << " ";
        for (auto itr = result.begin(); itr != result.end(); ++itr) {
            cout << *itr << " ";
        }
        cout << endl;
    }
    return 0;
}

C++: // 2011/03/22 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int bus[16];
	bus[0]  = 0;
	bus[1]  = 1;
	bus[2]  = 2;
	bus[3]  = 3;
	bus[4]  = 4;
	bus[5]  = 5;
	bus[6]  = 6;
	bus[7]  = 7;
	bus[8]  = 8;
	bus[9]  = 9;
	bus[10] = 5;
	bus[11] = 4;
	bus[12] = 3;
	bus[13] = 2;
	bus[14] = 1;
	bus[15] = 0;

	int n;
	cin >> n;

	for(int i=0; i<n; i++){
		int a, b;
		cin >> a >> b;

		if(a==1&&b<1)
			a = 14;
		if(a==2&&b<2)
			a = 13;
		if(a==3&&b<3)
			a = 12;
		if(a==4&&b<4)
			a = 11;
		if(a==5&&b<5)
			a = 10;

		cout << bus[a];
		do{
			a++;
			cout << ' ' << bus[a];
		}while(bus[a]!=b);
		cout << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
	int n,s,e,r[15]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
	cin >> n;
	for (;n>0;n--) {
     cin >> s >> e;
	 if (s>e && s<6) s=15-s;
	 while(true) { 
		 cout << r[s];
		 if (r[s]==e) {cout << endl; break;}
		 cout << ' ';
		 s=(s+1) % 15;
	 }
	}
	return 0;
}

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

//a->bまでangleの方向ではじめたときのルート
//angle: 1 -> right -1 -> left
std::vector<int> walk(int a, int b, int angle){
	std::vector<int> res;
	res.push_back(a);
	while(a != b){
		if(a == 9){
			a = 5;
			angle = -1;
		}else if(a == 0 && angle == -1){
			a = 1;
			angle = 1;
		}else{
			a += angle;
		}

		res.push_back(a);
	}
	
	return res;
}

int main(){
	int n, angle, a, b;
	std::cin >> n;
	for(;n--;){
		std::cin >> a >> b;

		std::vector<int> lv = walk(a, b, -1),
			rv = walk(a, b, 1), &shortest_v = lv;
		//a >= 6のとき左方向からはじめられない
		if(a >= 6 || lv.size() > rv.size()){
			shortest_v = rv;
		}

		std::cout << shortest_v[0];
		for(int i=1;i<shortest_v.size();i++){
			std::cout << " " << shortest_v[i];
		}
		std::cout << "\n";
	}
}

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--) {
		int a, b; cin >> a >> b;
		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>

using namespace std;

main(){
  int n;
  while(cin >> n){
    for(int c=0;c<n;c++){
      int s, g;
      cin >> s >> g;
      int d;
      if(s<=5 && g<s){
	d=0;
      }else{
	d=1;
      }
      if(d==1){
	bool finish=false;
	for(int i=s;i<10;i++){
	  cout << i;
	  if(i==g){
	    finish=true;
	    break;
	  }
	  cout << ' ';
	}
	if(finish){
	  cout << endl;
	  continue;
	}
	if(g<=5){
	  for(int i=5;i>=0;i--){
	    cout << i;
	    if(i==g){
	      break;
	    }
	    cout << ' ';
	  }
	  cout << endl;
	}else{
	  for(int i=5;i<10;i++){
	    cout << i;
	    if(i==g) break;
	    cout << ' ';
	  }
	  cout << endl;
	}
      }else{
	for(int i=s;i>=0;i--){
	  cout << i;
	  if(i==g) break;
	  cout << ' ';
	}
	cout << endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int s[15] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};

int disp(int a, int b){
	for(int i = a;;i++){
		cout << s[i%15] << " ";
		if(s[i%15] == b){cout << endl;return 0;}
	}
	
	return 0;
}

int main(){
	int n, a, b;cin >> n;
	while(n--){
		cin >> a >> b;
		if(6 <= a && a <= 9)disp(a, b);
		else{
			disp(0 < b-a ? a : 15-a, b);
		}
	}
	return 0;
}