Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

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<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int n;
  vector<int> r,f;
  cin>>n;
  r.reserve(n);
  f.reserve(n);
  for(i=0;i<n;i++)
    cin>>r[i]>>f[i];
  for(i=0;i<n;i++){
    if(r[i]<6){
      if(f[i]<r[i]){
	for(j=r[i];j>f[i];j--)
	  cout<<j<<" ";
	cout<<j<<endl;
      }else{
	for(j=r[i];j<f[i];j++)
	  cout<<j<<" ";
	cout<<j<<endl;
      }
    }else{
      if(f[i]>r[i]){
	for(j=r[i];j<f[i];j++)
	  cout<<j<<" ";
	cout<<j<<endl;
      }else{
	for(j=r[i];j<10;j++)
	  cout<<j<<" ";
	if(f[i]>5){
	  cout<<"5 4 3 2 1 0 1 2 3 4 5 ";
	  for(j=6;j<f[i];j++)
	    cout<<j<<" ";
	  cout<<j<<endl;
	}else{
	  for(j=5;j>f[i];j--)
	    cout<<j<<" ";
	  cout<<j<<endl;
	}
      }
    }
  }
  return 0;
}

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

using namespace std;

int main(){

	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		int from,to;
		cin>>from>>to;
		// ¶ûüÉV~[V
		int angle=1;
		int c=from;
		vector<int> ph;
		ph.push_back(c);
		while(1){
			if(angle==0&&c==5){
				c++;
			}
			else if(angle==1&&c==5){
				c--;
			}
			else if(c>=6&&c<=9){
				c++;
				if(c==10){
					c=5;
					angle=1;
				}
			}
			else if(angle==0&&c>=1&&c<=4){
				c++;
			}
			else if(angle==1&&c>=1&&c<=4){
				c--;
			}
			else if(c==0){
				c++;
			}
			ph.push_back(c);
			if(c==to)
				break;
		}
		c=from;
		angle=0;
		vector<int>ph2;
		ph2.push_back(c);
		while(1){
			if(angle==0&&c==5){
				c++;
			}
			else if(angle==1&&c==5){
				c--;
			}
			else if(c>=6&&c<=9){
				c++;
				if(c==10){
					c=5;
					angle=1;
				}
			}
			else if(angle==0&&c>=1&&c<=4){
				c++;
			}
			else if(angle==1&&c>=1&&c<=4){
				c--;
			}
			else if(c==0){
				c++;
			}
			ph2.push_back(c);
			if(c==to)
				break;
		}
		if(ph.size()<ph2.size()){
			for(int j = 0; j < ph.size(); j++){
				cout<<ph[j];
				if(j!=ph.size()-1){
					cout<<" ";
				}
				else
					cout<<endl;
			}
		}
		else{
			for(int j = 0; j < ph2.size(); j++){
				cout<<ph2[j];
				if(j!=ph2.size()-1){
					cout<<" ";
				}
				else
					cout<<endl;
			}
		}

	}

	return 0;
}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem0140 : Bus Line **/
int main()
{
	int N; cin>>N;
	int p1[] = {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};
	
	rep(z, N) {
		int s, t; cin>>s>>t;
		
		int ans=INF, a=-1, b=-1;
		for (int i=0; i<25; i++) {
			if (p1[i]==s) {
				int tt=1;
				for (int j=i; j<25; j++) {
					if (p1[j]==t) {
						if (ans>tt) {
							ans = tt;
							a = i;
							b = i+tt;
						}
						break;
					}
					tt++;
				}
			}
		}
		
		
		for (int i=a; i<b; i++) {
			if (i!=a) cout<<" ";
			cout << p1[i];
		}
		cout << endl;
	}
}

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)
#define PB push_back
#define p(a,b) g.PB(pii(a, b))
#define INF (1<<29)

typedef pair<int, int> pii;
typedef vector<pii> vp;

int main() {
	vp g; //pos to
	REP(i, 9) p(i, i + 1);
	p(9, 10);
	REP(i, 4) p(5 - i, i + 11);
	p(1, 0);
	
	int n;
	cin >> n;
	while (n--) {
		int prev[2][10], miner[2], tmp[2];
		int a, b;
		scanf("%d %d", &a, &b);
		
		tmp[0] = tmp[1] = INF;
		REP(i, g.size()) if (g[i].first == a) {
			if (tmp[0] == INF) tmp[0] = i;
			else tmp[1] = i;
		}
		
		miner[0] = miner[1] = INF;
		REP(i, 2) {
			if (tmp[i] == INF) break;
			
			queue<int> que; //pos
			que.push(tmp[i]);
			
			miner[i] = 0;
			while(true) {
				int pos = g[que.front()].first;
				int to = g[que.front()].second;
				que.pop();
				
				prev[i][miner[i]++] = pos;
				if (pos == b) break;
				
				que.push(to);
			}
		}
		
		int ans = miner[0] < miner[1] ? 0 : 1;
		REP(i, miner[ans]) {
			if (i != 0) printf(" ");
			printf("%d", prev[ans][i]);
		}
		cout << endl;
	}
	return 0;
}

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;
    while(jo!=ko){
      if(jo <= 5){
	if(jo == 0 && ko!=0){
	  p[h]=jo;
	  jo++;
	  h++;
	}
	if(jo<ko){
	  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++;
	  }
	  if(jo > 9 && ko == 5){
	    break;
	  }
	}
      }
    }
  
    for(d=0;d<h;d++){
      cout << p[d] << " " ;
    }
    cout << ko << endl;
  }
}

C++: #include <iostream>

using namespace std;


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

}

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;
	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);
			if (b == 5) puts("5");
			else {
				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;
}