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<stdio.h>

int main(){

int n,s,f;
int w;

while(1){
scanf("%d",&n);if(n==0)break;

for(int i=0;i<n;i++)
scanf("%d %d",&s,&f);

if(s<=5){
 if(s<f){
for(int i=s;i<=f;i++)
{
if(i!=s)printf(" ");
printf("%d",i);
}
     }
else if(s>f){
for(int i=s;i>=f;i--)
{
if(i!=s)printf(" ");
printf("%d",i);
}
}

if(s>5){
 if(f>6){
for(int i=s;i<=f;i++)
{
if(i!=s)printf(" ");
printf("%d",i);
}
}
 if(f<=5){
for(int i=s;i<=9;i++)
{
if(i!=s)printf(" ");
printf("%d",i);
}

for(int i=5;i>=f;i--)
{
if(i!=5)printf(" ");
printf("%d",i);
}

}
}

return 0;
}

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

using namespace std;

int main()
{
    int n;
    
    cin >> n;
    for (int i = 0; i < n; i++) {
        int s, e;

        cin >> s >> e;
        if (s <= 5) {
            if (s < e) {
                while (s != e) 
                    printf("%d ", s++);
                printf("%d\n", e);
            }
            else {
                while (s != e)
                    printf("%d ", s--);
                printf("%d\n", e);
            }
        }
        else if (s < e) {
            while (s < e) 
                printf("%d ", s++);
            printf("%d\n", e);
        }
        else if (e < s) {
            while (s != 5) {
                printf("%d ", s);
                s = (s + 1) - ((s + 1) / 10) * 5;
            }

            if (e == 5) 
                printf("5\n");
            else {
                printf("5 ");

                s--;
                while (s != e && s != 0)
                    printf("%d ", s--);
                if (s == e)
                    printf("%d\n", e);
                else if (e == 0) {
                    printf("0\n");
                    break;
                }
                else {
                    while (s != e)
                        printf("%d ", s++);
                    printf("%d\n", e);
                }
            }
        }
    }

    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	char s[]="012345678954321012345678";
	int len=24;

	int n;	cin>>n;
	while(n--){
		int start,goal;	cin>>start>>goal;
		int ans=100,ans_st;
		for(int i=0;i<len;i++){
			if(s[i]!=start+'0')	continue;
			for(int j=i+1;j<len;j++){
				if(s[j]==goal+'0'){
					if(ans>j-i)	ans=j-i,ans_st=i;
				}
			}
		}
		for(int i=ans_st;;i++){
			cout<<(i==ans_st?"":" ")<<s[i];
			if(s[i]==goal+'0')	break;
		}
		cout<<endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int num[]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
    for(int i=0,x,y;i<n;i++){
        cin>>x>>y;
        if(x<6&&y<6&&y-x>0){
            cout<<num[x];
            for(int j=x+1;j<=y;j++)cout<<" "<<num[j];
            cout<<endl;
        }
        else if(x<6&&y<6){
            cout<<num[15-x];
            for(int j=16-x;j<16-y;j++)cout<<" "<<num[j];
            cout<<endl;
        }
        else{
            cout<<num[x];
            for(int j=x+1;num[j-1]!=y;j++){
                if(j==16)j=1;
                cout<<" "<<num[j];
            }
            cout<<endl;
        }
    }
}

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];
                } else{if(y<=5){
		    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];
	            
                    }else {
                       for(int j=0;j<16;j++)
                            if(a[j]==x) l=j;
                       for(int p=l;p<=15;p++)
		            cout<<a[p]<<" ";
                       for(int k=0;k<16;k++)
			    if(a[k]==y) m=k;
                       for(int q=1;q<m;q++)
		           cout<<a[q]<<" ";                       
                        cout<<a[m];
                    }              
                 }
                 cout<<endl;
        }
        return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct Edge{
	int src,dst;
	Edge(){}
	Edge(int s,int d):src(s),dst(d){}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void solve(Graph& g,int begin,int end)
{
	int size=g.size();
	vi prev(size,-1);
	queue<Edge> q;
	q.push(Edge(-2,begin));
	while(q.size()){
		Edge e=q.front(); q.pop();
		if(prev[e.dst]!=-1) continue;
		prev[e.dst]=e.src;
		foreach(it,g[e.dst])
			q.push(*it);
	}
	vi res;
	for(int i=end;i>=0;i=prev[i])
		res.push_back(i);
	reverse(allof(res));
	//printf("%d->%d: ",begin,end);
	rep(i,res.size())
		printf("%d%c",res[i],i==res.size()-1?'\n':' ');
}

int main()
{
	Graph g(10);
	int src[]={0,1,1,2,2,3,3,4,4,5,5,6,7,8,9};
	int dst[]={1,0,2,1,3,2,4,3,5,4,6,7,8,9,5};
	rep(i,sizeof(src)/sizeof(src[0]))
		g[src[i]].push_back(Edge(src[i],dst[i]));
	
	int n;
	cin>>n;
	rep(i,n){
		int begin,end;
		cin>>begin>>end;
		solve(g,begin,end);
	}
	
	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	const int stations[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};
	int n;
	scanf("%d", &n);
	rep(i, n){
		int s, g;
		scanf("%d%d", &s, &g);
		
		for(s = 5<s || s<g ? s : 15-s; stations[s] != stations[g]; s=(s+1)%15)
			printf("%d ", stations[s]);
		printf("%d\n", stations[g]);
	}
	return 0;
}