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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	
	int n;
	cin>>n;
	rep(j,n){
		// if(k==l) continue;
		vint ans;
		int a,b;
		// cout<<a<<" -> "<<b<<endl;
		cin>>a>>b;
		// cout<<q.front()<<endl;
		queue<int> q;
		rep(i,10) q.push(i);
		rep(i,5) q.push(5-i);

		rep(i,30){
			int t=q.front();
			q.push(t);
			q.pop();
			if(t==a){
				ans.clear();
				ans.PB(t);
			}
			else if(t==b&&ans.size()&&ans[0]==a){
				ans.PB(t);
				break;
			}
			else{
				ans.PB(t);
			}
		}
		rep(i,ans.size()){
			if(i) cout<<" ";
			cout<<ans[i];
		}
		cout<<endl;
	}
}

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

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

int main() {
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    int s, g; cin >> s >> g;
    for(int j = 0; j < 15; j++) {
      if(j < 9 && s < 6 && g < 6 && s > g) j += 9;
      if(s == stop[j]) {
        for(int k = 0; k < 15; k++) {
          int num = (j+k)%15;
          cout << stop[num];
          if(stop[num] != g) cout << ' ';
          else {
              cout << endl;
              break;
          }
        }
      }
    if(s < 6 && s < g && j > 5) break;
    }
  }
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<queue>
#include<map>
#define P pair<int,int>
using namespace std;

int main() {
	int bus[] = { 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 };
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		int c, d;
		scanf("%d%d", &c, &d);
		vector<int>l(100);
		for (int e = 0; e < 14; e++) {
			if (bus[e] == c) {
				vector<int>f;
				for (int g = e; g < 30; g++) {
					f.push_back(bus[g]);
					if (bus[g] == d)break;
				}
				if (f.size() < l.size())l = f;
			}
		}
		for (int x = 0; x < l.size(); x++) {
			if (x)printf(" ");
			printf("%d", l[x]);
		}
		puts("");
	}
}

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

void solve(int f,int t) {
  bool r = false;
  if(f < t) {
    for(int i=0;i< t - f + 1;i++) {
      if(r) cout << " ";
      cout << f + i;
      r = true;
    }
    cout << endl;
    return;
  }

  else if(f > t) {
    if(f >= 6) {
      for(int i=0;i < 9 - f + 1;i++) {
        if(r) cout << " ";
        cout << f + i;
        r = true;
      }
      f = 5;
    }
    if(t == 5) {
      cout << 5 << endl;
      return;
    }
    for(int i=0;i< f - t + 1;i++) {
      if(r) cout << " ";
      cout << f - i;
      r = true;
    }
    cout << endl;
    return;
  }

  else if(f == t) {
    cout << f << endl;
    return;
  }
}

int main() {
  int n,f,t;
  cin >> n;
  for(int i=0;i<n;i++) {
    cin >> f >> t;
    solve(f,t);
  }
}

C++: //06
#include<iostream>

using namespace std;

int main(){
  int n;
  cin>>n;
  while(n--){
    int s,t;
    cin>>s>>t;
    if(s<=5){
      int d=((t>s)?1:-1);
      for(;;){
	cout<<s<<((s==t)?'\n':' ');
	if(s==t)break;
	s+=d;
      }
    }else if(0&&t>=5){
      for(;;){
	cout<<s<<((s==t)?'\n':' ');
	if(s==t)break;
	s=((s-5)+1)%5+5;
      }
    }else{
      int d=1;
      for(;;){
	cout<<s<<((s==t)?'\n':' ');
	if(s==t)break;
	s+=d;
	if(s==10){
	  s=5;
	  d=-1;
	}else if(s==-1){
	  s=1;
	  d=1;
	}
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int N = 10;
const int INF = 1e9;

int a, b;

void fr(int n, vector<int> &r, vector<P> &v){
  r.push_back(n);
  if(n == a) return ;
  fr(v[n].second, r, v);
}

int main() {
  vector<int> G[N];
  G[0].push_back(1);
  G[1].push_back(0); G[1].push_back(2);
  G[2].push_back(1); G[2].push_back(3);
  G[3].push_back(2); G[3].push_back(4);
  G[4].push_back(3); G[4].push_back(5);
  G[5].push_back(4); G[5].push_back(6); G[5].push_back(9);
  G[6].push_back(5); G[6].push_back(7);
  G[7].push_back(6); G[7].push_back(8);
  G[8].push_back(7); G[8].push_back(9);
  G[9].push_back(5); G[9].push_back(8);
  int T; cin >>T;
  REP(t, T){
    cin >>a >>b;
    queue<P> open;
    open.push(P(0, a));
    vector<P> closed(N, P(INF, INF));
    closed[a] = P(0, -1);
    while(!open.empty()){
      P tmp = open.front(); open.pop();
      int c = tmp.first, n = tmp.second;
      REP(i, G[n].size()){
        int next = G[n][i];
        if(closed[next].first <= c + 1) continue;
        closed[next] = P(c + 1, n);
        open.push(P(c + 1, next));
      }
    }
    //REP(i, N) cout <<i <<": " <<closed[i].first <<", " <<closed[i].second <<endl;
    vector<int> r;
    fr(b, r, closed);
    REVERSE(r);
    REP(i, r.size()) cout <<r[i] <<(i + 1 == (int)r.size() ? "" : " "); cout <<endl;
  }


  return 0;
}