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>
using namespace std;
int main(){
	int s,t,n; cin>>n;
	while(n--){
		cin>>s>>t;
		if(s<t){
			while(s!=t)cout<<s++<<" ";
			cout<<t<<endl;
		}else{
			if(0<=t&&t<=5){
				while(s!=t){
					cout<<s<<" ";
					s=s>5?s>8?5:s+1:s-1;
				}
				cout<<t<<endl;
			}else{
				while(s!=t){
					cout<<s++<<" ";
					if(s==10){
						s=6;
						cout<<"5 4 3 2 1 0 1 2 3 4 5 ";
					}
				}
				cout<<t<<endl;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(void) {
  int N;
  int s, g, t;
  cin >> N;
  for(int a = 0 ; a < N ; a++) {
    cin >> s >> g;
    if(s < g) {
      for(int i = s ; i < g ; i++) {
	cout << i << ' ';
      }
      cout << g << endl;
    }
    else if(s > g) {
      for(int i = s ; i > g ; i--) {
	cout << i << ' ';
      }
      cout << g << endl;
    }
    else if(s == g) {
      cout << s << endl;
    }
  }
  return 0;
}

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

int N , a , b ;
int table[] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1} ;

void func(){
	vector<int> V1 ;
	vector<int> V2 ;
	
	for( int i=0 ; i<15 ; i++ ){
		if( table[i] == a && V1.size() ){
			for( int j=i ; ; j++ ){
				V2.push_back( table[j%15] ) ;
				if( table[j%15] == b ) break ;
			}
		}
		else if( table[i] == a ){
			for( int j=i ; ; j++ ){
				V1.push_back( table[j%15] ) ;
				if( table[j%15] == b ) break ;
			}
		}
	}
	
	if( V2.empty() || V1.size() <= V2.size() ){
		for( int i=0 ; i<V1.size() ; i++ ) cout << (i?" ":"") << V1[i] ;
		cout << endl ;
	}else {
		for( int i=0 ; i<V2.size() ; i++ ) cout << (i?" ":"") << V2[i] ;
		cout << endl ;
	}
}

int main(){
	
	cin >> N ;
	while( N-- ){
		cin >> a >> b ;
		func() ;
	}
	
return 0 ;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

string s = "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";
int n, start, goal;
string ans;

int main(){
	cin >> n;
	REP(i, n){
		cin >> start >> goal;
		bool f = 0;
		int lb = 0, ub = 0;
		REP(i, s.size()){
			string t;
			if (s[i] - '0' == start){
				lb = i;
				f = 1;
			}
			if (f&&s[i] - '0' == goal){
				ub = i;
				//cout << lb << " " << ub << endl;
				t = s.substr(lb, ub - lb+1);
				if (ans.empty())ans = t;
				else{
					if (ans.size() > t.size())ans = t;
				}
			}
		}
		cout << ans << endl;
		ans.clear();
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,b;
    cin>>n;
    for (int i=0;i<n;i++) {
        cin>>a>>b;
        if (a<b) {
            for (int j=a;j<b+1;j++) {
                if (j==b) {
                    cout<<j<<endl;
                } else {
                    cout<<j<<" ";
                }
            }
        } else {    //a>b
            if (a<=5&&b<=5) {
                for (int k=a;k>=b;k--) {
                    if (k==b) {
                        cout<<k<<endl;
                    } else {
                        cout<<k<<" ";
                    }
                }
            } else if (b<=5) {
                for (int l=a;l<=9;l++) {
                    cout<<l<<" ";
                }
                for (int m=5;m>=b;m--) {
                    if (m==b) {
                        cout<<m<<endl;
                    } else {
                        cout<<m<<" ";
                    }
                }
            } else {
                for (int p=a;p<=9;p++) {
                    cout<<p<<" ";
                }
                for (int q=5;q>=0;q--) {
                    cout<<q<<" ";
                }
                for (int r=1;r<=b;r++) {
                    if (r==b) {
                        cout<<r<<endl;
                    } else {
                        cout<<r<<" ";
                    }
                }
            }
        }
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
string a="6 7 8 9 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 5 4 3 2";
main(){
  int n,s,t,i,j;
  cin>>n;
  while(n--){
    cin>>s>>t;
    for(i=0;s!=a[i]-'0';i++);
    for(j=i;t!=a[j]-'0';j++)if(a[j]-'0'==s)i=j;
    cout<<a.substr(i,j-i+1)<<endl;
  }
}

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);
			}
			printf("%d\n", g);
		}else{
			for(int i = s; i > g; i--){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}
	}else{
		if(s < g){
			for(int i = s; i < g; i++){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}else if(g <= 5){
			for(int i = s; i <= 9; i++){
				printf("%d ", i);
			}
			for(int i = 5; i > g; i--){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}else{
			for(int i = s; i <= 9; i++){
				printf("%d ", i);
			}
			for(int i = 5; i > 0; i--){
				printf("%d ", i);
			}
			for(int i = 0; i < g; i++){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}
	}
}

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<cstdio>

int n,m,l,k;

void solve(int p, int d){

  if(p == m){
    printf("%d\n",p);
    return;
  }

  printf("%d ", p);

  if(p == 9) solve(5, 0);
  else if(!p || d) solve(p+1, 1);
  else solve(p-1, 0);

}

int main(){

  scanf("%d", &l);

  while( l-- ){

    scanf("%d %d",&n, &m);

    if(n == 9 || (n < 6 && n > m)) k = 0;
    else k = 1;
    
    solve(n, k);

  }

}

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

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

int main() {
  
  int n, s, t;
  cin >> n;
  
  rep(i,n) {
    cin >> s >> t;
    if(s <= 5) {
      if(s < t) {
	cout << s;
	for(int j=s+1; j<=t; j++) cout << " " << j;
	cout << endl;
      }
      if(s > t) {
	cout << s;
	for(int j=s-1; j>=t; j--) cout << " " << j;
	cout << endl;
      }
    }
    else {
      if(t <= 5) {
	for(int j=s; j<10; j++) cout << j << " ";
	s=5;
	cout << s;
	for(int j=s-1; j>=t; j--) cout << " " << j;
	cout << endl;
      } else if(s < t) {
	cout << s;
	for(int j=s+1; j<=t; j++) cout << " " << j;
      } else {
	for(int j=s; j<10; j++) cout << j << " ";
	cout << "5 4 3 2 1 0 1 2 3 4 5";
	for(int j=6; j<=t; j++) cout << " " << j;
	cout << endl;
      }
    }
  }
  
  return 0;
}