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

#define INF (1<<20)
#define min(a,b) ((a) > (b) ? (b) : (a))

int dp[10][10];
int from[15] = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
int to[15] = {1,2,3,4,5,6,7,8,9,5,4,3,2,1,0};

int main(){
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			dp[i][j] = INF;
		}
		dp[i][i] = 0;
	}
	for(int i = 0; i < 15; i++){
		dp[from[i]][to[i]] = 1;
	}
	for(int k = 0; k < 10; k++){
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}

	int n,s,e;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d%d",&s,&e);
		vector<int> r = vector<int>();
		r.push_back(e);
		while(s != e){
			for(int j = 0; j < 10; j++){
				if(dp[s][e] - dp[s][j] == 1 && dp[j][e] == 1){
					e = j;
					r.push_back(j);
					break;
				}
			}
		}
		for(int i = r.size() - 1; i > 0; i--){
			printf("%d ",r[i]);
		}
		printf("%d\n",r[0]);

	}
	return 0;
}