#include <iostream>
#include <queue>
#include <vector>

#define MAX_V 10

using namespace std;

struct edge_t {
    int from, to;
    edge_t(int from=0, int to=0) :
        from(from), to(to) {}
};

vector<edge_t> graph[MAX_V];

void init() {
    for (int i = 0; i < 9; i++) 
        graph[i].push_back(edge_t(i, i+1));
    graph[9].push_back(edge_t(9, 5));
    for (int i = 5; i > 0; i--) 
        graph[i].push_back(edge_t(i, i-1));
}

struct state_t {
    int stop;
    string path;
    state_t(int stop=0, string path="") :
        stop(stop), path(path) {}
};

void show_path(int s, int g) {
    queue<state_t> q;
    q.push(state_t(s, string("")));

    while (!q.empty()) {
        state_t p = q.front(); q.pop();
        if (p.stop == g) {
            string path = p.path;
            path.push_back(g+'0');
            cout << path[0];
            for (int i = 1; i < path.size(); i++) {
                cout << ' ' << path[i];
            }
            cout << endl;
            break;
        }
        for (int i = 0; i < graph[p.stop].size(); i++) {
            edge_t e = graph[p.stop][i];
            string path = p.path; 
            path.push_back(e.from + '0');
            q.push(state_t(e.to, path));
        }
    }
}

int main() {
    init();
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        int s, g; cin >> s >> g;
        show_path(s, g);
    }
    return 0;
}