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

int main(){
	int n,from,to,k,min,a;
	int toid[10][2] = { {1, 1}, {0, 2}, {1, 3}, {2, 4}, {3, 5}, {4, 6}, {7 ,7}, {8 ,8}, {9, 9}, {5, 5}};
	vector<int> res,tmp;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> from >> to;
		min = 100;
		res.clear();
		for(int j = 0;j < 2;++j){
			tmp.clear();
			k = j;
			a = from;
			while(a != to){
				tmp.push_back(a);
				if(a == 9 || a == 0) k = 1 - k;
				a = toid[a][k];
//				cout << a << endl;
			}
//			cout << j << endl;
			tmp.push_back(to);
			if(a == to && tmp.size() < min){
				min = tmp.size();
				res.swap(tmp);
			}
		}
		for(int j = 0;j < res.size();++j){
			if(j != 0) cout << " ";
			cout << res[j];
		}
		cout << endl;
	}
	return 0;
}