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 <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 main() {
  int T; cin >>T;
  REP(t, T){
    int a, b; cin >>a >>b;
    cout <<a;
    while(a != b){
      if(a <= 5) a = (abs(b - (a + 1)) < abs(b - (a - 1)) ? a + 1 : a - 1);
      else a += 1;
      if(a == 10) a = 5;
      if(a == -1) a = 1;
      cout <<" " <<a;
    }
    cout <<endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,f,t,*ip,*p,*q,x,a[]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,};
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d",&f,&t);
		q=&a[24];
		ip=&a[f];

		p=find(&a[f],a+24,t);
		if(f<6) q=find(a+10,a+24,t);

		if(q!=a+24)
		{
			if( q>a+15-f && (q-(a+15-f)) < (p-ip)) 
				ip=a+15-f, p=q;
		}
		x=0;
		for(;ip<=p;++ip)
			printf("%s%d",(x++?" ":""),*ip);
		putchar('\n');
	}
	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", &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);
				from = 5;
			}
			for (int i = from; i > to; --i)
				printf("%d ", i);
			printf("%d\n", to);
		}

	}

	return 0;
}

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

int main(){
	int n;
	int bus[15]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
	
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		int a, b;
		scanf(" %d %d", &a, &b);
		
		if(a==0 || 5<a){ //1通りしかありえない
			int start=0, goal;
			while(bus[start] != a) start++;
			
			goal=start;
			bool flag=false;
			while(1){
				if(flag) printf(" ");
				printf("%d", bus[goal%15]);
				if(bus[goal%15] == b) break;
				goal++;
				flag=true;
			}
			printf("\n");
		}
		else{ //2通りある
			int start=0, goal, count1=0, count2=0;
			
			while(bus[start] != a) start++;
			goal=start;
			while(bus[goal%15] != b){
				goal++;
				count1++;
			}
			
			start++;
			int tmp=0;
			while(bus[start%15] != a) start++;
			goal=start;
			while(bus[goal%15] != b){
				goal++;
				count2++;
			}
			
			if(count1 < count2) goal=a;
			else goal=15-a;
			
			bool flag=false;
			while(1){
				if(flag) printf(" ");
				
				printf("%d", bus[goal%15]);
				if(bus[goal%15] == b) break;
				goal++;
				flag=true;
			}
			printf("\n");
			
		}
		
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int bus[]{ 0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0 };
int main() {
	int n; scanf("%d", &n);
	rep(t, n) {
		int s, g; scanf("%d%d", &s, &g);
		int x = 0, y = 15;
		for (int i = 0; i < 16; i++) {
			for (int j = i + 1; j < 16; j++) {
				if (bus[i] == s&&bus[j] == g&&j - i < y - x) {
					x = i; y = j;
				}
			}
		}
		for (int i = x; i <= y; i++) {
			printf("%d", bus[i]);
			if (i == y)printf("\n");
			else printf(" ");
		}
	}
}

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)
        {
            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(i == ans.size()-1) break; cout << " ";}
        cout << endl;
    }
    return 0;
}

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

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

void solve( int s, int t )
{
    if ( s >= 0 && s <= 5 && t >= 0 && t <= 5 )
    {
        if ( s > t )
        {
            for ( int i = s; i >= t; i-- )
            {
                cout << i;
                if ( i == t ) cout << endl; else cout << " ";
            }
            return;
        }
        else
        {
            for ( int i = s; i <= t; i++ )
            {
                cout << i;
                if ( i == t ) cout << endl; else cout << " ";
            }
            return;
        }
    }

    int k = 0;
    for ( k = 0; k < 15; k++ ) if ( route[k] == s ) break;
    while ( route[k] != t )
    {
        cout << route[k] << " ";
        k = ( k + 1 ) % 15;
    }
    cout << route[k] << endl;;
}

int main( void )
{

    int n;
    cin >> n;

    for ( int i = 0; i < n; i++ )
    {
        int s, t;
        cin >> s >> t;
        solve( s, t );
    }

    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;
          }
        }
      }
      else {
        for (int i = a - 1; i >= b; i--){
          cout << ' ' << i;
        }
      }
    }
    cout << endl;
  }
  return (0);
}