#include <iostream>
#include <deque>
#include <set>

using namespace std;

bool data[10][10];

void init()
{
	for( int i = 0;i < 10;i++ ){
		for( int j = 0;j < 10;j++ ){
			data[i][j] = false;
		}
	}

	data[0][1] = true;
	data[1][0] = true;
	data[1][2] = true;
	data[2][1] = true;
	data[2][3] = true;
	data[3][2] = true;
	data[3][4] = true;
	data[4][3] = true;
	data[4][5] = true;
	data[5][4] = true;
	data[5][6] = true;
	data[6][7] = true;
	data[7][8] = true;
	data[8][9] = true;
	data[9][5] = true;
}

bool serch( int start, int end, deque<int> &answer, set<int> &history )
{
	if( end == start ) return true;

	for( int i = 0;i < 10;i++ ){
		if( data[start][i] ){
			if( history.count( i ) ) continue;
			history.insert( i );
			answer.push_back( i );
			bool a = serch( i, end, answer, history );
			if( a == true ) return true;
		}
	}
	answer.clear();
	return false;
}


int main(int argc, char const* argv[])
{
	int n;
	int start,end;

	deque<int> answer;
	set<int> history;
	cin >> n;

	init();
	for( int i = 0;i < n;i++ ){
		answer.clear();
		history.clear();
		cin >> start >> end;

		history.insert( start );
		serch( start, end, answer, history );

		cout << start;
		for( deque<int>::iterator it = answer.begin();it != answer.end();it++ ) cout << " " << *it;
		cout << endl;
	}

	return 0;
}