#include <iostream>
#include <vector>
using namespace std;

const int INT = -1;
int nextstop[10][2] = {{1,1},{0,2},{1,3},{2,4},{3,5},{4,6},{INT,7},{INT,8},{INT,9},{INT,5}};

int main(){
	int n,start,goal,a,b,ta,tb;
	vector<int> routa,routb;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> start >> goal;
		a = b = start;
		ta = 0;
		tb = 1;
		routa.clear();
		routb.clear();
		while(a != goal && b != goal){
			routa.push_back(a);
			routb.push_back(b);
			if(!a) ta = 1 - ta;
			if(!b) tb = 1 - tb;
			a = nextstop[a][ta];
			b = nextstop[b][tb];
		}
		if(a == goal){
			for(int i = 0;i < routa.size();++i){
				if(i) cout << " ";
				cout << routa[i];
			}
			cout << " " << a << endl;
		}
		else{
			for(int i = 0;i < routb.size();++i){
				if(i) cout << " ";
				cout << routb[i];
			}
			cout << " " << b << endl;
		}
	}
	return 0;
}