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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()


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

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

int main()
{
	int n;
	
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		
		int l_roote[16] = {a};
		int l = 0;
		if (a < 1 || a > 5){
			l = INT_MAX;
		}
		else {
			int p = a;
			int angle = -1;
			while (p != b){
				p += angle;
				
				if (p == -1){
					p = 1;
					angle = 1;
				}
				else if (p == 10){
					p = 5;
					angle = -1;
				}
				
				l_roote[++l] = p;
			}
		}
		
		int r_roote[16] = {a};
		int r = 0;
		
			int p = a;
			int angle = 1;
			while (p != b){
				p += angle;
				
				if (p == -1){
					p = 1;
					angle = 1;
				}
				else if (p == 10){
					p = 5;
					angle = -1;
				}
				
				r_roote[++r] = p;
			}
		
		if (l < r){
			for (int j = 0; j <= l; j++){
				if (j != 0){
					printf(" ");
				}
				printf("%d", l_roote[j]);
			}
		}
		else {
			for (int j = 0; j <= r; j++){
				if (j != 0){
					printf(" ");
				}
				printf("%d", r_roote[j]);
			}
		}
		puts("");
	}
	
	return 0;
}

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

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    int N;
    cin >> N;
    for (;N--;) {
        int src, dst;
        cin >> src >> dst;

        if (src < dst) {
            cout << src;
            for (int j = src+1; j <= dst; ++j) {
                cout << ' ' << j;
            }
            cout << endl;
        } else {
            cout << src;
            if (src <= 5) {
                for (int j = src-1; j >= dst; --j) {
                    cout << ' ' << j;
                }
            } else {
                for (int j = src+1; j <= 9; ++j) {
                    cout << ' ' << j;
                }
                if (dst <= 5) {
                    for (int j = 5; j >= dst; --j) {
                        cout << ' ' << j;
                    }
                } else {
                    for (int j = 5; j <= dst; ++j) {
                        cout << ' ' << j;
                    }
                }
            }
            cout << endl;
        }

    }

    return 0;
}

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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1e18+1;

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

	while ( n-- ) {
		int a, b;
		cin >> a >> b;
		bool flag = a < b;
		while ( a != b ) {
			cout << a << " ";
			if ( flag ) {
				if ( a == 9 ) {
					a = 5;
					flag = false;
				}
				else a++;
			} else {
				if ( a == 0 ) {
					a = 1;
					flag = true;
				} else if ( a == 9 ) {
					a = 5;
				} else {
					a--;
				}
			}
		}
		cout << b << endl;
	}
	return 0;
}

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

int main()
{
    char stop[] = 
    {'0','1','2','3','4','5','6','7','8','9','5','4','3','2','1'};
    
	int N;
	cin >> N;
	while(N--)
	{
		string ans;
	    char start,last;
	    cin >> start >> last;

	    bool started=false, end=false;
		while(1)
		{
		    for(int i=0; i<15; i++)
		    {
				if(started)
				{
		        	ans+=" ";
					ans+=stop[i]; 
				}
				
		        if(stop[i]==start)
		        {
					ans.clear();
					ans+=stop[i];
		            started = true;
		        }
		        	
		        if(stop[i]==last && started)
		        {
					end=true;
		            break;
		        }
		    }
			if(end) break;
		}

		cout << ans << endl;
	}
}

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

const int stop[31] = {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,5,4,3,2,1,0};
int main()
{
	int n;
	cin >> n;
	for(int x=0;x<n;x++){
		int a,b;
		cin >> a >> b;
		bool flag = false;
			for(int i=0;i<31;i++){
				if(stop[i] == a){
					for(int k=i;k<31;k++){
						if(stop[k] == b)
							break;
						else if(stop[k] == a)
							i = k;
					}
					for(int j=i;j<31;j++){
						if(stop[j] != b)
							cout << stop[j] << " ";
						else{
							cout << stop[j] << endl;
							flag = true;
							break;
						}
					}
				}
				if(flag)
					break;
			}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int F = 9;

int main()
{
    int s, g, n; cin >> n;
    REP(n)
    {
        vector<int> ans;
        cin >> s >> g;
        if(s <= 5 && g <= 5)
        {
            if( s < g)for(int j = s;j <= g;j++) ans.push_back(j);

            if(s > g)for(int j = s; j >= g;j--) ans.push_back(j);
        }
        if( s>5 && g <= 5)//OK
        {
            for(int j = s; j<= F;j++) ans.push_back(j);
            for(int j = 5; j >= g;j--) ans.push_back(j);
        }
        if(s <= 5 && g> 5)//OK
            for(int j = s; j<=g;j++) ans.push_back(j);
    
        if(s >5 && g > 5)
        {
            if( s < g)for(int j = s; j<=g;j++) ans.push_back(j);
            if( s > g )
            {
                for(int j = s; j<=F;j++) ans.push_back(j);
                //for(int j = 5; j>=0;j--) ans.push_back(j);
                for(int j = 5;j <=g;j++) ans.push_back(j);
            }
        }

        rep(j,ans.size()){ cout << ans[j]; if(j == ans.size()-1) break; cout << " ";}
        cout << endl;
    }
    return 0;
}