Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

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<queue>
using namespace std;
int main()
{
	int n;

	cin >> n;
	for(int i = 0; i < n; ++i){
		int st, ed;
		queue<int> q;
		cin>>st>>ed;

		if( st == ed ){
			cout << "\n";
			continue;
		}

		if( ed <= 5 ){
			if( st > 5 ){
				for(int i = st; i <= 9; ++i) q.push( i ); 
				for(int i = 5; i >= ed; --i) q.push( i );
			}else{
				if( st > ed )
					for(int i = st; i >= ed; --i) q.push( i );
				else
					for(int i = st; i <= ed; ++i) q.push( i );
			}
		}else{
			if( st < ed ){
				for(int i = st; i <= ed; ++i) q.push( i );
			}else{
				for(int i = st; i <= 9; ++i) q.push( i );
				for(int i = 5; i <= ed; ++i) q.push( i );
			}
		}
		cout << q.front();
		q.pop();
		while( !q.empty() ){
			cout << ' ' << q.front();
			q.pop();
		}
		cout << '\n';
	}
	return 0;
}

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

void s_out(string s){
	for(int i=0;i<s.size();i++){
		cout<<s[i];
		if(i+1==s.size())cout<<"\n";
		else cout<<" ";
	}
}

string l="012345678954321";
int t[10][2]={{0,0},{1,14},{2,13},{3,12},{4,11},{5,10},{6,6},{7,7},{8,8},{9,9}};

int main(){
	
	int n;
	cin>>n;
	for(;n;n--){
		string s1="",s2="";
		int a1=0,a2=0;
		
		char s,g;
		cin>>s>>g;
		int st;
		
		st=t[s-'0'][0];
		while(1){
			s1+=l[st];
			if(l[st]==g)break;
			a1++;
			st++;
			if(st>14)st=0;
		}
		
		st=t[s-'0'][1];
		while(1){
			s2+=l[st];
			if(l[st]==g)break;
			a2++;
			st++;
			if(st>14)st=0;
		}
		
		
		
		
		if(a1<a2)s_out(s1);
		else s_out(s2);
	}
	
	
	return 0;
}

C++: #include <bits/stdc++.h>

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

int main()
{
  rep(i, in()){
    int f, t;
    f = in();
    t = in();
    vector<int> way;
    if (f < t){
      for (int i = f; i <= t; i++){
        way.push_back(i);
      }
    }
    else if (f <= 5){
      for (int i = f; i >= t; i--){
        way.push_back(i);
      }
    }
    else {
      for (int i = f; i <= 9; i++){
        way.push_back(i);
      }
      for (int i = 5; i >= t; i--){
        way.push_back(i);
      }
    }
    show(way, ' ');
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	string ans[10][10]={
	{
		"0",
		"0 1",
		"0 1 2",
		"0 1 2 3",
		"0 1 2 3 4",
		"0 1 2 3 4 5",
		"0 1 2 3 4 5 6",
		"0 1 2 3 4 5 6 7",
		"0 1 2 3 4 5 6 7 8",
		"0 1 2 3 4 5 6 7 8 9"
	},
	{
		"1 0",
		"1",
		"1 2",
		"1 2 3",
		"1 2 3 4",
		"1 2 3 4 5",
		"1 2 3 4 5 6",
		"1 2 3 4 5 6 7",
		"1 2 3 4 5 6 7 8",
		"1 2 3 4 5 6 7 8 9"
	},
	{
		"2 1 0",
		"2 1",
		"2",
		"2 3",
		"2 3 4",
		"2 3 4 5",
		"2 3 4 5 6",
		"2 3 4 5 6 7",
		"2 3 4 5 6 7 8",
		"2 3 4 5 6 7 8 9"
	},
	{
		"3 2 1 0",
		"3 2 1",
		"3 2",
		"3",
		"3 4",
		"3 4 5",
		"3 4 5 6",
		"3 4 5 6 7",
		"3 4 5 6 7 8",
		"3 4 5 6 7 8 9"
	},
	{
		"4 3 2 1 0",
		"4 3 2 1",
		"4 3 2",
		"4 3",
		"4",
		"4 5",
		"4 5 6",
		"4 5 6 7",
		"4 5 6 7 8",
		"4 5 6 7 8 9"
	},
	{
		"5 4 3 2 1 0",
		"5 4 3 2 1",
		"5 4 3 2",
		"5 4 3",
		"5 4",
		"5",
		"5 6",
		"5 6 7",
		"5 6 7 8",
		"5 6 7 8 9"
	},
	{
		"6 7 8 9 5 4 3 2 1 0",
		"6 7 8 9 5 4 3 2 1",
		"6 7 8 9 5 4 3 2",
		"6 7 8 9 5 4 3",
		"6 7 8 9 5 4",
		"6 7 8 9 5",
		"6",
		"6 7",
		"6 7 8",
		"6 7 8 9"
	},
	{
		"7 8 9 5 4 3 2 1 0",
		"7 8 9 5 4 3 2 1",
		"7 8 9 5 4 3 2",
		"7 8 9 5 4 3",
		"7 8 9 5 4",
		"7 8 9 5",
		"7 8 9 5 6",
		"7",
		"7 8",
		"7 8 9"
	},
	{
		"8 9 5 4 3 2 1 0",
		"8 9 5 4 3 2 1",
		"8 9 5 4 3 2",
		"8 9 5 4 3",
		"8 9 5 4",
		"8 9 5",
		"8 9 5 6",
		"8 9 5 6 7",
		"8",
		"8 9"
	},
	{
		"9 5 4 3 2 1 0",
		"9 5 4 3 2 1",
		"9 5 4 3 2",
		"9 5 4 3",
		"9 5 4",
		"9 5",
		"9 5 6",
		"9 5 6 7",
		"9 5 6 7 8",
		"9"
	}
};
	int n,a,b;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		cout<<ans[a][b]<<endl;
	}
	return 0;
}

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]<<" ";
                }
                cout<<a[m]<<endl;
              }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<<a[m]<<endl;
              }
        }
        return 0;
}

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

main(){
  int tcase; cin >> tcase;
  int s, t;
  for ( int i = 0; i < tcase; i++ ){
    vector<int> v;
    cin >> s >> t;
    if ( s < t ){
      for ( int i = s; i <= t; i++ ) v.push_back(i);
    } else {
      if ( s <= 5 ){
	for ( int i = s; i >= t; i--) v.push_back(i);
      } else {
	for ( int i = s; i <= 9; i++ ) v.push_back(i);
	for ( int i = 5; i >= t; i-- ) v.push_back(i);
      }
    }
    for ( int i = 0; i < v.size(); i++ ){
      if ( i) cout << " ";
      cout << v[i];
    }
    cout << endl;
  }
}

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(){
	queue<int> q;
	rep(i,10) q.push(i);
	rep(i,6) q.push(5-i);
	int n;
	cin>>n;
	rep(i,n){
		vint ans;
		int a,b;
		cin>>a>>b;
		// cout<<q.front()<<endl;
		rep(i,15){
			int t=q.front();
			q.push(t);
			q.pop();
			if(t==a){
				ans.clear();
				ans.PB(t);
			}
			else if(t==b){
				ans.PB(t);
				break;
			}
			else{
				ans.PB(t);
			}
		}
		rep(i,ans.size()){
			if(i) cout<<" ";
			cout<<ans[i];
		}
		cout<<endl;
	}
}