#include <iostream>
#include <stack>
#include <queue>

using namespace std;

int hyou[10][10] = {{0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
				    {1, 0, 1, 0, 0, 0, 0, 0, 0, 0},
				    {0, 1, 0, 1, 0, 0, 0, 0, 0, 0},
				    {0, 0, 1, 0, 1, 0, 0, 0, 0, 0},
				    {0, 0, 0, 1, 0, 1, 0, 0, 0, 0},
				    {0, 0, 0, 0, 1, 0, 1, 0, 0, 0},
				    {0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
				    {0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
				    {0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
					{0, 0, 0, 0, 0, 1, 0, 0, 0, 0},};

typedef pair<int, int> P;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		queue<P> q;
		P pp;
		pp.first = a;
		pp.second = -1;
		int hyou2[10] = {0};
		q.push(pp);
		while (!q.empty()) {
			P p = q.front();
			hyou2[p.first] = p.second;
			bool hantei = false;
			q.pop();
			for (int j = 0; j < 10; j++) {
				if (hyou[p.first][j] == 1) {
					if (j == b) {
						hyou2[j] = p.first;
						hantei = true;
						break;
					} else if (hyou2[j] == 0){
						P ppp;
						ppp.first = j;
						ppp.second = p.first;
						q.push(ppp);
					}
				}
			}
			if (hantei) {
				break;
			}
		}
		stack<int> stk;
		int t = b;
		while (t != -1) {
			stk.push(t);
			t = hyou2[t];
		}
		cout << stk.top();
		stk.pop();
		while (!stk.empty()) {
			cout << " " << stk.top();
			stk.pop();
		}
		cout << endl;
	}
	return 0;
}