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>

const int a[16] = {
    0,
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    5,
    4,
    3,
    2,
    1,
    0,
};

int main()
{
    int n;
    scanf( "%d\n", &n );
    for( int j = 0; j < n; j++ )
    {
        int source = 0, sink = 0;
        scanf( "%d %d\n", &source, &sink );
        if( source <= 5 )
        {
            if( source < sink )
            {
                for( int i = source; i <= sink; i++ )
                {
                    printf( "%d ", i );
                }
                printf( "\n" );
            }
            else
            {
                for( int i = source; i >= sink; i-- )
                {
                    printf( "%d ", i );
                }
                printf( "\n" );
            }
        } 
        else
        {
            if( sink >= 5 )
            {
                if( source < sink )
                {
                    for( int i = source; i <= sink; i++ )
                    {
                        printf( "%d ", i );
                    }
                    printf( "\n" );
                }
                else
                {
                    for( int i = source; i <= 9; i++ )
                    {
                        printf( "%d ", i );
                    }
                    if( sink != 5 )
                    {
                        printf( "5 4 3 2 1 0 1 2 3 4" );
                    }
                    for( int i = 5;i < sink; i++ )
                    {
                        printf( "%d ", i );
                    }
                    printf( "\n" );
                }
            }
            else
            {
                for( int i = source; i <= 9; i++ )
                {
                    printf( "%d ", i );
                }
                for( int i = 5; i >= sink; i++ )
                {
                    printf( "%d ", i );
                }
                printf( "\n" );
            }
        }
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		for(int i=0;i<n;++i){
			int from,to;
			cin>>from>>to;
			if(from<to)for(int i=from;i<=to;++i)cout<<i<<((i==to)?"":" ");
			else if(from<=5)for(int i=from;i>=to;--i)cout<<i<<((i==to)?"":" ");
			else if(to<=5){
				for(int i=from;i<=9;++i)cout<<i<<((i==9)?"":" ");
				for(int i=5;i>=to;--i)cout<<" "<<i;
			}else{
				for(int i=from;i<=9;++i)cout<<i<<((i==9)?"":" ");
				for(int i=5;i<=to;++i)cout<<" "<<i;
			}
			cout<<"\n";
		}
	}
	return 0;
}

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

#define loop(i, n) for (int i = 0; i < n; i++)

int main()
{
    int d;
    cin >> d;
    for (int data = 0; data < d; data++) {
        int a, b;
        cin >> a >> b;
        if (a < b) {
            for (int i = a; i < b; i++) {
                cout << i << " ";
            }
            cout << b << endl;
        } else if (a >= 6) {
            for (int i = a; i < 10; i++) {
                cout << i << " ";
            }
            for (int i = 5; i > b; i--) {
                cout << i << " ";
            }
            cout << b << endl;
        } else {
            for (int i = a; i > b; i--) {
                cout << i << " ";
            }
            cout << b << endl;
        }
    }
    return 0;
}

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

using namespace std;

int main(){
  int i, j, n, before, after;
  vector<int> line, way;
  vector<int>::iterator iter1, iter2;

  for(i=0; i<10; ++i)
    line.push_back(i);
  for(i=5; i>=0; --i)
    line.push_back(i);

  for(i=0; i<line.size(); ++i)
    cout << line[i] << " ";
  cout << endl;

  cin >> n;

  for(i=0; i<n; ++i){
    cin >> before >> after;
    
    if(before < after){
      iter1 = find(line.begin(), line.begin()+10, before);
      iter2 = find(iter1, line.begin()+10, after);
    }else{
      iter1 = find(line.begin()+6, line.end(), before);
      iter2 = find(iter1, line.end(), after);
    }
    copy(iter1, iter2+1, back_inserter(way));

    for(j=0; j<way.size()-1; ++j)
      cout << way[j] << " ";
    cout << way[way.size()-1] << endl;

    way.clear();
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  while(n--){
    int s,g;
    cin >> s >> g;
    bool flag = false;
    if(s >= 6 && s <= 9){
      if(g >= s){
	for(int i=s;i<=g;i++){
	  if(flag) cout << " ";
	  cout << i;
	  flag = true;
	}
	cout << endl;
	return 0;
      }
      else {
	for(int i=s;i<=9;i++){
	  if(flag) cout << " ";
	  cout << i;
	  flag = true;
	}
	if(g >= 6 && s > g){
	  for(int i=5;i> 0;i--){
	    if(flag) cout << " ";
	    cout << i;
	    flag  = true;
	  }
	  for(int i=0;i<=g;i++){
	    if(flag) cout << " ";
	    cout << i;
	    flag  = true;
	  }
	  cout << endl;
	  return 0;
	}
	s = 5;
      }
    }
    if(g - s > 0){
      for(int i=s;i<=g;i++){
	if(flag) cout << " ";
	cout << i;
	flag  = true;
      }
      cout << endl;
    }
    else {
      for(int i=s;i>=g;i--){
	if(flag) cout << " ";
	cout << i;
	flag = true;
      }
      cout << endl;
    }
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
string a="6 7 8 9 5 4 3 2 1 0 1 2 3 4 5 6";
main(){
  int n,s,t,i,j;
  cin>>n;
  while(n--){
    cin>>s>>t;
    for(i=0;s!=a[i]-'0';i++);
    for(j=i;t!=a[j]-'0';j++)if(a[j]-'0'==s)i=j;
    cout<<a.substr(i,j-i+1)<<endl;
  }
}

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

int main(){
    int ans2[10],ans1[10];
    int n,f,e,cnt;
    bool sj,fj,judge,ze,ro;
    cin >> n;
    while(n--){
        cin >> f >> e;
        cnt = 1;
        sj = false;
        fj = false;
        ze = true;
        ro = true;
        judge = false;
        int sta = f;
        ans1[0] = sta;
        ans2[0] = sta;
        while(1){
            if(sta == e) break;
            if(f == e){
                judge = true;
                break;
            }
            if(f > 5 && f < 9) f = -100000;
            if(sta == 9 && !sj){
                sta = 5;
                sj = true;
            }
            else if(sta == 0 && sj) sj = false;
            else if(sj) sta--;
            else if(!sj) sta++;
            ans1[cnt] = sta;
            
            if(f == 0 && !fj) fj = true;
            else if(f == 9 && !fj){
                fj = false;
                f = 5;
            }
            else if(!fj) f--;
            else if(fj) f++;
            ans2[cnt] = f;
            cnt++;
        }
        if(judge){
            for(int i=0;i<cnt-1;i++){
                cout << ans2[i] << " ";
                if(ans2[i+1] == 0 && ans2[i] == 0) i++;
            }
            cout << ans2[cnt-1] << endl;
        }
        else {
            for(int i=0;i<cnt-1;i++){
                cout << ans1[i] << " ";
                if(ans1[i+1] == 0 && ans1[i] == 0) i++;
            }
            cout << ans1[cnt-1] << endl;
        }
    }
}