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 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 << endl;
				else cout << j << ' ';
			}
			continue;
		}
		if(from<=5)
		{
			for(int j=from;j>=to;j--)
			{
				if(j!=to)cout << j << endl;
				else cout << j << ' ';
			}
		}
		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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

void f(int a,int b){
	cout<<a;
	if(a==b){cout<<endl;return;}
	if(5<=a&&a<=8){
		a++;
	}else if(a==9){
		a=5;
	}else if(a<b){
		a++;
	}else{
		a--;
	}
	cout<<" ";
	f(a,b);
}

int main() {
	int n=in();
	int a,b;
	int i;
	for(i=0;i<n;i++){
		cin>>a>>b;
		f(a,b);
	}
	return 0;
}

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

const int INT = -1;
int nextstop[10][2] = {{1,1},{0,2},{1,3},{2,4},{3,5},{4,6},{INT,7},{INT,8},{INT,9},{INT,5}};

int main(){
	int n,start,goal,a,k;
	vector<int> rout;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> start >> goal;
		for(int j = 0;j < 2;++j){
			k = j;
			a = start;
			rout.clear();
			while(a != goal){
				rout.push_back(a);
				a = nextstop[a][k];
				if(a == -1 || a == 0){
					break;
				}
				else if(j == 1 && rout[rout.size() - 1] == 9) k = 1 - k;
			}
			if(a == goal) {
				rout.push_back(a);
				break;
			}
		}
		for(int j = 0;j < rout.size();++j){
			if(j) cout << " ";
			cout << rout[j];
		}
		cout << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        int s,g;
        scanf("%d%d",&s,&g);
        int pos=s;
        printf("%d",s);
        bool flag=false;
        while(pos!=g){
            if(pos>5){
                if(pos==9)pos=5,flag=true;
                else pos++;
            }
            else if(pos==0){
                flag=false;
                pos++;
            }
            else{
                if(flag)pos--;
                else if(pos>g)pos--;
                else pos++;
            }
            printf(" %d",pos);
        }
        puts("");
        }
    return 0;
}

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

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

using namespace std;

int main()
{
	int n;
	cin >> n;

	int d[25] = {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};

	rep(i,n)
	{
		int a,b;
		cin >> a >> b;

		vector<int> v,v2;
		
		bool flag = false;
		for(int j=0;j<26;j++)
		{
			if(d[j] == a && !flag)
			{
				flag = true;
			}
			else if(d[j] == a && flag)
			{
				v.clear();
			}

			if(flag) v.push_back(d[j]);
			
			if(flag && d[j] == b)
			{
				flag = false;
				break;
			}
		}

		rep(j,v.size())
		{
			cout << v[j]  << " ";
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
  int n;
  int bus_stop[]={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};
  scanf("%d", &n);
  while(n--) {
    int get, off;
    scanf("%d %d", &get, &off);
    int i;
    for((get<6 && get>off) ? i=(15-get):i=get; bus_stop[i]!=off; i++) {
      printf("%d ", bus_stop[i]);
    }
    printf("%d\n", off);
  }
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<double,int> P;

static const double eps = 10e-9;

int main(){
	int n;
	scanf("%d",&n);
		for(int i=0;i<n;i++){
			int src,dst;
			scanf("%d %d",&src,&dst);
			if(src <= 5 && dst <= 5){
				if(src < dst){
					for(int j=src;j<=dst;j++){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
				else if(src > dst){
					for(int j=src;j>=dst;j--){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
			}
			else if(src >= 5 && dst >= 5){
				if(src < dst){
					for(int j=src;j<=dst;j++){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
				else if(src > dst){
					for(int j=src;j<=9;j++){
						printf("%d ",j);
					}

					if(dst == 5){
						cout << 5 << endl;
						continue;
					}
					for(int j=5;j>=0;j--){
						printf("%d ",j);
					}

					for(int j=1;j<=4;j++){
						printf("%d ",j);
					}

					for(int j=5;j<=dst;j++){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
			}

			else{
				if(src < dst){
					for(int j=src;j<=dst;j++){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
				else if(src > dst){
					for(int j=src;j<=9;j++){
						printf("%d ",j);
					}

					for(int j=5;j>=dst;j--){
						printf("%d%s",j,j == dst ? "\n" : " ");
					}
				}
			}

		}
}

C++: #include <iostream>

using namespace std;

void print_stops(int from, int to) {
    if (from <= 5 && to <= 5) {
        if (from < to) {
            for (int i = from; i <= to; i++) {
                cout << i << ' ';
            }
        } else {
            for (int i = from; i >= to; i--) {
                cout << i << ' ';
            }
        }
    } else if (from <= 5 && 6 <= to && to <= 9) {
        for (int i = from; i <= to; i++) {
            cout << i << ' ';
        }
    } else if (6 <= from && from <= 9 && to <= 5) {
        for (int i = from; i <= 9; i++) {
            cout << i << ' ';
        }
        for (int i = 5; to <= i; i--) {
            cout << i << ' ';
        }
    } else if (6 <= from && from <= 9 && 6 <= to && to <= 9) {
        if (from < to) {
            for (int i = from; i <= to; i++) {
                cout << i << ' ';
            }
        } else {
            for (int i = from; i <= 9; i++) {
                cout << i << ' ';
            }
            for (int i = 5; 0 <= i; i--) {
                cout << i << ' ';
            }
            for (int i = 1; i <= 5; i++) {
                cout << i << ' ';
            }
            for (int i = 6; i <= to; i++) {
                cout << i << ' ';
            }
        }
    }
    cout << endl;
}

int main() {
    int n; cin >> n;
    while (n--) {
        int from, to;
        cin >> from >> to;
        print_stops(from, to);
    }
    return 0;
}