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++: #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);
void up(int x,bool f) {
	bool dir = f;
	if (dir) {
		x++;
		if (x == 10) {
			x = 5;
		}
	}
}
signed main() {
	int n; cin >> n;
	while (n--) {
		int a, b; cin >> a >> b;
		int x = a;
		vector<int>v,w;
		bool dir = true;
		while (x!=b) {
			v.push_back(x);
			if (dir) {
				if (x == 9) {
					x = 5;
					dir = false;
				}
				else x++;
			}
			else {
				if (x == 0) {
					dir = true;
				}
				else x--;
			}
		}
		v.push_back(x);
		dir = false;
		x = a;
		while (x != b) {
			w.push_back(x);
			if (dir) {
				if (x == 9) {
					x = 5;
					dir = false;
				}
				else x++;
			}
			else {
				if (x == 0) {
					dir = true;
				}
				else x--;
			}
		}
		w.push_back(x);

		if (v.size() < w.size()) {
			rep(i, 0, v.size()) {
				if (i)cout << " ";
				cout << v[i];
			}
			cout << endl;
		}
		else {
			rep(i, 0, w.size()) {
				if (i)cout << " ";
				cout << w[i];
			}
			cout << endl;
		}

	}
	return 0;
}

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

int main(){
	int n,from,to,k,min,a;
	int toid[10][2] = { {1, 1}, {0, 2}, {1, 3}, {2, 4}, {3, 5}, {4, 6}, {7 ,7}, {8 ,8}, {9, 9}, {5, 5}};
	vector<int> res,tmp;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> from >> to;
		min = 100;
		res.clear();
		for(int j = 0;j < 2;++j){
			tmp.clear();
			k = j;
			a = from;
			while(a != to){
				tmp.push_back(a);
				if(a == 9 || a == 0) k = 1 - k;
				a = toid[a][k];
//				cout << a << endl;
			}
//			cout << j << endl;
			tmp.push_back(to);
			if(a == to && tmp.size() < min){
				min = tmp.size();
				res.swap(tmp);
			}
		}
		for(int j = 0;j < res.size();++j){
			if(j != 0) cout << " ";
			cout << res[j];
		}
		cout << endl;
	}
	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,b,ta,tb;
	vector<int> routa,routb;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> start >> goal;
		a = b = start;
		ta = 0;
		tb = 1;
		routa.clear();
		routb.clear();
		while(a != goal && b != goal){
			routa.push_back(a);
			routb.push_back(b);
			if(!a) ta = 1 - ta;
			if(!b) tb = 1 - tb;
			a = nextstop[a][ta];
			b = nextstop[b][tb];
		}
		if(a == goal){
			for(int i = 0;i < routa.size();++i){
				if(i) cout << " ";
				cout << routa[i];
			}
			cout << " " << a << endl;
		}
		else{
			for(int i = 0;i < routb.size();++i){
				if(i) cout << " ";
				cout << routb[i];
			}
			cout << " " << b << endl;
		}
	}
	return 0;
}

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

void downTo(vector<int> &vs, int s, int t) {
    while (s >= t) {
        vs.push_back(s--);
    }
}

void upTo(vector<int> &vs, int s, int t) {
    while (s <= t) {
        vs.push_back(s++);
    }
}

int main() {
    int n;
    while (cin >> n) {
        while (n--) {
            int s, t;
            cin >> s >> t;
            vector<int> ans;
            if (s <= 5) {
                if (s < t) {
                    upTo(ans, s, t);
                } else {
                    downTo(ans, s, t);
                }
            } else {
                if (s < t) {
                    upTo(ans, s, t);
                } else {
                    upTo(ans, s, 9);
                    if (t < 6) {
                        downTo(ans, 5, t);
                    } else {
                        downTo(ans, 5, 0);
                        upTo(ans, 1, t);
                    }
                }
            }
            cout << ans[0];
            for (int i = 1, size = ans.size(); i < size; i++) {
                cout << " " << ans[i];
            }
            cout << endl;
        }
    }
}

C++: #include<stdio.h>
int main(void)
{
  int n,a,b,c,r[15],s;
  scanf("%d",&n);
  while(n--){
    scanf("%d%d",&a,&b);
    c=0;
    if(a>b)s=-1;
    else s=1;
    while(a!=b){
      r[c++]=a;
      if(a<6){
        a+=s;if(a==0)s=1;
      }
      else{
        a++;if(a>9)a=5,s=-1;
      }
    }
    for(a=0;a<c;a++){
      printf("%d ",r[a]);
    }
    printf("%d\n",b);
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	while (n--)
	{
		int from, to;
		scanf("%d %d", &from, &to);
		if (to > from)
		{
			for (int i = from; i < to; ++i)
				printf("%d ", i);
			printf("%d\n", to);
		}
		else
		{
			if (from >= 6)
			{
				for (int i = from; i <= 9; ++i)
					printf("%d ", i);

				if (to >= 6 && to < from)
				{
					for (int i = 5; i > 0; --i)
						printf("%d ", i);
					for (int i = 0; i < to; ++i)
						printf("%d ", i);
					printf("%d\n", to);
					continue;
				}
				else
					from = 5;
			}
			for (int i = from; i > to; --i)
				printf("%d ", i);
			printf("%d\n", to);
		}
	}

	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n;
	while (cin >> n) {
		while (n--) {
			int a, b;
			scanf("%d %d", &a, &b);
			if (a < b)
				for (int i = a; i <= b; i++) printf("%d%c", i, i == b ? '\n' : ' ');
			else if (a <= 5)
				for (int i = a; i >= b; i--) printf("%d%c", i, i == b ? '\n' : ' ');
			else {
				for (int i = a; i <= 9; i++) printf("%d ", i);
				for (int i = 5; i > 0; i--) printf("%d ", i);
				for (int i = 0; i <= b; i++) printf("%d%c", i, i == b ? '\n' : ' ');
			}
		}
	}
	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){
			for(int j = a;j <= b;j++) cout << (j == a ? "" : " ") << j;
		}else if(a >= 6){
			for(int j = a;j <= 9;j++) cout << (j == a ? "" : " ") << j;
			if(b >= 6) {
				for(int j = 5;j >= 0;j--) cout << " " << j;
				for(int j = 1;j <= b;j++) cout << " " << j;
			}
			else for(int j = 5;j >= b;j--) cout << " " << j;
		}else{
			for(int j = a;j >= b;j--) cout << (j == a ? "" : " ") << j;
		}
		cout << endl;
	}
	return 0;
}