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 a=0,b,c,d,n,h=0,jo,ko,i,p[100]={0};
  cin >> n;
  for(i=0;i<n;i++){
    a=0;
    cin >> jo >> ko;
    h=0;
    while(jo!=ko){
      if(jo == 9 && ko == 5){
	p[h]=jo;
	h++;
	break;
      }
      if(jo == 0 && ko!=0){
	p[h]=jo;
	jo++;
	h++;
	a=0;
      }
      if(jo > ko && jo <6){
	p[h]=jo;
	jo--;
	h++;
      }
      if(jo > ko && jo>=6){
	if(jo <= 9){
	  p[h]=jo;
	  jo++;
	  h++;
	}
	if(jo > 9){
	  jo=5;
	  p[h]=jo;
	  jo--;
	  h++;
	  a=1;
	}
      }
      if(jo < ko && a!=1){
	p[h]=jo;
	jo++;
	h++;
      }
      if(jo < ko && a==1){
	p[h]=jo;
	jo--;
	h++;
      }
    }
    for(d=0;d<h;d++){
      cout << p[d] << " " ;
    }
    cout << ko << endl;
  }
}

C++: import java.util.Scanner;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Collections;

import java.util.Comparator;

class Main{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);

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

		int n = in.nextInt();
		for(int i = 0; i < n; i++){
			int s =in.nextInt(), e = in.nextInt();
			ArrayList<String> al = new ArrayList<String>();
			for(int j = 0; j < d.length; j++){
				StringBuilder sb = new StringBuilder();
				if(d[j] == s){
					for(int k = j; k < d.length; k++){
						if(k != j) sb.append(" ");
						sb.append((char)('0' + d[k]));
						if(d[k] == e){
							al.add(sb.toString());
							break;
						}
					}
				}
			}
			Collections.sort(al, new Comp());
			System.out.println(al.get(0));
		}
	}
}

class Comp implements Comparator<String>{
	public int compare(String a, String b){
		int l1 = a.length(), l2 = b.length();
		if(l1 > l2) return 1;
		else if (l1 == l2) return 0;
		else return -1;
	}
}

C++: #include <iostream>
using namespace std;
int main()
{
	int q;
	cin >> q;
	for(int i=0;i<q;i++)
	{
		int from,to;
		cin >> from >> to;
		if(from < to)
		{
			for(int j=from;j<to;j++)cout << j << ' ';
			cout << to << endl;
			continue;
		}
		if(from<=5)
		{
			for(int j=from;j>to;j--)cout << j <<  ' ';
			cout << to << endl;
		}
		else if(to>=5)
		{
			for(int j=from;j<=9;j++)cout << j << ' ';
			for(int j=5;j<to;j++)cout << j << ' ';
			cout << to << endl;
		}
		else
		{
			for(int j=from;j<=9;j++)cout << j << ' ';
			for(int j=5;j>to;j--)cout << j << ' ';
			cout << to << 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);
	if ( t <= 5 ){
	  for ( int i = 5; i >= t; i-- ) v.push_back(i);
	} else {
	  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>
using namespace std;

char stop[] ="0123456789543210";

void solve(int start,int goal) {
  int ans = 10000;int pos = 0;
  for(int i=0;i<16;i++) {
    if(stop[i] != start + '0') continue;
    //stop[i] == goal
    for(int j=i+1;j<16;j++) {
      if(stop[j] == goal + '0') {
        ans = min(ans,j-i);pos = i;
      }
    }
  }
  for(int i = pos;i<=pos + ans;i++) {
    cout << ( i==pos ? "":" ") << stop[i];
  }
  cout << endl;
}

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

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
template <class _Tv> inline string join(const _Tv &v,string sep=" "){
    ostringstream s;for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

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

vector<int> solve(int st, int ed){
    vector<int> r;
    int n = sizeof(tbl)/sizeof(tbl[0]);
    for(int i = 0; i < n*2; ++i){
        if(tbl[i%n] == st) r.clear();
        r.push_back(tbl[i%n]);
        if(tbl[i%n] == ed) break;
    }
    return r;
}

int main(){
    int n,a,b;
    cin >> n;
    while(cin >> a >> b){
        cout << join(solve(a,b)) << endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
using namespace std;
typedef long long ll;

int main(){
    int jun[]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int fr,to;
        scanf("%d%d",&fr,&to);
        int mi=INT_MAX,miat;
        for(int j=0;j<15;j++){
            if(jun[j]==fr){
                for(int k=0;k<15;k++){
                    if(jun[(j+k)%15]==to){
                        if(k<mi){
                            mi=k;
                            miat=j;
                            break;
                        }
                    }
                }
            }
        }
        for(int j=0;j<=mi-1;j++){
            printf("%d ",jun[(j+miat)%15]);
        }
        printf("%d\n",jun[(mi+miat)%15]);
    }
}

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

int main()
{
  int n;
  int s,g;
  int add;
  cin>>n;
  while(n-->0){
    cin>>s>>g;
    add=1;

    if(s<=g){
      cout<<s;
      while(s!=g){
	s+=add;
	cout<<" "<<s;
      }
    }else{
      if(s<=5)add=-1;
      cout<<s;
      while(s!=g){
	if(s==9){
	  s=6;
	  add=-1;
	}
	if(s==0){
	  s=0;
	  add=1;
	}
	s+=add;
	cout<<" "<<s;
      }
    }
    puts("");
  }
}