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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int s[16] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};
int s2[20] = {5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9};
int main(void){
  int n;
  cin>>n;
  while(n--){
    int a,b;
    vector<int> ans;
    cin>>a>>b;
    bool f=false;
    REP(i,16){
      if(s[i]==a){
        if(!f)f=true;
        else ans.clear();
      }
      if(f) ans.push_back(s[i]);
      if(f&&s[i]==b) break;
    }
    if(b>=5&&a>b){
      ans.clear();
      f = false;
      REP(i,20){
        if(s2[i]==a){
          if(!f)f=true;
          else ans.clear();
        }
        if(f) ans.push_back(s2[i]);
        if(f&&s2[i]==b) break;
      }
    }
    REP(i,ans.size()){
      if(i) cout<<" ";
      cout<<ans[i];
    }
    cout<<endl;
  }
  return 0;
}

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

int main()
{
  int n;
  int a, b;

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

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;
	while(~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);
					}

					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;
int main(){
  int a=0,b,c,d,n,h=0,jo,ko,i,p[100]={0};
  cin >> n;
  for(i=0;i<n;i++){
    cin >> jo >> ko;
    h=0;
    for(c=0;c<11;c++){
      p[c]=0;
    }
    while(jo!=ko){
      if(jo <= 5){
	if(jo == 0 && ko!=0){
	  p[h]=jo;
	  jo++;
	  h++;
	}
	if(jo<ko && jo!=0){
	  p[h]=jo;
	  jo++;
	  h++;
	}
	if(jo>ko){
	  p[h]=jo;
	  jo--;
	  h++;
	}
      }
      if(jo > 5){
	if(jo<ko){
	  p[h]=jo;
	  jo++;
	  h++;
	}
	if(jo>ko){
	  if(jo <= 9){
	    p[h]=jo;
	    jo++;
	    h++;
	  }
	  if(jo > 9 && ko < 5){
	    jo=5;
	    p[h]=jo;
	    jo--;
	    h++;
	  }
	  if(jo > 9 && ko > 5){
	    jo=5;
	    p[h]=jo;
	    jo++;
	    h++;
	  }
	}
      }
    }
    for(d=0;d<h;d++){
      cout << p[d] << " " ;
    }
    cout << ko << endl;
  }

}

C++: #include <iostream>

using namespace std;

main(){
  int n;
  while(cin >> n){
    for(int c=0;c<n;c++){
      int s, g;
      cin >> s >> g;
      int d;
      if(s<=5 && g<s){
	d=0;
      }else{
	d=1;
      }
      if(d==1){
	bool finish=false;
	for(int i=s;i<10;i++){
	  cout << i;
	  if(i==g){
	    finish=true;
	    break;
	  }
	  cout << ' ';
	}
	if(finish){
	  cout << endl;
	  continue;
	}
	if(g<=5){
	  for(int i=5;i>=0;i--){
	    cout << i;
	    if(i==g){
	      break;
	    }
	    cout << ' ';
	  }
	  cout << endl;
	}else{
	  for(int i=5;i>0;i--){
	    cout << i;
	    cout << ' ';
	  }
	  for(int i=0;i<5;i++){
	    cout << i;
	    cout << ' ';
	  }
	  for(int i=5;i<10;i++){
	    cout << i;
	    if(i==g) break;
	    cout << ' ';
	  }
	  cout << endl;
	}
      }else{
	for(int i=s;i>=0;i--){
	  cout << i;
	  if(i==g) break;
	  cout << ' ';
	}
	cout << endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n,a,b;

int main(){
	cin>>n;
	while(cin>>a>>b){
		if(a<=5||a>5&&b>a){
			if(a<b){
				for(int i=a;i<=b;i++){cout<<i;if(i!=b)cout<<" ";}
				cout<<endl;
			}
			else {
				for(int i=a;i>=b;i--){cout<<i;if(i!=b)cout<<" ";}
				cout<<endl;
			}
		}
		if(a>5&&b<=5){
			for(int i=a;i<=9;i++)cout<<i<<" ";
			for(int i=5;i>=b;i--){cout<<i;if(i!=b)cout<<" ";}
			cout<<endl;
		}
		if(a>5&&b>5&&b<a){
			for(int i=a;i<=9;i++)cout<<i<<" ";
			cout<<"5 4 3 2 1 0 1 2 3 4 5 ";
			for(int i=6;i<=b;i++){cout<<i;if(i!=b)cout<<" ";}
			cout<<endl;
		}
	}
}

C++: int main()
{
  const int busstop[] = {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};
  const int bussize = sizeof(busstop) / sizeof(int);

  int n;
  while (cin >> n) {
    while (n--) {
      int a, b;
      cin >> a >> b;

      int s = 0;
      for (; s < bussize; ++s) {
	if (busstop[s] == a)
	  break;
      }

      vector<int> ans;
      for (int i = s; i < bussize; ++i) {
	ans.push_back(busstop[i]);
	if (busstop[i] == b)
	  break;
      }

      if (1 <= a && a <= 5 && b < a) {
	vector<int> rev;
	for (int i = s; i >= 0; --i) {
	rev.push_back(busstop[i]);
	if (busstop[i] == b)
	  break;
	}
	if (rev.size() < ans.size())
	  ans = rev;
      }

      for (int i = 0; i < ans.size()-1; ++i)
	cout << ans[i] << " ";
      cout << ans.back() << endl;
    }
  }
  return 0;
}