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>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;

bool G[10][10];

vector <int> solve( int a, int b )
{
    queue < vector <int> > Q;
    vector <int> S;
    S.push_back( a );
    Q.push( S );
    
    while ( Q.empty() == false )
    {
        vector <int> C = Q.front();
        Q.pop();
        int cur = *( C.end()-1 );

        if ( cur == b )
        {
            return C;
        }

        for ( int i = 0; i < 10; i++ )
        {
            if ( G[cur][i] && find( C.begin(), C.end(), i ) == C.end() )
            {
                C.push_back( i );
                Q.push( C );
                C.pop_back();
            }
        }
    }

    return vector <int>();
}

int main( void )
{
    memset( G, false, sizeof( G ) );
    G[0][1] = G[1][0] = true;
    G[1][2] = G[2][1] = true;
    G[2][3] = G[3][2] = true;
    G[3][4] = G[4][3] = true;
    G[4][5] = G[5][4] = true;
    G[5][6] = true;
    G[6][7] = true;
    G[7][8] = true;
    G[8][9] = true;
    G[9][5] = true;

    int n;
    cin >> n;

    for ( int i = 0; i < n; i++ )
    {
        int a, b;
        cin >> a >> b;
        vector <int> path = solve( a, b );
        cout << path.size() << endl;
        for ( vector <int> ::iterator it = path.begin(); it != path.end(); it++ )
        {
            cout << *it;
            if ( ( it + 1 ) != path.end() ) cout << " ";
            else cout << endl;
        }
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;


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

int ans[10][10];
int tmp[10][10];

int main(){
  for(int i=15;i>=0;i--){

    for(int a=0;a<15;a++){

      int from=A[a];
      int to=A[ (a+i)%15 ];
      
      ans[ from ][ to ]=i;
      tmp[ from ][ to ]=a;
    }
  }

  int tc;
  cin>>tc;

  for(int Tc=0;Tc<tc;Tc++){

    int from;
    int to;
    cin>>from>>to;

    for(int i=0;i<=ans[from][to];i++){
      if(i>0)cout<<' ';

      cout<< A[ (tmp[from][to]+i)%15 ];
    }
    cout<<endl;
    
  }
  
  return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF (1<20)
int G[20];
int search(int s,int f){
  if(s==-1) return INF;
  int count;
  for(int i=0;i<16;i++){
    int ind = (i+s)%16;
    //   printf("%d\n",G[ind]);
    if(G[ind] == f){
      count = i;
      break;
    }
  }
  return count;
}
void printans(int s,int f){
  for(int i=0;i<16;i++){
    int ind = (i+s)%16;
    printf("%d",G[ind]);
    if(G[ind] == f){
      break;
    }
    printf(" ");
  }
  puts("");
}
int main(){
  int n;
  for(int i=0;i<10;i++) G[i]=i;
  for(int i=10,j=5;i<16;i++,j--) G[i]=j;
  scanf("%d\n",&n);
  for(int i=0;i<n;i++){
    int s,f;
    scanf("%d %d",&s,&f);
    int count = 0;
    int st=-1;
    count = search(s,f);
    for(int i=10;i<16;i++){
      if(G[i]==s){ 
	st = i;
      }
    }
    if(st>0){
      if(count < search(st,f)){
	printans(s,f);
      }else{
	printans(st,f);
      }
    }else{
      printans(s,f);
    }
  }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <functional>
#include <iterator>
using namespace std;

const int INF = (int)1e9;
typedef pair<int, int> P;

struct Edge {
    int to, cost;
    Edge(int t, int c) : to(t), cost(c) { }
};

pair<int, vector<int> > dijkstra_with_route(const vector<vector<Edge> > &edges, const int from, const int to) {
    vector<int> dist(edges.size(), INF);
    vector<int> prev(edges.size(), -1);

    priority_queue<P, vector<P>, greater<P> > Q;
    Q.push(P(0, from));
    dist[from] = 0;

    while(!Q.empty()) {
        P p = Q.top(); Q.pop();
        int v = p.second;
        int d = p.first;
        if(v == to) break;
        if(d > dist[v]) continue;
        for(int i = 0; i < (int)edges[v].size(); i++) {
            Edge e = edges[v][i];
            int c = d + e.cost;
            if(c < dist[e.to]) {
                dist[e.to] = c;
                Q.push(P(c, e.to));
                prev[e.to] = v;
            }
        }
    }

    vector<int> res;
    int u = to;
    while(u != from) {
        res.push_back(u);
        u = prev[u];
    }
    res.push_back(from);
    reverse(res.begin(), res.end());
    return make_pair(dist[to], res);
}

int main() {
    vector<vector<Edge> > edges(10);
    edges[0].push_back(Edge(1, 1));
    edges[1].push_back(Edge(0, 1));
    edges[1].push_back(Edge(2, 1));
    edges[2].push_back(Edge(1, 1));
    edges[2].push_back(Edge(3, 1));
    edges[3].push_back(Edge(2, 1));
    edges[3].push_back(Edge(4, 1));
    edges[4].push_back(Edge(3, 1));
    edges[4].push_back(Edge(5, 1));
    edges[5].push_back(Edge(4, 1));
    edges[5].push_back(Edge(6, 1));
    edges[6].push_back(Edge(7, 1));
    edges[7].push_back(Edge(8, 1));
    edges[8].push_back(Edge(9, 1));
    edges[9].push_back(Edge(0, 1));

    int N; cin >> N;
    while(N--) {
        int from, to; cin >> from >> to;
        auto res = dijkstra_with_route(edges, from, to).second;
        for(int i = 0; i < (int)res.size() - 1; i++) {
            cout << res[i] << ' ';
        }
        cout << *res.rbegin() << endl;
    }
}

C++: #include <iostream>

using namespace std;

int main()
{
	int s, t, d, n;
	cin >> n;
	
	while(n--){
		cin >> s >> t;
		d = (t < s && s <= 5)? -1 : 1;
		while(t != s){
			cout << s << " ";
			s += d;
			if(s == 10){
				d = -1;
				s = 5;
			} else if(s == -1){
				d = 1;
				s = 1;
			}
		}
		cout << t << endl;
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i)
	{
		int start, goal;
		cin >> start >> goal;
		if(0 <= start && start <= 5)
		{
			if(0 <= goal && goal <= 5)
			{
				cout << start;
				if(start < goal)
				{
					for(int i = start + 1; i <= goal; ++i)
					{
						cout << " " << i;
					}
					cout << endl;
				}
				else
				{
					for(int i = start - 1; i >= goal; --i)
					{
						cout << " " << i;
					}
					cout << endl;
				}
			}
			else if(goal == 6 || goal == 7)
			{
				cout << start;
				for(int i = start + 1; i <= goal; ++i)
				{
					cout << " " << i;
				}
				cout << endl;
			}
			else if(goal == 8 || goal == 9)
			{
				cout << start;
				for(int i = start + 1; i <= 5; ++i)
				{
					cout << " " << i;
				}
				for(int i = 8; i <= goal; ++i)
				{
					cout << " " << i;
				}
				cout << endl;
			}
		}
		else
		{
			cout << start;
			for(int i = start + 1; i <= 9; ++i)
			{
				cout << " " << i;
				if(i == goal)
				{
					goto NEXT;
				}
			}
			if(goal <= 5)
			{
				for(int i = 5; i >= goal; --i)
				{
					cout << " " << i;
				}
			}
			else
			{
				for(int i = 5; i >= 0; --i)
				{
					cout << " " << i;
				}
				for(int i = 1; i <= goal; ++i)
				{
					cout << " " << i;
				}
			}
NEXT:
			cout << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}