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 <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;



int main()
{
  const int busstop[] = {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};
  const int bussize = sizeof(busstop) / sizeof(int);

  int n;
  while (cin >> n) {
    while (n--) {
      int a, b;
      cin >> a >> b;

      int s = 0;
      for (; s < bussize; ++s) {
	if (busstop[s] == a)
	  break;
      }

      vector<int> ans;
      for (int i = s; i < bussize; ++i) {
	ans.push_back(busstop[i]);
	if (busstop[i] == b)
	  break;
      }

      if (1 <= a && a <= 5 && b < a) {
	vector<int> rev;
	for (int i = s; i >= 0; --i) {
	rev.push_back(busstop[i]);
	if (busstop[i] == b)
	  break;
	}
	if (rev.size() < ans.size())
	  ans = rev;
      }

      for (int i = 0; i < ans.size()-1; ++i)
	cout << ans[i] << " ";
      cout << ans.back() << endl;
    }
  }
  return 0;
}

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;
					dir = false;
				}
				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 <string>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i,n) for (int i = 0; i < (n); ++i)


vector<int> R;
int main() {
    int s, g;
    string ans;

    rep(i, 10) {
        R.push_back(i);
    }
    for(int i=5; i>0; --i) {
        R.push_back(i);
    }
    int n;
    cin >> n;

    rep(re, n) {
        cin >> s >> g;
        bool start = false, goal = false;

        while (1) {
            for(int i=0; i<15; ++i) {
                if(start) {
                    ans += " ";
                    ans += to_string(R[i]);
                }

                if(R[i] == s) {
                    ans.clear();
                    ans += to_string(R[i]);
                    start = true;
                }

                if (R[i] == g && start) {
                    goal = true;
                    break;
                }
            }

            if (goal) break; //もし最後にたどり着いても終わっていなかったらまた最初に折り返す．
        }
        cout << ans << endl;
    }

}

C++: #include<iostream>
using namespace std;
int main(){
  int a=0,b,c,d,n,h=0,jo,ko,i,p[100]={0};
  cin >> n;
  for(i=0;i<n;i++){
    cin >> jo >> ko;
    h=0;
    while(jo!=ko){
      if(jo <= 5){
	if(jo == 0 && ko!=0){
	  p[h]=jo;
	  jo++;
	  h++;
	}
	if(jo<ko && jo!=0){
	  p[h]=jo;
	  jo++;
	  h++;
	}
	if(jo>ko){
	  p[h]=jo;
	  jo--;
	  h++;
	}
      }
      if(jo > 5){
	if(jo<ko){
	  p[h]=jo;
	  jo++;
	  h++;
	}
	if(jo>ko){
	  if(jo <= 9){
	    p[h]=jo;
	    jo++;
	    h++;
	  }
	  if(jo > 9 && ko < 5){
	    jo=5;
	    p[h]=jo;
	    jo--;
	    h++;
	  }
	  if(jo > 9 && ko > 5){
	    jo=5;
	    p[h]=jo;
	    jo++;
	    h++;
	  }
	  if(jo > 9 && ko == 5){
	    break;
	  }
	}
      }
    }
  
  for(d=0;d<h;d++){
    cout << p[d] << " " ;
  }
  cout << ko << endl;
}
}

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


string bus = "012345678954321012345678954321";
int start,end;

void solve(){
  if(start < end){
    for(int i = start; i <= end; i++){
      if(i != start) cout << " ";
      cout << bus[i];
    }
  }else{
    for(int i = 6;; i++){
      if(bus[i]-'0' == start){
	start =i;
	break;
      }
    }

    for(int i = start;;i++){
      if(i != start) cout << " ";
      cout << bus[i];
      if(bus[i] -'0' == end) break;
    }
  }
}

int main(){
  int in;
  cin >> in;
  for(int i = 0; i < in; i++){
    cin >> start >> end;
    solve();
    cout << endl;
  }
  return 0;
}

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

using namespace std;
string bus_stop = "012345678954321012345678954321";

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		char s, g;
		cin >> s >> g;
		string ans1, ans2;
		bool flag = false;
		int pos = 0;
		for(int i = 0; i < bus_stop.size(); ++i)
		{
			if(!flag && bus_stop[i] == s)
			{
				flag = true;
				pos = i;
			}
			if(flag)
			{
				ans1 += bus_stop[i];
				if(bus_stop[i] == g)
				{
					break;
				}
			}
		}
		flag = false;
		for(int i = pos + 1; i < bus_stop.size(); ++i)
		{
			if(bus_stop[i] == s)
			{
				flag = true;
			}
			if(flag)
			{
				ans2 += bus_stop[i];
				if(bus_stop[i] == g)
				{
					break;
				}
			}
		}
		if(ans1.size() < ans2.size())
		{
			cout << ans1[0];
			for(int i = 1; i < ans1.size(); ++i)
			{
				cout << " " << ans1[i];
			}
			cout << endl;
		}
		else
		{
			cout << ans2[0];
			for(int i = 1; i < ans2.size(); ++i)
			{
				cout << " " << ans2[i];
			}
			cout << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}