#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

V ans;
ll pos, goal, n;

ll d[10][10];
bool used[10];

void solve(ll pos){
	ans.push_back(pos);
	if (pos == goal){
		REP(i, ans.size())cout << ans[i] << " ";
		cout << endl;
		return;
	}

	for (int i = 0; i < 10; i++){
		if (d[pos][i] == 1){
			if (used[i] == 0){
				used[i] = 1;
				solve(i);
				ans.pop_back();
				used[i] = 0;
			}
		}
	}
	return;
}

int main(){
	//REP(i, 10)REP(j, 10)d[i][j] = INF;
	d[0][1] = d[1][0] = d[1][2] = d[2][1] = d[2][3] = d[3][2] = d[3][4] = 1;
	d[4][3] = d[4][5] = d[5][4] = d[5][6] = d[6][7] = d[7][8] = d[8][9] = d[9][5] = 1;
	cin >> n;
	REP(i, n){
		cin >> pos >> goal;

		if (pos == goal){
			cout << pos << endl;
			continue;
		}

		REP(j, 10)used[j] = 0;
		used[pos] = 1;
		solve(pos);
		ans.clear();
	}
}