#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <functional>
#include <iterator>
using namespace std;

const int INF = (int)1e9;
typedef pair<int, int> P;

struct Edge {
    int to, cost;
    Edge(int t, int c) : to(t), cost(c) { }
};

pair<int, vector<int> > dijkstra_with_route(const vector<vector<Edge> > &edges, const int from, const int to) {
    vector<int> dist(edges.size(), INF);
    vector<int> prev(edges.size(), -1);

    priority_queue<P, vector<P>, greater<P> > Q;
    Q.push(P(0, from));
    dist[from] = 0;

    while(!Q.empty()) {
        P p = Q.top(); Q.pop();
        int v = p.second;
        int d = p.first;
        if(v == to) break;
        if(d > dist[v]) continue;
        for(int i = 0; i < (int)edges[v].size(); i++) {
            Edge e = edges[v][i];
            int c = d + e.cost;
            if(c < dist[e.to]) {
                dist[e.to] = c;
                Q.push(P(c, e.to));
                prev[e.to] = v;
            }
        }
    }

    vector<int> res;
    int u = to;
    while(u != from) {
        res.push_back(u);
        u = prev[u];
    }
    res.push_back(from);
    reverse(res.begin(), res.end());
    return make_pair(dist[to], res);
}

int main() {
    vector<vector<Edge> > edges(10);
    edges[0].push_back(Edge(1, 1));
    edges[1].push_back(Edge(0, 1));
    edges[1].push_back(Edge(2, 1));
    edges[2].push_back(Edge(1, 1));
    edges[2].push_back(Edge(3, 1));
    edges[3].push_back(Edge(2, 1));
    edges[3].push_back(Edge(4, 1));
    edges[4].push_back(Edge(3, 1));
    edges[4].push_back(Edge(5, 1));
    edges[5].push_back(Edge(4, 1));
    edges[5].push_back(Edge(6, 1));
    edges[6].push_back(Edge(7, 1));
    edges[7].push_back(Edge(8, 1));
    edges[8].push_back(Edge(9, 1));
    edges[9].push_back(Edge(5, 1));

    int N; cin >> N;
    while(N--) {
        int from, to; cin >> from >> to;
        auto res = dijkstra_with_route(edges, from, to).second;
        for(int i = 0; i < (int)res.size() - 1; i++) {
            cout << res[i] << ' ';
        }
        cout << *res.rbegin() << endl;
    }
}