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>
#include <cstdio>
#include <string>
using namespace std;

#define loop(i, n) for (int i = 0; i < n; i++)

int main()
{
    int d;
    cin >> d;
    for (int data = 0; data < d; data++) {
        int a, b;
        cin >> a >> b;
        if (a < b) {
            for (int i = a; i < b; i++) {
                cout << i << " ";
            }
            cout << b << endl;
        } else if (a >= 6) {
            for (int i = a; i < 10; i++) {
                cout << i << " ";
            }
            if (b <= 5) {
                for (int i = 5; i > b; i--) {
                    cout << i << " ";
                }
                cout << b << endl;
            } else {
                for (int i = 5; i >= 0; i--) {
                    cout << i << " ";
                }
                for (int i = 1; i < b; i++) {
                    cout << i << " ";
                }
                cout << b << endl;
            }
        } else {
            for (int i = a; i > b; i--) {
                cout << i << " ";
            }
            cout << b << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

int n, s, t;
int stops[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0};
vector<int> ss1, ss2;
bool flag1, flag2;

int main()
{
	cin >> n;

	REP(n)
	{
		cin >> s >> t;
		
		ss1.clear();
		ss2.clear();

		flag1 = flag2 = false;

		//printf("s = %d, t = %d\n", s, t);

		if (0 <= s && s <= 5)
		{
			for (int j=s; j<16; j++)
			{
				ss1.pb(stops[j]);
				if (stops[j] == t)
				{
					flag1 = true;
					break;
				}
			}
			for (int j=15-s; j<16; j++)
			{
				ss2.pb(stops[j]);
				if (stops[j] == t)
				{
					flag2 = true;
					break;
				}
			}
		} else {
			for (int j=s; j<16; j++)
			{
				ss1.pb(stops[j]);
				if (stops[j] == t)
				{
					flag1 = true;
					break;
				}
			}
		}

		//printf("ss1.size = %d, ss2.size = %d\n", ss1.size(), ss2.size());
		//printf("flag1 = %d, flag2 = %d\n", (flag1 ? 1 : 0), (flag2 ? 1 : 0));

		if (flag1 && flag2 && ss1.size() != 0 && ss2.size() != 0 && ss1.size() < ss2.size())
		{
			rep(j, ss1.size())
			{
				cout << ss1[j];
				cout << ((j != ss1.size() - 1) ? " " : "\n");
			}
		}
		if (flag1 && flag2 && ss1.size() != 0 && ss2.size() != 0 && ss2.size() < ss1.size())
		{
			rep(j, ss2.size())
			{
				cout << ss2[j];
				cout << ((j != ss2.size() - 1) ? " " : "\n");
			}
		}
		if (flag1 && ss1.size() != 0 && ss2.size() == 0)
		{
			rep(j, ss1.size())
			{
				cout << ss1[j];
				cout << ((j != ss1.size() - 1) ? " " : "\n");
			}
		}
		if (flag2 && ss1.size() == 0 && ss2.size() != 0)
		{
			rep(j, ss2.size())
			{
				cout << ss2[j];
				cout << ((j != ss2.size() - 1) ? " " : "\n");
			}
		}
		if (flag1 && ss1.size() == ss2.size())
		{
			rep(j, ss1.size())
			{
				cout << ss1[j];
				cout << ((j != ss1.size() - 1) ? " " : "\n");
			}
		}
		if (flag2 && ss1.size() == ss2.size())
		{
			rep(j, ss2.size())
			{
				cout << ss2[j];
				cout << ((j != ss2.size() - 1) ? " " : "\n");
			}
		}
		if (flag1 && !flag2)
		{
			rep(j, ss1.size())
			{
				cout << ss1[j];
				cout << ((j != ss1.size() - 1) ? " " : "\n");
			}
		}
		if (!flag1 && flag2)
		{
			rep(j, ss2.size())
			{
				cout << ss2[j];
				cout << ((j != ss2.size() - 1) ? " " : "\n");
			}
		}
	}
	
	return 0;
}

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

using namespace std;

int main(){
  int i, j, n, before, after;
  vector<int> line, way;
  vector<int>::iterator iter1, iter2;

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

  cin >> n;

  for(i=0; i<n; ++i){
    cin >> before >> after;
    
    if(before < after){
      iter1 = find(line.begin(), line.begin()+10, before);
      iter2 = find(iter1, line.begin()+10, after);
    }else{
      iter1 = find(line.begin()+6, line.end(), before);
      iter2 = find(iter1, line.end(), after);
    }
    copy(iter1, iter2+1, back_inserter(way));

    for(j=0; j<way.size()-1; ++j)
      cout << way[j] << " ";
    cout << way[way.size()-1] << endl;

    way.clear();
  }

  return 0;
}

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

int main(){
    int n;
    
    cin >> n;
    while(n--){
        int s,g;
        vector<int> v;
        
        cin >> s >> g;
        if(s < g){
            for(int i = s ; i <= g ; i++) v.push_back(i);
        }
        else if(s > g){
            if(s > 5){
                for(int i = s ; i <= 9 ; i++) v.push_back(i);
                if(g > 5){
                    for(int i = 5 ; i >= 0 ; i--) v.push_back(i);
                    for(int i = 1 ; i <= g ; i++) v.push_back(i);
                }
                else{
                    for(int i = 5 ; i >= g ; i--) v.push_back(i);
                }
            }
            else if(s <= 5){
                for(int i = s ; i >= g ; i--) v.push_back(i);
            }
        }
        
        for(int i = 0 ; i < v.size() ; i++){
            if(!i) cout << v[i];
            else cout << ' ' << v[i];
        }
        cout << endl;
    }
    
    return 0;
}

C++: #include<bits/stdc++.h>
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};
  cin>> n;
  while(n--) {
    int get, off;
    cin>> get>> off;
    int i;
    for((get<6 && get>off) ? i=(15-get):i=get; bus_stop[i]!=off; i++) {
      cout<< bus_stop[i]<< ' ';
    }
    cout<< off<< endl;
  }
}

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

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

int main(){
	int n,s,g,count,k,a;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> s >> g;
		count = 1000000000;
		for(int j = 0;j < 15;++j){
			if(busstop[j] == s){
				int tmp = 0;
				k = j;
				while(busstop[k] != g){
					++k;
					k%=15;
					++tmp;
				}
				if(tmp < count){
					count = tmp;
					a = j;
				}
			}
		}
		while(busstop[a] != g){
			cout << busstop[a++] << " ";
			a  %= 15;
		}
		cout << g << endl;
	}
	return 0;
}