#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

#define INF 1000010

using namespace std;

int cost[10][10];
int d[10];
bool used[10];
int V = 10;
int prev[10];

void dijkstra(int s){
    fill(d, d+V, INF);
    fill(used, used+V, false);
    fill(prev, prev+V, -1);
    d[s] = 0;

    while(true){
        int v = -1;
        for(int u=0; u < V; u++){
            if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
        }

        if(v == -1) break;
        used[v] = true;

        for(int u=0; u < V; u++){
            if(d[u] > d[v]+cost[v][u]){
                d[u] = d[v]+cost[v][u];
                prev[u] = v;
            }
        }
    }
}

vector<int> get_path(int t){
    vector<int > path;
    for(; t != -1; t = prev[t]) path.push_back(t);
    reverse(all(path));
    return path;
}

int main(){
    int n;
    cin >> n;
    for(int k=0; k < n; k++){
        for(int i=0; i < 10; i++) for(int j=0; j < 10; j++) cost[i][j] = INF;

        for(int i=1; i < 6; i++){
            cost[i][i-1] = 1;
            cost[i-1][i] = 1;
        }
        cost[5][6] = 1; cost[6][7] = 1; cost[7][8] = 1; cost[8][9] = 1; cost[9][5] = 1;

        int e1,e2;
        cin >> e1 >> e2;

        dijkstra(e1);
        vector<int> path = get_path(e2);
        for(int i=0; i < path.size(); i++){
            if(i == 0) cout << path[i];
            else cout << " " << path[i];
        }
        cout << endl;
    }
}