#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define PP(m) REP(i, m.size()) cout << m[i] << endl;

int main() {
  vector<int> co(10);
  vector<int> cr(10);

  REP(i, 9) co[i] = i+1;
  REP(i, 9) cr[i] = i+1;
  co[9] = 5;
  cr[9] = 5;

  for (int i=0; i<5; i++) cr[5-i] = 4-i;

  int n;
  cin >> n;
  REP(i, n) {
    int a,b;
    string r="";
    bool rev = false;
    cin >> a >> b;
    while (true) {
      r += to_string(a);
      if (a == b) {
        r += "\n";
        break;
      }
      if (a == 9 || (a == 0 && rev) || (a <= 5 && b <= 5 && a > b && !rev)) {
        rev = !rev;
      }
      if (!rev) {
        a = co[a];
      } else {
        a = cr[a];
      }
      r += " ";
    }
    cout << r;
  }

  return 0;
}