#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<utility>
#include<cctype>
using namespace std;

#define ull unsigned long long
#define stt(it,order) sort(it.begin(),it.end(),order)
#define st(it) sort(it.begin(),it.end())
#define ll long long
#define rep(i,j) for(int i=0;i<j;++i)
#define loop(i,a,j) for(int i=a;i<j;++i)
#define mpi(it,table,T,E) for(map<T,E>::iterator it = table.begin();it!=table.end();++it)
#define PI 3.141592654
#define pb(v,e) v.push_back(e)

string sint(int i){
   stringstream buf;
   buf<<i;
   return buf.str();
}

/*
   ifstream fin("input.txt");
   ofstream fout("output.txt");
#define cin fin
#define cout fout
*/

int graph[15][15] = { 
   {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
   {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
   {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
   {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0},
   {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0},
   {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
   {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0},
   {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},
   {0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},
   {0,0,0,0,0,0,0,0,0,0,1,0,0,0,0},
   {0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
   {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
   {0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
   {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};

int sol[15];

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

string print(int i,int e){
   if( i == -1)return "";
   if(e)return print(sol[i],0)+sint(alias[i])+"\n";
   return print(sol[i],0)+sint(alias[i])+" ";
}

string do_bfs(int j,int k){
   
   bool vis[15];
   memset(vis,0,sizeof(vis));
   memset(sol,-1,sizeof(sol));

   vis[j] = true;
   sol[j] = -1;

   queue<int> nodes;
   nodes.push(j);

   int stop = j;

   while(!nodes.empty()){
      int nx = nodes.front();
      nodes.pop();
      if( alias[nx] == k){
         stop = nx;
         break;
      }
      rep(i,15){
         if( graph[nx][i] == 1 && !vis[i]){
            sol[i] = nx;
            vis[i] = true;
            nodes.push(i); 
         }
      }
   }
   return print(stop,1);
}

int main(){
   int u;
   scanf("%d",&u);
   rep(a,u){
      string sol = "1 2 3 4 5 6 7 8 9 5 4 3 2 1 0 0 0";
      
      int j,k;
      scanf("%d %d",&j,&k);

      rep(i,15){
         if( alias[i] == j){
            string aux = do_bfs(i,k);
            if( sol.size() > aux.size()) sol = aux;
         }
      }
      printf("%s",sol.c_str());
   }
   return 0;
}