Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

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;

void f(int a, int b){
	if( a < b ){
		for(int i=a ; i <= b ; i++ ){
			if( i != a )
				cout << " ";
			cout << i;
		}
	}else{
		for(int i=a ; i >= b ; i-- ){
			if( i != a )
				cout << " ";
			cout << i;
		}
	}
}

int main(){
	int n;
	cin >> n;
	for(int i=0 ; i < n ; i++ ){
		int a,b;
		cin >> a >> b;
		if( a <= 5 && b <= 5 ){
			f(a,b);
		}else{
			if( a <= 5 && b > 5 ){
				f(a,b);
			}else if( a > 5 && b <= 5 ){
				f(a,9);
				cout << " ";
				f(5,a);
			}else if( a > 5 && b > 5 ){
				if( a < b ){
					f(a,b);
				}else{
					f(a,9);
					cout << " ";
					f(5,0);
					cout << " ";
					f(1,b);
				}
			}
		}
		cout << endl;
	}
}

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(5, 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>
#include <vector>
using namespace std;

int main() {
	vector<int> v;

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

	int n;
	cin >> n;
	for(int t = 0; t < n; t++) {
		int s, g;
		vector<int> ret;
		ret.resize(64);
		cin >> s >> g;
		for(int i = 0;i < v.size(); i++) {
			if(s == v[i]) {
				vector<int> tmp;
				for(int j = i;; j++) {
					tmp.push_back(v[j % v.size()]);
					if(v[j % v.size()] == g)
						break;
				}
				if(tmp.size() < ret.size())
					ret = tmp;
			}
		}

		cout << ret[0];
		for(int i = 1; i < ret.size(); i++)
			cout << " " << ret[i];
		cout << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int c=0;c<n;c++){
    int a,b;
    cin>>a>>b;
    if(a<=5){
      for(int i=0;i<=abs(a-b);i++){
	if(i)cout<<" ";
	cout<<(a<b?a+i:a-i);
      }
      cout<<endl;
    }else{
      if(a<b){
	int f=0;
	for(int i=a;i<=9;i++){
	  if(i!=a)cout<<" ";
	  cout<<i;
	  if(i==b){
	    f=1;
	    break;
	  }
	}
	if(!f){
	  for(int i=5;i>=b;i--){
	    if(i!=5)cout<<" ";
	    cout<<i;
	  }
	}
	cout<<endl;
      }else{
	for(int i=a;i<=9;i++){
	  if(i!=a)cout<<" ";
	  cout<<i;
	}
	for(int i=-5;abs(i)!=b;i++){
	  cout<<" "<<abs(i);
	}
	cout<<" "<<b<<endl;
      }
    }
  }
  return 0;
}

C++: #include<stdio.h>

int main(){

int n,s,f;
int w;

//while(1){
scanf("%d",&n);

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

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

}
}printf("\n");
}

return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

vector<vector<int> > G{
    {1},{0,2},{1,3},{2,4},{3,5},{6,4},{7},{8},{9},{5}
};

void solve(int a, int b){
    queue<pair<int,int>> q;

    int prev[10], d[10];
    rep(i,10) d[i]=1e9;
    d[a]=0;
    q.push(make_pair(a,0));
    while(q.size()){
        pair<int,int> s=q.front(); q.pop();
        int v=s.first, dis=s.second;

        rep(i,G[v].size()){
            int e=G[v][i];
            if(d[e] > d[v]+1){
                prev[e]=v;
                d[e] = d[v]+1;
                q.push(make_pair(e,d[e]));
            }
        }
    }

    vector<int> ans{b};
    while(ans.back()!=a) ans.push_back(prev[ans.back()]);
    rep(i,ans.size()){
        cout << ans[ans.size()-1-i] << (i+1==ans.size() ? '\n' : ' ');
    }
}

int main(){
    // rep(i,10)rep(j,10){
    //     printf("%d %d :", i,j);
    //     solve(i,j);
    // }
    int n; cin>>n;
    rep(i,n){
        int a,b; cin>>a>>b;
        solve(a,b);
    }
}

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++)
			{
				if(j!=to)cout << j << ' ';
				else cout << j << endl;
			}
			continue;
		}
		if(from<=5)
		{
			for(int j=from;j>=to;j--)
			{
				if(j!=to)cout << j <<  ' ';
				else cout << j << endl;
			}
		}
		else if(from>5&&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;
}