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

# define INF ((int)(1<<30))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12

template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,-1,1,0 }, dy[4] = { 1,0,0,-1 };

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int now, end;
		cin >> now >> end;
		vi ans;
		bool a = false;
		if (now > end&&now>5)
		{
			for (; now <= 9; now++)ans.push_back(now);
			now = 5; 
			for (; now >= 0; now--)
			{
				ans.push_back(now);
				if (now == end)break;
			}
			now = 1;
			if(now!=end)
			for (; now <= end; now++)
			{
				ans.push_back(now);
				if (now == end)break;
			}
		}
		else if (now > end)
		{
			for (; now >= end; now--)ans.push_back(now);
		}
		else
		{
			for (; now <= end; now++)ans.push_back(now);
		}
		for (int i = 0; i < ans.size(); i++)
		{
			cout << (i ? " " : "") << ans[i];
		}
		cout << endl;

	}
}

C++: #include <cstdio>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int ls = 15;
int l[] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
int main(void){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    int a,b;
    cin >> a >> b;
    if(0 < a && a <= 5 && a > b){
      a = ls - a;
    }

    for(int j = a; l[j%ls] != b; j++){
      cout << l[j%ls] << ' ';
    }
    cout << b << endl;
  }
}

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(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;
	}
      }
    }
  }
  return 0;
}

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

void solve(int s, int g){
	if(s <= 5){
		if(s < g){
			for(int i = s; i <= g; i++){
				printf("%d", i);
				if(i != g)	printf(" ");
			}
			printf("\n");
		}else{
			for(int i = s; i >= g; i--){
				printf("%d", i);
				if(i != g - 1)	printf(" ");
			}
			printf("\n");
		}
	}else if(g <= 5){
		for(int i = s; i <= 9; i++){
			printf("%d ", i);
		}
		for(int i = 5; i >= g; i--){
			printf("%d", i);
			if(i != g - 1)	printf(" ");
		}
		printf("\n");
	}else{
		if(s < g){
			for(int i = s; i <= g; i++){
				printf("%d", i);
				if(i != g )	printf(" ");
			}
			printf("\n");
		}else{
			for(int i = s; i <= 9; i++){
				printf("%d ", i);
			}
			for(int i = 5; i <= g; i++){
				printf("%d", i);
				if(i != g)	printf(" ");
			}
			printf("\n");
		}
	}
}

int main(void){
	int n, s, g;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d %d", &s, &g);
		solve(s, g);
	}
  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int F = 9;

int main()
{
    int s, g, n; cin >> n;
    REP(n)
    {
        vector<int> ans;
        cin >> s >> g;
        if(s <= 5 && g <= 5)
        {
            if( s < g)for(int j = s;j <= g;j++) ans.push_back(j);

            if(s > g)for(int j = s; j >= g;j--) ans.push_back(j);
        }
        if( s>5 && g <= 5)
        {
            for(int j = s; j<= F;j++) ans.push_back(j);
            for(int j = 5; j >= g;j--)ans.push_back(j);
        }
        if(s <= 5 && g> 5)
            for(int j = s; j<=g;j++) ans.push_back(j);
    
        if(s >5 && g > 5)
        {
            if( s < g)for(int j = s; j<=g;j++) ans.push_back(j);
            if( s > g)
            {
                for(int j = s; j<=F;j++) ans.push_back(j);
                for(int j = 5; j>=0;j--) ans.push_back(j);
                for(int j = 0;j <=g;j++) ans.push_back(j);
            }
        }

        rep(j,ans.size()){ cout << ans[j]; if(i == ans.size()-1) break; cout << " ";}
        cout << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
  int i, j, n, before, after;
  vector<int> line, way;
  vector<int>::iterator iter1, iter2;

  for(i=0; i<10; ++i)
    line.push_back(i);
  for(i=5; i>=0; --i)
    line.push_back(i);

  cin >> n;

  for(i=0; i<n; ++i){
    cin >> before >> after;
    
    if(before < after){
      iter1 = find(line.begin(), line.begin()+10, before);
      iter2 = find(iter1, line.begin()+10, after);
    }else{
      iter1 = find(line.begin()+6, line.end(), before);
      iter2 = find(iter1, line.end(), after);
    }
    copy(iter1, iter2+1, back_inserter(way));

    for(j=0; j<way.size()-1; ++j)
      cout << way[j] << " ";
    cout << way[way.size()-1] << endl;

    way.clear();
  }

  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int s[16] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
int s2[10] = {5,6,7,8,9,5,6,7,8,9};
int main(void){
  int n;
  cin>>n;
  while(n--){
    int a,b;
    vector<int> ans;
    cin>>a>>b;
    bool f=false;
    REP(i,16){
      if(s[i]==a){
        if(!f)f=true;
        else ans.clear();
      }
      if(f) ans.push_back(s[i]);
      if(f&&s[i]==b) break;
    }
    if(b>=5&&a>b){
      ans.clear();
      f = false;
      REP(i,10){
        if(s2[i]==a){
          if(!f)f=true;
          else ans.clear();
        }
        if(f) ans.push_back(s2[i]);
        if(f&&s2[i]==b) break;
      }
    }
    REP(i,ans.size()){
      if(i) cout<<" ";
      cout<<ans[i];
    }
    cout<<endl;
  }
  return 0;
}