
import std.stdio, std.range, std.algorithm, std.conv;

int[] bus_stop = [1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0];

void show(int[] trace, int start) {
  if (start != trace[0]) trace.reverse;
  trace.map!(to!string).join(" ").writeln;
}

void main() {
  int times;
  readf("%d\n", &times);
  foreach(t; 0..times) {
    int start, finish;
    int[][2] trace;
    readf("%d %d\n", &start, &finish);
    int ci, si, index = 0;
    for(int i = 0; i < bus_stop.length; i++)
      if (bus_stop[i] == start) {ci = si = i; break;}

    do {
      trace[index] ~= bus_stop[ci];
      if (ci == finish) {
        trace[index + 1] ~= [trace[index][$ - 2]] ~ [trace[index][$ - 1]];
        index++;
      }
      ci++;
      if (ci == bus_stop.length) ci = 0;
    } while(ci != si);
    trace[index] ~= bus_stop[ci];
    (trace[0].length < trace[1].length) ? trace[0].show(start) : trace[1].show(start);
  }
}