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 <vector>

using namespace std;

typedef vector<int> VI;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )

#define PB( n ) push_back( n )

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

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

	REP( dt, 0, t )
	{
		int a, b;
		cin >> a >> b;

		VI r, l;
		int i, j;

		i = a;
		for ( j = i; Stop[j] != b; j++ )
		{
			if ( 15 <= j )
			{
				j = 0;
			}

			r.PB( Stop[j] );
		}
		r.PB( Stop[j] );

		i = a;
		for ( j = i; Stop[j] != b; j-- )
		{			
			if ( j < 0 )
			{
				j = 14;
			}

			l.PB( Stop[j] );
		}
		l.PB( Stop[j] );

		VI res = ( l.size() < r.size() ? l : r );

		UREP( i, 0, res.size() )
		{
			cout << res[i] << ( i + 1 == res.size() ? '\n' : ' ' );
		}
	}

	return 0;
}

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 );
        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 <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int N = 10;
const int INF = 1e9;

int a, b;

void fr(int n, vector<int> &r, vector<P> &v){
  r.push_back(n);
  if(n == a) return ;
  fr(v[n].second, r, v);
}

int main() {
  vector<int> G[N];
  G[0].push_back(1);
  G[1].push_back(0); G[1].push_back(2);
  G[2].push_back(1); G[2].push_back(3);
  G[3].push_back(2); G[3].push_back(4);
  G[4].push_back(3); G[4].push_back(5);
  G[5].push_back(4); G[5].push_back(6); G[5].push_back(9);
  G[6].push_back(5); G[4].push_back(7);
  G[7].push_back(6); G[4].push_back(8);
  G[8].push_back(7); G[4].push_back(9);
  G[9].push_back(5); G[9].push_back(8);
  int T; cin >>T;
  REP(t, T){
    cin >>a >>b;
    queue<P> open;
    open.push(P(0, a));
    vector<P> closed(N, P(INF, INF));
    while(!open.empty()){
      P tmp = open.front(); open.pop();
      int c = tmp.first, n = tmp.second;
      REP(i, G[n].size()){
        int next = G[n][i];
        if(closed[next].first <= c + 1) continue;
        closed[next] = P(c + 1, n);
        open.push(P(c + 1, next));
      }
    }
    vector<int> r;
    fr(b, r, closed);
    REVERSE(r);
    REP(i, r.size()) cout <<r[i] <<(i + 1 == (int)r.size() ? "" : " "); cout <<endl;
  }


  return 0;
}

C++: #include <iostream>

using namespace std;

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

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

const std::string bstop = "0123456789543210";

int main()
{
	int n;
	std::cin >> n;
	while( n-- )
	{
		int s, e;
		std::cin >> s >> e;
		
		bool fl = false;
		std::string ans;
		for( int i = 0; i != bstop.size(); ++i )
		{
			if( fl )
			{
				ans += ' ';
				ans += bstop[i];
			}

			if( bstop[i] == s + '0' )
			{
				ans.clear();
				fl = true;
				ans = bstop[i];
			}

			if( fl && bstop[i] == e + '0' )
				break;
		}
		
		std::cout << ans << std::endl;
	}

	return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
string str = "0 1 2 3 4 5 6 7 8 9 5 4 3 2 1 0";
string getstr(char s, char g) {
	int i, j;
	for (i = 0; str[i] != s; i++);
	for (j = i; str[j] != g; j++)if (str[j] == s)i = j;
	return str.substr(i, j - i + 1);
}
signed main() {
	int n; cin >> n;
	while (n--) {
		char a, b; cin >> a >> b;
		cout << getstr(a, b) << endl;
	}
	return 0;
}