#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 a, b;

void fr(int n, vector<int> &r, vector<P> &v){
  r.push_back(n);
  if(n == a) return ;
  fr(v[n].second, r, v);
}

int main() {
  vector<int> G[N];
  G[0].push_back(1);
  G[1].push_back(0); G[1].push_back(2);
  G[2].push_back(1); G[2].push_back(3);
  G[3].push_back(2); G[3].push_back(4);
  G[4].push_back(3); G[4].push_back(5);
  G[5].push_back(4); G[5].push_back(6); G[5].push_back(9);
  G[6].push_back(5); G[4].push_back(7);
  G[7].push_back(6); G[4].push_back(8);
  G[8].push_back(7); G[4].push_back(9);
  G[9].push_back(5); G[9].push_back(8);
  int T; cin >>T;
  REP(t, T){
    cin >>a >>b;
    queue<P> open;
    open.push(P(0, a));
    vector<P> closed(N, P(INF, INF));
    while(!open.empty()){
      P tmp = open.front(); open.pop();
      int c = tmp.first, n = tmp.second;
      REP(i, G[n].size()){
        int next = G[n][i];
        if(closed[next].first <= c + 1) continue;
        closed[next] = P(c + 1, n);
        open.push(P(c + 1, next));
      }
    }
    vector<int> r;
    fr(b, r, closed);
    REVERSE(r);
    REP(i, r.size()) cout <<r[i] <<(i + 1 == (int)r.size() ? "" : " "); cout <<endl;
  }


  return 0;
}